It seems that Yahoo cannot search for Message-ID (it is not fully featured IMAP server).
You have to do the search manually.
It can be done like this:
private static ImapMessageCollection SearchMessageId(Imap client, string messageId)
{
// Message-ID to search for
MessageId id = new MessageId(messageId);
// iterate through all messages
ImapMessageCollection result = new ImapMessageCollection();
var page = client.GetMessageList(ImapListFields.Envelope);
foreach (var item in page)
{
if (id.Equals(item.MessageId))
result.Add(item);
}
return result;
}
However, this code retrieves all messages. It can be very slow and the server can limit the result to only first N messages. Instead, I suggest you to perform paged list. Alternatively, you can stop search after first successful match. The method can look like this:
private static ImapMessageCollection SearchMessageId(Imap client, string messageId, int pageSize)
{
// Message-ID to search for
MessageId id = new MessageId(messageId);
// iterate through all messages
ImapMessageCollection result = new ImapMessageCollection();
for (int i = client.CurrentFolder.TotalMessageCount; i > 0; i -= pageSize)
{
var set = new ImapMessageSet();
set.AddRange(Math.Max(1, i - pageSize), i);
var page = client.GetMessageList(set, ImapListFields.Envelope);
foreach (var item in page)
{
if (id.Equals(item.MessageId))
result.Add(item);
}
if (result.Count > 0)
break;
}
return result;
}
It can be used like this:
var msgSearch = SearchMessageId(
imap,
"51564654484944321346546654.JavaMail.yahoo@mail.yahoo.com",
50);