Table in msg file gets screwed when trying to convert to image

Hi,

We are using Aspose.Network & Aspose.Words to convert msg files to tif images.
We have been using Aspose.Network.dll (6.1.0.0) & Aspose.Words.dll (9.1.0.0) for above task.

Attached Outlook.msg should generate 2 tif images when below code is ran but it instead generates 8 tif images.
Outlook.msg contains table which gets screwed during execution of below code.

using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using Aspose.Words;
using Aspose.Words.Saving;
using Aspose.Network.Outlook;

namespace Test
{
class Program
{
static void Main(string[] args)
{
Aspose.Network.License licenseNetwork = new Aspose.Network.License();
licenseNetwork.SetLicense("Aspose.Network.lic");

Aspose.Words.License licenseWords = new Aspose.Words.License();
licenseWords.SetLicense("Aspose.Words.lic");

MapiMessage msg = MapiMessage.FromFile("Outlook.msg");

using (MemoryStream rtfStream = new MemoryStream())
{
TextWriter tw = new StreamWriter(rtfStream);
tw.Write(msg.BodyRtf);
tw.Flush();

Document doc = new Document(rtfStream);

ImageOptions imgOptions = new ImageOptions();
imgOptions.Resolution = (float)200;
imgOptions.TiffCompression = TiffCompression.Ccitt4;

for (int i = 0; i < doc.PageCount; i++)
doc.SaveToImage(i, 1, "image" + i.ToString() + ".tif", imgOptions);
}
}
}
}

This issue was reported from our customer as critical issue that must be fixed ASAP.
It is being used in production environment and fix is urgent.

Please provide us with an ETA for a fix so that we can tell our customer.

Thank You.

Hello

Thanks for your request. After some investigation I see that this problem is not related to Aspose.Words. The output RTF has 8 pages. Please see the following code:

MapiMessage msg = MapiMessage.FromFile("C:\\Temp\\Outlook.msg");
Stream outputFile = new FileStream("C:\\Temp\\out.rtf", FileMode.Create);
StreamWriter writer = new StreamWriter(outputFile);
writer.Write(msg.BodyRtf);
writer.Close();
outputFile.Close();

So I will move this request to Aspose.Network forum. My colleagues from Aspose.Network team will answer you shortly.

Best regards,

Hi,

Thank you for inquiry.

I have reproduced the issue at my end and logged this bug (ID: 27105). We will look into it and will inform you when it gets fixed.

Could you please try using the MailMessage class for loading the MSG file and use the below code for converting to TIF. I got the correct body text this way when converted to TIF.

MailMessage msg = MailMessage.Load(“Outlook.msg”, MessageFormat.Msg);
MemoryStream mhtStream = new MemoryStream();
msg.Save(mhtStream, MailMessageSaveType.MHtmlFromat);
mhtStream.Position = 0;

Document doc = new Document(mhtStream);
doc.Save(“test.tiff”, SaveFormat.Tiff);

Hi,

Can you give us status update on this fix?

Thanks!

Hi,

We have added a new property (BodyHtml) in MapiMessage class. This MSG file contains HTML formatted text, that’s why MapiMessage.BodyRtf does not contain correct data.

The fix would hopefully be available in the upcoming release, which is scheduled to be released at the end of this month.

