当我在searchPhrase中使用带有特殊字符的搜索命令时,我收到此错误,例如“سلام” 它在其他情况下工作正常。我也尝试过编码为UTF-8。那时没有错误,但它没有回复任何结果。
var uids = Client.Inbox.Search(SearchQuery.SubjectContains(searchPhrase));
任何建议?
答案 0 :(得分:3)
我刚刚使用MailKit在GMail上测试了这个,这就是我得到的:
S: A00000006 OK [READ-ONLY] INBOX selected. (Success)
C: A00000007 UID SEARCH RETURN () CHARSET UTF-8 SUBJECT {8+}
C: سلام
S: * ESEARCH (TAG "A00000007") UID
S: A00000007 OK SEARCH completed (Success)
错误是什么?似乎对我来说工作正常(除了我很明显在主题标题中没有任何带有该字符串的消息)。
这是我的小测试程序:
using System;
using MailKit.Net.Imap;
using MailKit.Search;
using MailKit;
using MimeKit;
namespace GMailSearchTest {
class Program
{
public static void Main (string[] args)
{
using (var client = new ImapClient (new ProtocolLogger (Console.OpenStandardOutput ()))) {
// For demo-purposes, accept all SSL certificates
client.ServerCertificateValidationCallback = (s,c,h,e) => true;
client.Connect ("imap.gmail.com", 993, true);
// Note: since we don't have an OAuth2 token, disable
// the XOAUTH2 authentication mechanism.
client.AuthenticationMechanisms.Remove ("XOAUTH2");
client.Authenticate ("xxx@gmail.com", "xxx");
client.Inbox.Open (FolderAccess.ReadOnly);
client.Inbox.Search (SearchQuery.SubjectContains ("سلام"));
client.Disconnect (true);
}
}
}
}