MailKit Imap 仅获取 messageId

MailKit Imap Get only messageId

标题总结了它。我需要从 Imap 文件夹中获取所有 MessageId 属性,而无需下载整封邮件。

...
IMailFolder inbox = imapClient.Inbox;
SearchQuery query = SearchQuery.All;

IList<UniqueId> idsList = inbox.Search(query);

foreach (var uid in idsList)
{
  MimeMessage message = inbox.GetMessage(uid);//This gets the entire message
    //but I only need the .MessageId, without getting the other parts
    if (message != null)
    {
       string messageId = message.MessageId;
    }
}
...

试试这个:

var summaries = client.Inbox.Fetch (0, -1, MessageSummaryItems.Envelope);
foreach (var message in summaries) {
    Console.WriteLine (message.Envelope.MessageId);
}

这应该能满足您的需求。