We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Saving Document to TIFF Create Chinese Characters

Hello,

Please review the thread at:

Alexey indicates that Aspose.Network needs to be involved in solving this issue.

As previously indicated on the Aspose.Word thread, this problem has been lingering for quite some time and is preventing us for completing our production implementation.

We need to have it addressed as soon as possible.

Thanks,

Jm

Hi,

Thank you for inquiry.

Could you please post a sample source message for our analysis?

private static Document BuildWordDocumentFromHtmlMessage(MailMessage asposeMessage) {

Document doc;

using(var memoryStream=new MemoryStream()) {

TextWriter textWriter=new StreamWriter(memoryStream, asposeMessage.BodyEncoding??Encoding.Default);

textWriter.Write(asposeMessage.HtmlBody);

textWriter.Flush();

var loadOptions=new Aspose.Words.LoadOptions();

loadOptions.LoadFormat=Aspose.Words.LoadFormat.Html;

doc=new Document(memoryStream, loadOptions);

}

return doc;

}


If sending of original source file is not possible, please try to overwrite any confidential information using MailMessage.
asposeMessage.HtmlBody = "test body";
asposeMessage.From = "a@b.com";
etc
asposeMessage.Save("test.eml", MailMessageSaveType.EmlFormat); // or MSG format

Saqib,

Thanks for your reply.

I still don’t have a clean email that I can send you at this time.

However, I think AsposeMessage.Zip file found in

I tried to go through your recommendations to create a MSG or EML file but when I do, something gets overwritten and that behavior is not longer observed.

Can you please take a look and let me know if there is something on the MailMessage which should trigger a different mechanism.

What in the message from Exchange would change the encoding of MailMessage.

As mentionned before, this issue has lingered for a while and prevents from completing this rollout.

Thanks,

Jm

Hi Jm,

Could you please check the charset of the message from MS Outlook --> message properties and see if the encoding matches the MailMessage.PreferredTextEncoding?

The encoding information is also available from Alternate views too. Does any of the encoding matches the encoding showed by Outlook?

MailMessage message = …; // get the message
Console.WriteLine("Preferred text encoding: " + message.PreferredTextEncoding);
Console.WriteLine("Body encoding: " + message.BodyEncoding);
Console.WriteLine("content-type: " + message.Headers[“Content-Type”]);

if (message.Headers[“Content-Type”] == null)
{
// Check the alternate views
foreach (AlternateView aView in message.AlternateViews)
{
Console.WriteLine("Alternate view ContentType: " + aView.ContentType);
}
}

Saqib,

Thank you for your reply and your willing to help.

I ran a test with a message that DOES produce “Chinese” looking characters file and I captured the information you mentioned. The result is as follows:

BodyFormat: Html

CodePage:28591

ContentType: multipart/alternative; boundary="_000_D4325E6538694949B5E5DC661CFB8098018680C2SDWPMSS003msgal_"

BodyEncoding:Null

PreferedTextEncoding:.

I also ran the test with a several other messages that DO NOT produce “Chinese” looking character file and some of them do result in the same values for BodyFormat, CodePage, ContentType, BodyEncoding and PreferedTextEncoding.

I am however not sure what you are asking regarding the charset of the message from MS Outlook.

These message look Ok when viewed in Outlook. It is when they are converted to TIFF file through a Aspose.Word document that they turn into “Chinese” looking messages.

Alexey from the Aspose.Word team says the following:

“Your file has Unicode encoding. The following code allows to convert it properly:

byte[] htmlbytes = Encoding.Unicode.GetBytes(File.ReadAllText(@"Test001\asposeMessage.html"));
using (MemoryStream ms = new MemoryStream(htmlbytes)){
    Document doc = new Document(ms);
    doc.Save(@"Test001\out.tiff");
}

I think, Aspose.Network should determine the encoding properly.“

This code produces a valid TIFF but does not work for all message.

Please advise.

Thanks,

Jm

Please also add the code below (remove the if condition). It seems that the message is multipart and the encoding information might become available from AlternateView.ContentType property.

