Bug 47991 - HSMF - All .msg attachments have zeros at the end of the files
Summary: HSMF - All .msg attachments have zeros at the end of the files
Status: RESOLVED WORKSFORME
Alias: None
Product: POI
Classification: Unclassified
Component: HSMF (show other bugs)
Version: 3.6-dev
Hardware: PC Windows XP
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-10-13 04:52 UTC by yoda
Modified: 2010-06-01 03:37 UTC (History)
0 users



Attachments
Test files as zip, contains msg and attachments before and after processing (4.19 KB, application/x-zip-compressed)
2009-12-11 04:00 UTC, yoda
Details

Note You need to log in before you can comment on or make changes to this bug.
Description yoda 2009-10-13 04:52:49 UTC
If an attachment is read from a msg file via the getAttachmentFiles() of the MapiMessage class and streamed to a file, the result will be a file with even length and lots of zeros in the end. For example a PDF file ends with %%EOF{CR}, but the attachment from the msg show in an editor: %%EOF{CR}{NUL}{NUL}{NUL}{NUL}{NUL}{NUL}{NUL}{NUL}{NUL}{NUL}{NUL}.

Just compare the original files that were put into the msg and the result of the getAttachmentFiles() method using a diff tool and you will see. Outlook extracts the attachments correctly by the way, it seems to know the exact length of the files.
Comment 1 Nick Burch 2009-11-03 16:10:11 UTC
Can you upload a sample .msg file with an attachment that displays this behaviour? We'll want to use that so we have something to test a fix against
Comment 2 yoda 2009-12-11 04:00:00 UTC
Created attachment 24690 [details]
Test files as zip, contains msg and attachments before and after processing

My sample code:

MAPIMessage mapiMsg = new MAPIMessage( new FileInputStream( new File("plain.msg") ) );
Map<String, ByteArrayInputStream> atts = mapiMsg.getAttachmentFiles();
if( atts != null && atts.size() == 1 )
{
	String attName = atts.keySet().iterator().next();
	ByteArrayInputStream att = atts.get( attName );
	FileUtils.stream( att, new FileOutputStream( new File("after.txt") ) );
}
Comment 3 Nick Burch 2009-12-11 04:43:39 UTC
Please do keep looking for a file that displays this problem, and which you can share. Without the message to investigate, there's unfortunately nothing we can do to fix it.
Comment 4 yoda 2010-06-01 03:37:51 UTC
I tried again with the newer revision 898295 (Jan 12 2010) and it seems to work now for me, but you and me should keep an eye on it :-)