Search code examples
c#.netwinformsimapimapx

How to Filter with UID in IMapX


I can successfully filter mails using these filters

imapXInboxFolder.Messages.Download(
    "SENTBEFORE 02-Feb-2016", 
     ImapX.Enums.MessageFetchMode.Tiny, 1                      
);         
// To get 1 mail sent before the date

.

imapXInboxFolder.Messages.Download(
    "FROM 'atlantatechvillage'", 
     ImapX.Enums.MessageFetchMode.Tiny, 1                      
);         
// To get 1 latest mail from a specific sender

.

imapXInboxFolder.Messages.Download(
    "UID 2345 FROM 'atlantatechvillage'", 
     ImapX.Enums.MessageFetchMode.Tiny, 1                      
);         
// Having UID 2345 and From the specific sender

So if I use only UID 2345 I can get mail with UID 2345 without any problem.

With the above filter query, the code checks for a mail with UID 2345 and whether it matches with the FROM address condition. If not exists returns null

What I really want is a query than can search for UID Greater than Or Less than a specific one which matches the specific From address Query.

I have searched all over the internet, iMapX documentation and all but no luck.


Solution

  • Here's how you could modify your last version to do what you want to do:

    // search for messages with a UID <= 2345:
    imapXInboxFolder.Messages.Download(
        "UID 1:2345 FROM 'atlantatechvillage'", 
         ImapX.Enums.MessageFetchMode.Tiny, -1                      
    );
    
    // search for messages with a UID >= 2345:
    imapXInboxFolder.Messages.Download(
        "UID 2345:* FROM 'atlantatechvillage'", 
         ImapX.Enums.MessageFetchMode.Tiny, -1                      
    );
    

    Hope that helps.