// Check the alternate views
foreach (AlternateView aView in message.AlternateViews)
{
Console.WriteLine("Alternate view ContentType: " + aView.ContentType);
}

I just wanted to check what characterset is being used in the message. Below is the screenshot of the message properties when opened in Outlook. It has utf-8 characterset.


According to your output
PreferedTextEncoding:.
it seems to be a bug to handle the encoding type of these kind of messages.

Saqib

Here’s the code I used to log the content type of the message.

public string ContentType {
    get {
        StringBuilder stringBuilder=new StringBuilder();
        // return true if it is an appointment
        stringBuilder.Append(AsposeMessage.Headers["Content-Type"]);
        if(AsposeMessage.Headers["Content-Type"]==null) {
            // Check the alternate views
            foreach(AlternateView alternateView in AsposeMessage.AlternateViews) {
                stringBuilder.Append("Alternate view ContentType: "+alternateView.ContentType);
            }
        }
        return stringBuilder.ToString();
    }
}

The screenshot did not come through. Can you resend/re-post it.

When I forward the faulty message to the mailbox and run through my test, the output is as follows:

BodyFormat: Html

CodePage:20127

ContentType: multipart/alternative;

boundary="_000_8FD20B28A8910E4DABA0514DA59504A7CBECB66ASLEXV2talxcom_"

BodyEncoding:Null

PreferedTextEncoding:System.Text.ASCIIEncoding

I just got clearance to send an email from the client with minimal PII.

Is there an email address where I forward the message?

I can’t post it on this forum without losing the faulty properties.

Thanks,

Jm

Hi Jm,

I have attached the image.

Please update the code and test with below:

public string ContentType {

get {

StringBuilder stringBuilder=new StringBuilder();

// return true if it is an appointment

stringBuilder.Append(AsposeMessage.Headers["Content-Type"]);


// Check the alternate views

foreach(AlternateView alternateView in AsposeMessage.AlternateViews) {

stringBuilder.Append("Alternate view ContentType: "+alternateView.ContentType);

}

return stringBuilder.ToString();

}

}

Hi,

Could you please tell how do you download the message?

When I try to load the 2 files with MailMessage.FromFile(), get the HTML and pass to Aspose.Word’s Document object, both files show the correct text in the TIFFs. Please see the below code:

MailMessage message = MailMessage.Load(“1.msg”, MessageFormat.Msg); // both msg work
StreamWriter writer = new StreamWriter(“test.html”);
writer.Write(message.HtmlBody);
writer.Close();

LoadOptions loadOptions = new LoadOptions();
loadOptions.LoadFormat = LoadFormat.Html;
Document doc = new Document(“test.html”, loadOptions);
doc.Save(“test.tiff”);

Since you are getting the messages from a mailbox, I tested by adding these files to Outlook connected with an IMAP server and got a different error, MailMessage.HtmlBody was blank.

Could you please tell us your scenario how you are getting the messages, so that we could check the html body and encoding issues.

I performed these tests with Aspose.Email for .NET 1.0 (previously Aspose.Network).

Hi,

We noticed that if you save the message to a MSG/EML file, something gets overwritten and the message converts fine. We don’t use that method.

We get the messages straight from the inbox using the following snippet of code:

