MailKit Imap 获取邮件的已读和未读状态

MailKit Imap get read and unread status of a mail

我正在使用 MailKit 从 gmail 帐户读取邮件。效果很好。但是,我想获取消息状态,例如是否已读、未读、重要、已加星标等。MailKit 可以吗?我似乎找不到任何相关信息。

这是我的代码:

 var inbox = client.Inbox;
 var message = inbox.GetMessage(4442);//4442 is the index of a message.

 Console.WriteLine("Message Importance : {0}", message.Importance);
 Console.WriteLine("Message Priority : {0}", message.Priority);

重要性和优先级总是 returns "Normal"。如何发现这条消息被标记为重要或不重要?以及如何获取此消息的已读或未读状态?

没有消息 属性 因为 MimeMessage 只是经过解析的原始 MIME 消息流,而 IMAP 不会将这些状态存储在消息流中,而是单独存储它们。

要获取所需信息,您需要使用 Fetch() 方法:

var info = client.Inbox.Fetch (new [] { 4442 }, MessageSummaryItems.Flags | MessageSummaryItems.GMailLabels);
if (info[0].Flags.Value.HasFlag (MessageFlags.Flagged)) {
    // this message is starred
}
if (info[0].Flags.Value.HasFlag (MessageFlags.Draft)) {
    // this is a draft
}
if (info[0].GMailLabels.Contains ("Important")) {
    // the message is Important
}

希望对您有所帮助。