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).
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);