public IIncomingMessage GetMessage(string pendingMessage) {

public string ContentType {
    get {
        MailMessage mailMessage;
        EMailBodyFormat bodyFormat=EMailBodyFormat.PlainText;
        IList<string> lstAttachments=new List<string>();
        using(ImapClient imapClient=GetClient()) {
            imapClient.SelectFolder("INBOX");
            mailMessage=imapClient.FetchMessage(pendingMessage);
            imapClient.Disconnect();
        }
        if(null==mailMessage) {
            return null;
        }
        if(mailMessage.IsBodyHtml) {
            bodyFormat=EMailBodyFormat.Html;
        }
        int attachmentNumber=0;
        foreach(Attachment attachment in mailMessage.Attachments) {
            attachmentNumber++;
            string attachmentName=ScrubFileName(attachment.Name, attachmentNumber);
            lstAttachments.Add(attachmentName);
        }
        IPendingMessage message=new PendingMessage(pendingMessage);
        IncomingMessage incomingMsg=new IncomingMessage(mailMessage, message, bodyFormat, lstAttachments);
        return incomingMsg;
    }
}

private ImapClient GetClient() {
    var client=new ImapClient(config.Server, config.Port, config.UserName, config.Password);
    client.Timeout=10 * 1000;
    client.Connect(true);
    client.SelectFolder(config.SourceFolder);
    return client;
}

private static string ScrubFileName(string currentFileName, int attachmentNumber) {
    string newFileName=ReplaceInvalidCharacters(Path.GetInvalidFileNameChars(), "", currentFileName);
    if(newFileName==currentFileName) {
        return currentFileName==null?currentFileName:currentFileName.Trim();
    }
    newFileName=string.IsNullOrEmpty(newFileName) ? "RenamedAttachment" + attachmentNumber : newFileName.Trim();
    if(newFileName.StartsWith(".")) {
        newFileName="RenamedAttachment" + attachmentNumber + newFileName;
    }
    return newFileName;
}

You can find comments in thread 331176 as they might be relevant in duplicating the behavior.

We are using Aspose.Network 6.7.0.0

Please advise.

Jm

Hi Jm,

Thanks for the details, but sorry I still could not reproduce the Chinese like characters behavior using ImapClient class. I tried with a locally installed IMAP server as well as IMAP service of MS Exchange. What I did with the messages is that I first added these to the Outlook Inbox which in turn synced these messages with the IMAP server. Then I used ImapClient to fetch these messages and converted to TIF.

Could you please test the following , as you already noticed if these are saved in EML/MSG, they work correctly.

public IIncomingMessage GetMessage(string pendingMessage) {

MailMessage mailMessage;

EMailBodyFormat bodyFormat=EMailBodyFormat.PlainText;

IList<string> lstAttachments=new List<string>();

using(ImapClient imapClient=GetClient()) {

imapClient.SelectFolder(“INBOX”);

mailMessage=imapClient.FetchMessage(pendingMessage);

// Update here

MemoryStream stream = new MemoryStream();

mailMessage.Save(stream, MailMessageSaveType.EmlFormat);

stream.Position = 0;

mailMessage = null;

mailMessage = MailMessage.Load(stream, MessageFormat.Eml);

// End update

imapClient.Disconnect();

}

if(null==mailMessage) {

return null;

}

if(mailMessage.IsBodyHtml) {

bodyFormat=EMailBodyFormat.Html;

}

int attachmentNumber=0;

foreach(Attachment attachment in mailMessage.Attachments) {

attachmentNumber++;

string attachmentName=ScrubFileName(attachment.Name, attachmentNumber);

lstAttachments.Add(attachmentName);

}

IPendingMessage message=new PendingMessage(pendingMessage);

IncomingMessage incomingMsg=new IncomingMessage(mailMessage, message, bodyFormat, lstAttachments);

return incomingMsg;

}


Saqib,

Your suggestion works for the offending message but does NOT for every other messages.

On a side note, I tried to serialize a MailMessage object to observe the entirety of the content and got the following message:

"To be XML serializable, types which inherit from IEnumerable must have an implementation of Add(System.Object) at all levels of their inheritance hierarchy. Aspose.Network.Mail.MailMessage does not implement Add(System.Object)."

Let me know if there is a process to escalate these issues with the Aspose technical support team.

Please advise.

Thanks,

Jm

Hi Jm,

So far, we have been only able to reproduce 1 issue with an IMAP server, the MailMessage.HtmlBody is blank. This is reproducable with the latest version of Aspose.Email for .NET 1.0, which is scheduled to be fixed in the next release.

For us, reproducing issues in this case is very complex if the customers use different email clients and use different types of mail servers. We actually require either

  1. Access to the original source (test email accounts information, source messages etc) Or
  2. Exact scenario which we could replicate at our end. In this case, you may provide us complete details like which email client is used to create the erroneous emails and the name/version of Imap mail server. Any other thing like inclusion of non-English characters, attachments etc which lead us to reproduce it at our end.

The issues you have found earlier (filed as 31236) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.