+1 vote
by (140 points)

We have some MSG and EML files modified with Apache POI and are attempting to load them with Rebex in our C# environment. The EML works fine however the MSG is throwing errors. Is there some way to enable logging or see more details about these errors so we can adjust our MSG files accordingly? We're trying to use OutlookMessage.Load(string fileName) from Rebex. Outlook is able to open and view the emails and attachments fine.

Sample error messages when trying to load the files with Rebex:
Stream length for the AttachRendering property (ID:0x37090102) is invalid.

Stream length for the AttachDataBinary property (ID:0x37010102) is invalid.

I'll continue to look at the MSG spec to see if we've missed something when modifying the attachments in the MSG but hopefully someone here has an idea.

2 Answers

0 votes
by (70.2k points)

The error says that the 'length' of the OLE-file-stream (where the data is stored) does not correspond to the 'byte count' specified by the MSG property.

We failed to load the MSG file because it is safer. Outlook probably works with the shorter value or ignores the property completely.

Is it possible for you to send us the problematic file(s) to support@rebex.net for analysis? We can then tell the exact cause of the issue. We can also mimic Outlook behavior if it is reasonable.

P.S: if you want to send the problematic file via email, please attach it as compressed file to prevent modifications along the way.

by (140 points)
Thanks, I probably missed the `byte count` property and need to update that. I'll try some more today to get that updated and loaded with Rebex.  If that doesn't work I'll send you MSG file and maybe you could point me to the property ID that I'm missing.

Thank you for your time and the info.
by (140 points)
I believe I see the issue with our MSG attachment properties.  For some reason they're not being updated like we expected them to be.  I'll report back if we're able to solve it.
+1 vote
by (70.2k points)

Thank you for sharing the MSG file with us.
I have analyzed the 13315453897600986597.msg file and it showed that the 'stream length' is 62542, but the 'byte count' specified by the PidTagAttachDataBinary property is 62084.

I have extracted the data from the stream and it seems the 62542 value is correct (the 62084 length would produce incomplete PDF file).

Also, if I save the attachment from the Outlook, the saved file is 62542 bytes length.

However the MS-OXMSG specification for variable length data clearly says:

Size MUST be equal to the size of the stream where the value of the property represented by this entry is stored.

If you manipulate the attachment data yourself, please update the corresponding property 'Size' ('byte count') value appropriately to produce valid MSG file.

What are you using for updating attachment data?
We have the MsgMessage class, which can do this task correctly. It is available on our labs page https://www.rebex.net/msg/.
However, we plan to include the MsgMessage class in our main product.
To update attachment data you can just do:

var msg = new MsgMessage();
msg.Attachments[0].Properties.SetValue<byte[]>(MsgPropertyTag.AttachDataBinary, newContentBytes);
by (140 points)
Thanks again for the information.  I was able to correct our process to edit the MSG attachment properties correctly and we can now load our modified MSG files with Rebex.