This project is read-only.

Samples for Search

Topics: Help requests
Jan 12, 2014 at 11:24 AM
Edited Jan 12, 2014 at 12:03 PM
Any help about Search method ? any options for search messages by Subject, Date, From, To, Body, etc ?

My first code using ImapX:
            var client = new ImapX.ImapClient("imap.gmail.com", true);
            if (client.Connect() && client.Login(user, pass))
            {
                //client.Behavior.ExamineFolders = false; 
                var folder = client.Folders.Inbox;

                var query = "(label:ErroresEnvio)";
                var messages = folder.Search(query, ImapX.Enums.MessageFetchMode.Basic | ImapX.Enums.MessageFetchMode.GMailExtendedData);
            }
But I get error (search not processed).


Anyways, Not documentation for this:

Google mail extensions
Requesting additional message information
Working with labels
Working with message threads
Coordinator
Jan 12, 2014 at 2:53 PM
Hi kiquenet,

first of all, if you need to request the additional GMail data everytime, you can set it as global fetch mode:
client.Behavior.MessageFetchMode = MessageFetchMode.Basic | MessageFetchMode.GMailExtendedData;
After that, the additional data, such as labels, thread id etc. will be downloaded. To access them see following sample:
// Use the Labels property to access the collection of labels.
message.Labels;

// Use the Add and Remove method to add or remove a label
message.Labels.Add("my label");
message.Labels.Remove("my label");

// Use the GmailThread property to access thread information
message.GmailThread

// Use the GMailMessageId property to access the Gmail message id
message.GMailMessageId
The Folder.Search method is an equivalent to the IMAP SEARCH command, which means in order to use the GMail search extensions, you need to pass the required parameter X-GM-RAW first:
folder.Search("X-GM-RAW \"has:attachment in:unread\"");
If you have more questions, feel free to ask.

Greets,

Pavel