We use Aspose Total Java, now we have such a problem:
There is such a test file, if you open it with Outlook, you will find that this Email contains an attached file. If you use Outlook to save this attachment, the file extension will be “.msg”
However, if we use Aspose Email to download this attachment, there is no file extension at all.
Here it is our code, and it has the problem I mentioned here
final MapiMessage msg = MapiMessage.fromMailMessage(emailFilename);
Files.createDirectories(Paths.get(tempDir));
final ArrayList<String> result = new ArrayList<>(1);
for (int i = 0; i < msg.getAttachments().size(); i++)
{
//Set a reference to the MapiAttachment object
final MapiAttachment outlookMessageAttachment = (MapiAttachment) msg.getAttachments().get_Item(i);
if(downloadInlineAttachmentAllowed || !outlookMessageAttachment.isInline())
{
//Display attachment type
Log.info(AsposeHelper.class, "Att Type : " + outlookMessageAttachment.getMimeTag());
Log.info(AsposeHelper.class, "File name : " + outlookMessageAttachment.getLongFileName());
String attachmentName = outlookMessageAttachment.getDisplayName();
//... ...
}
}
I have also tried your code, and it works, however the result of getMimeTag() of your code is null.
So the real question is, what is the difference between MapiMessage.fromMailMessage(String filename) and MapiMessage.load(filename)?
You have shared a file in Outlook MSG format (Test-Email 9.msg). The “MapiMessage.fromMailMessage” method in your case performs a double conversion. Outlook MSG will be converted to MIME format and then back to Outlook MSG:
final MapiMessage msg = MapiMessage.fromMailMessage(emailFilename);
Instead, use the “MapiMessage.load” method to load the Outlook MSG format message:
final MapiMessage msg = MapiMessage.load(emailFilename);
The original message does not have an attachment property “PR_ATTACH_MIME_TAG”(getMimeTag() is null).
You can determine the attachment type as an embedded message in a loop:
//Display attachment type
if (outlookMessageAttachment.getObjectData() != null && outlookMessageAttachment.getObjectData().isOutlookMessage())
System.out.println("Att Type : Outlook Message");
else
System.out.println("Att Type : " + outlookMessageAttachment.getMimeTag());
1.Outlook MSG will be converted to MIME format, all MAPI properties will be lost.
Embedded Attachment will be converted from Outlook MSG format to MIME format and added with Content-Type: message/rfc822
2.Mime message will be converted to Outlook MSG
A property PR_ATTACH_MIME_TAG = message/rfc822 will be created for the embedded attachment