folder.Search 不准确
问题描述 场景:是获取client的 folder.Search获取qq未读邮箱,现在邮件有3个未读邮箱,现在执行可以查出3个,但是然后 我手动邮箱 更改1个已读,现在在执行查询还是 3个未读, 执行几次 都是 ,然后 在执行 folder.Search 几十次 ,然后才查出2个
I can't read Chinese(?) text. You'll have to find a way to ask in English.
First of all, thank you for your reply
Problem description
Scenario: it is to get the client's folder.search to get the QQ unread mailbox. Now there are three unread mailboxes in the mail, and three can be found by executing it now. However, I manually change one read mailbox. Now I am executing the query or three unread mailboxes, which are executed several times, and then I execute folder.search dozens of times, and then I find two
The search interface is correct, but there is no way to query the results in real time. There is a delay. For example, when I change an email, the query is still the result set of the previous query
Example:
using (var client = new ImapClient())
{
client.Connect(this.Host, this.ImapPort, true);
client.Authenticate(this.Account, this.PassWord);
var folder = client.GetFolder("INBOX");
folder.Open(FolderAccess.ReadWrite);
var uniqueIds = folder.Search(SearchQuery.NotSeen);
Console.WriteLine(uniqueIds.Count);
}
MailKit's ImapClient doesn't cache anything, it always sends the query directly to the server to get the latest response from the server.
In my experience, many IMAP servers do not synchronize state between multiple connections instantaneously. You often have to wait to get updates.
In other words, if Client 1 (let's say it's a webmail client) marks a message as \Seen, Client 2 (e.g. MailKit in your case) won't see that change instantly.
You can try using ImapClient.NoOp() or ImapFolder.Check() to see if that fixes it. You could also try closing and re-opening the ImapFolder. That seems to work with some IMAP servers.
Can you provide a link to the imapclient. NOOP () or imapfolder. Check Links?
There are the following questions
I don't quite understand what you said. After client 1 changes, it won't be synchronized to client 2?
But I called the search interface again
ImapClient.NoOp() ImapFolder.Check()
I don't quite understand what you said. After client 1 changes, it won't be synchronized to client 2?
Correct. Not all IMAP server implementations synchronize their connections correctly. QQ obviously doesn't, for example.
But I called the search interface again
Doesn't matter. It's up to the IMAP server to synchronize. It's a bug (or a "feature") in the server.