7

我正在使用 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);

重要性和优先级始终返回“正常”。如何找到这条消息被标记为重要或不重要?以及如何获取此消息的已读或未读状态?

4

1 回答 1

10

没有消息属性,因为 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
}

希望有帮助。

于 2016-01-09T00:58:34.257 回答