+1 vote

I tried searching IMAP email from a .net application:

List<long> uids = imap.Search().Where(
    Expression.And(
        Expression.To("example1@domain.com"),
        Expression.HasFlag(Flag.Unseen)))

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?

by

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:
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));
}
by (298k points)
...