The issues you have found earlier (filed as 27105) have been fixed in [this update](http://www.aspose.com/community/files/51/.net-components/aspose.network-for-.net/entry307168.aspx).

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

Hi,

Your fix works for email with HTML body when I use 'MapiMessage.BodyHtml'.

But for email with RTF body I have to use 'MapiMessage.BodyRtf'.

Is there a way to detect what my email body format is before I read the body?

I want to do:

if (body is HTML)
{
MapiMessage.BodyHtml
}
else
{
MapiMessage.BodyRtf
}

Hi,

We just found another major problem with 'MapiMessage.BodyHtml'.

It cannot process word with latin character like 'Geschäftsführer' correctly.

Please look at 'Outlook2.msg' and it's converted image using:

'MapiMessage.BodyRtf': image0.tif

vs.

'MapiMessage.BodyHtml': image0_bodyhtml.tif, image1_bodyhtml.tif

Another thing to note is that BodyHtml adds more 'Carriage Return (CR)' and makes more pages.

'Outlook2.zip' containing 4 files mentioned attached.

Thanks!

Hi,

I am sorry, currently there is no way to tell the text format of the MSG file. We will look into this further and add some property that will tell the text format. I will update you here when it becomes available.

Hi,

super50505:
We just found another major problem with ‘MapiMessage.BodyHtml’.

It cannot process word with latin character like 'Geschäftsführer' correctly.

I have logged this issue (ID: 27988) in our bug tracking system. We will look into it and will inform you once it gets fixed.

super50505:
Another thing to note is that BodyHtml adds more 'Carriage Return (CR)' and makes more pages.

I am sorry, I could not reproduce this issue at my end. The output Rtf contains 1 page and the number of CR characters seems to be equal to the number of CR characters in MSG. Please also see the test.html file which is created, it does not have extra CR characters.

using (MemoryStream rtfStream = new MemoryStream())
{
TextWriter tw = new StreamWriter(rtfStream);
tw.Write(msg.BodyHtml);
tw.Flush();

StreamWriter writer = File.CreateText("test.html");
writer.Write(msg.BodyHtml);
writer.Close();
Process.Start("test.html");
Document doc = new Document(rtfStream);
doc.Save("test.tiff", SaveFormat.Tiff);
}

Hi,

super50505:
We just found another major problem with ‘MapiMessage.BodyHtml’.

It cannot process word with latin character like 'Geschäftsführer' correctly.



To process the Unicode characters properly, please use the below code:
using (MemoryStream rtfStream = new MemoryStream())
{
// Pass Encoding.Unicode as arguments here
TextWriter tw = new StreamWriter(rtfStream, Encoding.Unicode);
tw.Write(msg.BodyHtml);
tw.Flush();
// rest of code will remain same
}

Hi,


Encoding.Unicode seems to work. Thanks!
Have comments on two other issues.


1) "I am sorry, currently there is no way to tell the text format of the MSG file. We will look into this further and add some property that will tell the text format. I will update you here when it becomes available."

Do you have an update on this? This is urgent requirement!


2) "I am sorry, I could not reproduce this issue at my end. The output Rtf contains 1 page and the number of CR characters seems to be equal to the number of CR characters in MSG. Please also see the test.html file which is created, it does not have extra CR characters."

Please look at uploaded Outlook2.zip file.
When you use 'msg.BodyRtf' it creates one tif
When you use 'msg.BodyHtml' it creates two tif

If you look at tif images in Outlook2.zip file, you will note that image created by 'msg.BodyHtml' contain extra per line when compared with image created by 'msg.BodyRtf'.
You are comparing html vs 'msg.BodyHtml'.
Please compare 'msg.BodyRtf' vs 'msg.BodyHtml'.


Thanks!

Hi,

For pt (1), we have added a new property MapiMessage.BodyType, which can tell the message body type. This feature will be included in our next release, scheduled to be available by the end of this month (June 2011).

Regarding pt (2), from the uploaded file Outlook2.zip, yes there is difference, the image0_bodyhtml.tif and image_bodyhtml.tif contain extra CR characters. But, when I convert the MSG at my end with msg.BodyHtml, I could not get these extra characters using the below code:

string strMsgFile = “Outlook2.msg”;
MapiMessage msg = MapiMessage.FromFile(strMsgFile);
using (MemoryStream rtfStream = new MemoryStream())
{
TextWriter tw = new StreamWriter(rtfStream, Encoding.Unicode);
tw.Write(msg.BodyHtml);
tw.Flush();

Document doc = new Document(rtfStream);
doc.Save(“test.tiff”, SaveFormat.Tiff);
}


Using Aspose.Network for .NET 6.5 and Aspose.Words for .NET 10.0.

The issues you have found earlier (filed as 27984 ; 27988 ) have been fixed in [this update](http://www.aspose.com/community/files/51/.net-components/aspose.network-for-.net/entry313463.aspx).

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

Issue 2798: BodyType property added.