如何在mailkit中获取uid?

how to get uid in mailkit?

我的代码是:

 using (ImapClient client = new ImapClient())
 {
     // Connect to the server and authentication and then 
     var inbox = client.Inbox;
     inbox.Open(FolderAccess.ReadOnly);
     int messageCount = inbox.Count - 1;
     for (int i = messageCount; i > 0 ; i--)
     {
           var visitor = new HtmlPreviewVisitor();
           MimeMessage message = inbox.GetMessage(i);
           message.Accept(visitor);
           // how can get uid for this message
     }
 }

我想保存uid。如何获取消息的 uid?

MimeMessage message =inbox.GetMessage(UniqueId.Parse(uid));

使用 MailKit 获取特定消息的 UID 的方法是在 ImapFolder 实例上使用 Fetch() 方法并将 MessageSummaryItem.UniqueId 枚举值传递给它。

通常,在 获取实际邮件之前,您需要获取文件夹 中邮件的 UID,如下所示:

// fetch some useful metadata about each message in the folder...
var items = folder.Fetch (0, -1, MessageSummaryItems.UniqueId | MessageSummaryItems.Size | MessageSummaryItems.Flags);

// iterate over all of the messages and fetch them by UID
foreach (var item in items) {
    var message = folder.GetMessage (item.UniqueId);

    Console.WriteLine ("The message is {0} bytes long", item.Size.Value);
    Console.WriteLine ("The message has the following flags set: {0}", item.Flags.Value);
}

Flags 包括 SeenDeletedAnswered 等内容。Flagged 标志表示消息已被标记为 "important" 由用户。