Why can Aspose Email shows 3 Attachment files instead of the correct 2?

I have such a test Email:
gurkovtest.zip (40,9 KB)

and I use following code:

    final MapiMessage msg = MapiMessage.fromMailMessage(emailFilename);

    final String dataDir = "./AsposeTemp/";
    Files.createDirectories(Paths.get(dataDir));

    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);
        //Display attachment type
        System.out.println("Att Type : " + outlookMessageAttachment.getMimeTag());
        //Display attached file name
        System.out.println("File Name : " + outlookMessageAttachment.getLongFileName());
        //Save attachment to the disk
        outlookMessageAttachment.save(dataDir + outlookMessageAttachment.getDisplayName());
    }

when I set a breakpoint at “msg.getAttachments().size()”, its actually value is 3, although my test Email has only 2 attachment files.

The console output is

Att Type : application/octet-stream
File Name : image001.jpg
Att Type : application/octet-stream
File Name : Original_Message.eml
Att Type : image/jpeg
File Name : image001.jpg

Hello @zwei,

There’s no Aspose.Email omission here.
One of the attachments is an image in the message body (look at the attached screenshot).
1.png (32.6 KB)

Thank you for your response, however, is there a way to download only such files in attachments, but not in message body? In this case, only 1 and 2 should be downloaded, not 3.

Hello @zwei ,

In response to your question, let me inform you that in order to distinguish between normal attachments and inline attachments, the MapiAttachment class has a method isInline() that returns ‘false’ if the attachment is normal.

The code sample below will show you how it works:

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 (!outlookMessageAttachment.isInline()) {
        //Display attachment type
        System.out.println("Att Type : " + outlookMessageAttachment.getMimeTag());
        //Display attached file name
        System.out.println("File Name : " + outlookMessageAttachment.getLongFileName());
        //Save attachment to the disk
        outlookMessageAttachment.save(dataDir + outlookMessageAttachment.getDisplayName());
  }
}
1 Like

Wow! Thank you very much, that is exactly what I wanted!

@zwei ,

Good! Thank you for the feedback.