4
votes

When I receive a mail with attahcment(s) from Exchange via IMAP protocol using MailKit, it's missing the attachment. When I do:

string.Format("Mail has {0} attachments", mime.Attachments.Count())

It report "0", even tho that the mail itself contain a attachment (I see the attachment if I open it in Outlook client), and when I activate the IMAP protocol logging, it's clearly that it contains an attachment:

S: X-MS-Has-Attach: yes
...
S: Content-Type: message/rfc822
S: Content-Disposition: attachment;
S:  creation-date="Thu, 07 Jan 2016 09:16:53 GMT";
S:  modification-date="Thu, 07 Jan 2016 09:16:53 GMT"
...
S: X-MS-Has-Attach:
...

Funny thing is the "S: X-MS-Has-Attach:" header in the attachment part, within the same package from server.

Is this a known issue, and how do I fix it so I won't miss the attachments in these cases? It only seems to happen on some mails and occur randomly.

Using: MailKit 1.0.14.0 MimeKit 1.0.13.0

I discovered that there are new update, but I won't really update if this won't solve the issue anyway.

1

1 Answers

6
votes

In the version of MimeKit that you are using, MimeMessage.Attachments is IEnumerable<MimePart>, but a message/rfc822 part is represented by a MessagePart which does not subclass MimePart, it subclasses MimeEntity (which is the base class for MimePart).

In newer versions, MimeMessage.Attachments is IEnumerable<MimeEntity> instead, and so will include your message/rfc822 attachment.

You can work around this in your version of MimeKit by using the BodyParts property instead of the Attachments property.