Mailkit: When does IMailFolder.Append return null?

Created on 30 Mar 2018  路  5Comments  路  Source: jstedfast/MailKit

The family of IMailFolder.Append methods have the return type UniqueId? (or an IList<> of that). For these return values, the documentation says

The UID of the appended message, if available; otherwise, null.

Would you mind elaborating a bit here about this "if available" business? For what sorts of reasons would these methods return null?

question

Most helpful comment

probably something along the lines of:

var uids = folder.Search (SearchQuery.HeaderContains ("Message-Id", message.MessageId));
var appendedUid = uids[uids.Count - 1];

All 5 comments

If the IMAP server does not support the UIDPLUS extension, then the return value will always be null.

Theoretically, if the server supports UIDPLUS, then it should always return a valid UniqueId... but as we all know, theory and reality can vary greatly.

I see. Thanks for that explanation.

Suppose we append a single MimeMessage. How would you recommend following up a call to Append in order to obtain the UniqueId of the just appended MimeMessage?

probably something along the lines of:

var uids = folder.Search (SearchQuery.HeaderContains ("Message-Id", message.MessageId));
var appendedUid = uids[uids.Count - 1];

@jstedfast, just a small thing!
Search method returns IList<UniqueId> so you should use Count instead of Length, 馃槈

Ah, thanks, I've updated the code in my previous comment.

Was this page helpful?
0 / 5 - 0 ratings