This is an error returned by your IMAP server (not Mail.dll).
It basically says that this server implements TEXT search expression only:
List<long> uids = imap.Search(Expression.Text("any text"));
I'd say this server is broken, as it doesn't implement required email search syntax properly.
I can't imagine it doesn't implement flag search, so get the uids of unseen messages first:
List<long> uids = imap.Search(Flag.Unseen);
Then use GetMessageInfoByUID
or even GetEnvelopeByUID as described here:
https://www.limilabs.com/blog/get-email-information-from-imap-fast
Those methods are fast, as they don't download entire email messages, but rather just meta data (from, to, subject, attachment names, ...):
List<MessageInfo> infos = imap.GetMessageInfoByUID(uids);
Then filter on the client side using MessageInfo.Envelope.To
list property:
List<long> filtered = infos
.Where(info => info.Envelope.To.Any(
to => to.GetMailboxes().Any(
m => m.Address == "test@example.com")))
.Select(info => (long)info.UID)
.ToList();
Finally download all email messages using Imap.GetMessageByUID
:
foreach (long uid in filtered)
{
IMail email = new MailBuilder().CreateFromEml(
client.GetMessageByUID(uid));
}