Lucky
Lucky

Reputation: 801

EWS Java - hasAttachments return false for inline/Embedded attachments

I'm reading email with inline/embedded images, mostly sender signature image. But when I try to find if the email.hasAttachments() it returns false, but If I Inspect email.getAttachments(); it shows me the inline attachments. here is my code, am I doing something wrong.

try {
        Item itm = Item.bind(service, itemId, new PropertySet(
                BasePropertySet.FirstClassProperties,
                ItemSchema.Attachments,ItemSchema.HasAttachments,
                ItemSchema.extendedProperties));

        emailMessage = EmailMessage.bind(service, itm.getId(),
                new PropertySet(BasePropertySet.FirstClassProperties,
                        EmailMessageSchema.Attachments, EmailMessageSchema.HasAttachments));

        log.info(From: " + emailMessage.getFrom());
        log.info(Subject: " + emailMessage.getSubject());
        log.info(Received: " + emailMessage.getDateTimeReceived());

        //get email attachments.
        attachments = getEmailAttachments(emailMessage, properties);
    }

    //getEmailAttachments() method.
    try {
        //check if the email has attachments.

        if (emailMessage.getHasAttachments()) { //returns false here
            //get all the attachments
            AttachmentCollection attachmentsCol = emailMessage.getAttachments();// will return the attachments
            log.info("File Count: " +attachmentsCol.getCount());
            //loop over the attachments
            for (int i = 0; i < attachmentsCol.getCount(); i++) {
                Attachment attchment = attachmentsCol.getPropertyAtIndex(i);

                if (attchment.getIsInline()) {
                    log.info("There is an inline attachment.");
                }
                //FileAttachment - Represents a file that is attached to an email item
                if (attchment instanceof FileAttachment) {
                    //my code here
                } else if (attchment instanceof ItemAttachment) { //ItemAttachment - Represents an Exchange item that is attached to another Exchange item.
                    //my code here
                }
            }

Upvotes: 0

Views: 819

Answers (1)

Glen Scales
Glen Scales

Reputation: 22032

HasAttachments is a calculated property who's value is based on other props. One property that Outlook can set that affects this is the SmartNoAttach property (you can see the value of this prop in a Mapi Editor) which effectively hides the Paperclip in outlook where a message has an Inline attachment like signature (and no real attachments). But it will also affect this properties value in EWS.

Upvotes: 2

Related Questions