【发布时间】:2017-10-28 07:43:17
【问题描述】:
我已经能够检索到我检查的最后一封邮件之后的UID列表,因此我可以从 IMAP 服务器获取新邮件强>:
using(var client = new ImapClient())
{
//client authentication code...
var inbox = client.Inbox;
inbox.Open(FolderAccess.ReadOnly);
//msgIdx contains the UID of the last message I've checked,
// so I can retrieve all the new messages after this one.
var range = new UniqueIdRange(new UniqueId((uint) msgIdx), UniqueId.MaxValue);
IList<UniqueId> uids = inbox.Search(range, SearchQuery.All);
foreach(var uid in uids)
{
//With the following instruction I download the whole message...
var message = inbox.GetMessage(uid);
LblMessageLog.Text += uid + " Subject:" + message.Subject + " []<br/>";
}
client.Disconnect(true);
}
问题是我不想下载整个邮件,而是只下载一个特定的附件,因为我知道它会一直存在于所有邮件中。
MailKit 网站上有一个示例,但它与我在上面所做的搜索相冲突:
foreach (var summary in inbox.Fetch (0, -1, MessageSummaryItems.UniqueId | MessageSummaryItems.BodyStructure)) {
if (summary.Body is BodyPartMultipart) {
var multipart = (BodyPartMultipart) summary.Body;
var attachment = multipart.BodyParts.OfType<BodyPartBasic> ().FirstOrDefault (x => x.FileName == "cert.xml");
if (attachment != null) {
// this will download *just* the attachment
var part = inbox.GetBodyPart (summary.UniqueId, attachment);
}
}
}
如何在 UID 上进行过滤数据然后只下载电子邮件的一部分?
【问题讨论】: