c# - How to get message body without downloading attachment -
i using imap4 client called: mailkit. works great, have problem on getting body of message without downloading attachments. want show mail's body text , attachments there are, if user clicks on attachment want download attachment.
i've tried:
var message = inbox.getmessage(uid, cancel.token);
but gets entire message.
also tried:
uids[0] = uid; var ms = inbox.fetch(uids, messagesummaryitems.bodystructure , cancel.token); var bp1 = inbox.getbodypart(uid, ms.first().body, cancel.token);
but again downloads attachment.
with sample code, downloading entire message because requesting top-level body part of message.
mime tree structure of "body parts". want traverse ms.first().body find part(s) want, , download them individually using getbodypart() method.
take @ mailkit.bodypartmultipart, mailkit.bodypartmessage, mailkit.bodypartbasic , mailkit.bodyparttext.
a bodypartmultipart contains other body parts.
a bodypartmessage parts contains message (which contain body part).
a bodypartbasic basic leaf-node body part - "attachment".
a bodyparttext text part (a subclass of bodypartbasic) can either attached text part or might consider main text of message.
to figure out if bodypartbasic meant displayed inline or attachment, need is:
if (part.contentdisposition != null && part.contentdisposition.isattachment) // attachment else // meant shown user part of message // (if image, meant displayed text)
i should add convenience property bodypartbasic called isattachment
make bit simpler (i'll try add today).
hope helps.
update: i've added bodypartbasic.isattachment convenience property in git master, next release of mailkit have it.
Comments
Post a Comment