Subject: DA ahead Cali schedule taken to the HA market 01/02/02
Importance: Low
----------------------------
Is this configurable in any way? I know I could always strip the first line in the text output, but wanted to see if there was a way to have Aspose handle it on the way out.
We need to reproduce this issue here, therefore you are requested to share the source emails along with the code used for converting them to text file. It will help us to observe the problem and provide assistance accordingly. Please try to provide simple console application which can be compiled and executed here.
I’ve attached an MSG and an EML, as well as a class with 2 unit tests outlining the behavior i’m seeing. Let me know if you need anything else, Thanks!
While saving the email to MHTML, please use MhtFormatOptions.HideExtraPrintHeader option to avoid writing the extra information to output as shown in the code sample below. You can also refer to our documentation section, Saving to MHTML with Optional Settings, for further information in this regard.
I adjusted my code to use those mht format options, and now my text file has 2 headers. It looks like the top-most header is correct. I tried the setting:
txtOptions.setExportHeadersFooters(false);
with similar results.
I must be missing another setting somewhere.
Example text output:
From: Zoom.Quiet
Sent: Mon, 14 Aug 2006 10:25:01 +0000
To: ubuntu-zh@lists.ubuntu.com
Subject: [Ubuntu-zh] [Wiki]样式错乱!
Attachments: 2006-08-14-181636_418x105_scrot.png
Zoom.Quiet
From: Zoom.Quiet
Sent: Mon, 14 Aug 2006 10:25:01 AM GMT
To: ubuntu-zh@lists.ubuntu.com
Subject: [Ubuntu-zh] [Wiki]样式错乱!
Attachments: 2006-08-14-181636_418x105_scrot.png
如图!
用户登录 Wiki 后,一些快捷链接在主导航之后了!不能点击!
实际上,登录链接就已经不能点击了!
–
“”“Time is unimportant, only life important!
blogging : http://blog.zoomquiet.org/pyblosxom/
wiki enter: http://wiki.woodpecker.org.cn/moin/ZoomQuiet
in douban: http://www.douban.com/people/zoomq/
If we run the following simplified code with your sample input files, the intermediate output MHTML and finalized text files generated do not exhibit the issue of dual headers as you have specified. Could you please make sure that you are using the latest versions of the Aspose.Email and Aspose.Words APIs at your end?
Sample Code
MailMessage eml = MailMessage.load(“845521\98.msg”, new MsgLoadOptions());
// Save as Mht with header
MhtSaveOptions mhtSaveOptions = new MhtSaveOptions();
int iSaveOptions = MhtFormatOptions.WriteHeader | MhtFormatOptions.HideExtraPrintHeader;
mhtSaveOptions.setMhtFormatOptions(iSaveOptions);
eml.save(“845521\98_out.mhtml”, mhtSaveOptions);
final Document document = new Document(“845521\98_out.mhtml”);
Ok It would appear that formatting the email through the (now deprecated) MhtMessageFormatter was at fault for the dual headers. Not sure that that was about so I figured i’d try to format my date/times the “non deprecated way”. Couldn’t find documentation on how to do that, but turns out there is a “DateTime” key you can add to the format templates to do what MhtMessageFormatter was doing.
Is there a page in the documentation that outlines all of the format templates and how they’re used?
Here is the “simplified” working code from above, along with the date/time formatting I required:
Thanks for the help Kashif.
@Test public void TestExtractTextFromMsgAsposeCode() throws Exception { MailMessage eml = MailMessage.load(“98.msg”, new MsgLoadOptions()); TimeZone timezone = TimeZone.getTimeZone(“GMT”); String dateTimeFormat = “ddd, d MMM yyyy h:mm:ss a '” + timezone.getID() + “’”; // Save as Mht with header MhtSaveOptions mhtSaveOptions = MhtSaveOptions.getDefaultMhtml(); mhtSaveOptions.setMhtFormatOptions(MhtFormatOptions.WriteHeader | MhtFormatOptions.HideExtraPrintHeader); if (mhtSaveOptions.getFormatTemplates().containsKey(“DateTime”)) { mhtSaveOptions.getFormatTemplates().set_Item(“DateTime”, dateTimeFormat); } else { mhtSaveOptions.getFormatTemplates().add(“DateTime”, dateTimeFormat); }
eml.setTimeZoneOffset(timezone.getOffset(eml.getDate().getTime())); eml.save(“98_out.mhtml”, mhtSaveOptions); final Document document = new Document(“98_out.mhtml”); TxtSaveOptions txtOptions = new TxtSaveOptions(); txtOptions.setSaveFormat(SaveFormat.TEXT); txtOptions.setEncoding(Charsets.UTF_8); txtOptions.setExportHeadersFooters(true); txtOptions.setPrettyFormat(true); txtOptions.setPreserveTableLayout(true); document.save(“98_out.txt”, txtOptions); }
You can find information about the format templates in one of our documentation examples, Rendering events during conversion to MHTML. We are glad that the suggested code sample helped you in this regard. Please feel free to write to us in case you have any further inquiry in this regard.