Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MailKit Imap get read and unread status of a mail

I am using MailKit to read messages from a gmail account. Works great. But, I want to get the message status as whether its read, unread, important, starred etc. Is this possible with MailKit? I can´t seem to find anything about it.

Here is my code:

 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);

Importance and priority always returns "Normal". How to find this message is marked as important or not? and how to get read or unread status of this message?.

like image 537
karthikkumar subramaniam Avatar asked Jan 08 '16 12:01

karthikkumar subramaniam


1 Answers

There is no message property because a MimeMessage is just the parsed raw MIME message stream and IMAP does not store those states on the message stream, it stores them separately.

To get the info you want, you'll need to use the Fetch() method:

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
}

Hope that helps.

like image 91
jstedfast Avatar answered Nov 07 '22 23:11

jstedfast