How to Recurse Embedded Messages com.aspose.network.outlook (Java or .NET)

Hi,

Does anyone know how to recursively iterate through embedded messages within a MapiMessage (created from an .msg file)?

Imagine you have a message with embedded messages (and embedded messages within messages). How do you iterate through these correctly - regardless of Java or .NET versions…

My thought is when you come to an embedded message with the MapiAttachmentsCollection, you should be able to create this as a new MapiMessage. In order to this I have been using:

MapiMessage m = MapiMessage.FromProperties(mapiAttamentsCol.get(i).getObjectData().getMyProperties());

Programatically this does seem to work, however, it does not allow me to recurse any deeper, the MapiAttachmentsCollection is empty (even though it does have more embedded messages within it).

Can anyone help?

Cheers,

James

Here is a little code extract…

// Cheeky helper method for copying byte arrays
byte[] concatenate(byte[] a, byte[] b) {

byte[] c= new byte[a.length+b.length];

// copy both arrays (should check for null)

System.arraycopy(a, 0, c, 0, a.length);
System.arraycopy(b, 0, c, a.length, b.length);

return c;
}

// Cheeky helpder method which is used to recurse through the

// the MSG and build up a sequential byte array based on the
// message structure. All this is put into totalContent


private void buildContentArray (MapiMessage msg) {


// We start with the main body of the email and add this to the content
totalContent = msg.getBody().getBytes();
// Now we do the attachments - these are embedded messages and file attachments

MapiAttachmentCollection mapiAttamentsCol = msg.getAttachments();
for(int i=0;i < mapiAttamentsCol.size();i++)
{
// System.out.println("Att FileName:\n " + mapiAttamentsCol.get(i).

getFileName());

try {
if (mapiAttamentsCol.get(i).getBinaryData() != null) {
byte[] currentContent = mapiAttamentsCol.get(i).getBinaryData();
totalContent = concatenate(totalContent,currentContent);

} else {
MapiMessage m = MapiMessage.FromProperties(mapiAttamentsCol.get(i).getObjectData().getMyProperties());
buildContentArray(m);
}
// System.out.println("Att MD5:\n "+ hexStringFromBytes(contentHash));

} catch (Exception e) {
e.printStackTrace();
}
}
}


etc…


// In main call

MapiMessage msg = MapiMessage.FromFile(filePath + “/” + cobjectId + fileExtension);

buildContentArray(msg);







The only other way that there seems to be able to deal with this is to write out the byte stream of the embedded email (outlook item) to disk and then read this back in with the static method - MapiMessage.FromFile. This would be a nasty workaround - requiring disk i/o when it should all be done in memory?

Please get back to me with any help…

Thanks,

James

Hi James,

Sorry for replying late. I have tested reading the msg files recursively. MapiMessage.FromProperties() method does not load the embedded objects properly. We are looking into this problem and will get back to you soon.

We might fix this issue in the coming month. Till that time, you may use the alternate method MapiMessage.FromFile(). This will of course effect the performance due to disk IO.

Could you please share the time line of your project? We will try our best to set the priority accordingly.

Hi Saqib,

Thanks for getting back to me on this one... OK we will move forward with the file based approach in the interim - but absolutely we really need the permanent fix as soon as we can.

The release to market date for the product is around the middle of March. However, we would like to be pushing a beta release during the middle of February. It would therefore be good to get the fix as soon as you can. Given the version we have from you is Beta anyway, we would be more than happy with ad-hoc fixes that you send through to us - we could help you with the testing. We have some alternative Java libraries we are evaluating - but the thing we like about yours is that there is an equivalent .Net and Java library which is almost like for like. This has some advantages for us with our architecture.

Please do everything you can to get the fix to us.

Much appreciated.

Regards,

James