+1 vote

I tried searching IMAP email from a .net application:

List<long> uids = imap.Search().Where(

But result is ImapResponseException exception:(

Limilabs.Client.IMAP.ImapResponseException: Only TEXT keyword is currently supported for fulltext search. Sorry.
   at __0000_0_00.___(ImapResponse _0)
   at __0000_0_00.__(ImapResponse _0)

I have one more important information and its that I am using Microsoft Visual Studio Community 2022 (64-bit) - Current Version 17.3.0 on target .net 6

Please can you give me some more hint?


1 Answer

0 votes
Best answer

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:

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)

Finally download all email messages using Imap.GetMessageByUID:

foreach (long uid in filtered)
    IMail email = new MailBuilder().CreateFromEml(
by (298k points)