Reputation: 11
Is there a way to fetch only all of the headers for an email in Mailkit? In AE mail there was a headersonly flag that would call the imap BODY.PEEK[HEADER] query, but in Mailkit it seems you can only fetch headers by specifying what headers you want, using
Fetch (IList<UniqueId> uids, MessageSummaryItems items, HashSet<HeaderId> fields, CancellationToken cancellationToken = default (CancellationToken)).
I tried using this fetch and all of the enums in HeaderId, but there were still quite a few headers that weren't being captured.
I also noticed that GetBodyPart has a headersonly flag, but it requires a bodypart as an input.
Upvotes: 1
Views: 1228
Reputation: 38618
If you cast the folder to an ImapFolder
, you can call:
var entity = ((ImapFolder) folder).GetBodyPart (uid, string.Empty, true);
var headers = entity.Headers;
There's also a Fetch method that takes a HashSet<string> as well, so you aren't limited to just what is available in HeaderId
Upvotes: 1