This project is read-only.

Searching by uid or subject...

Jun 1, 2009 at 3:09 PM
Edited Jun 3, 2009 at 8:08 AM

Hi,

I didn't find in this class a method to select one mail by its message id. Can anybody suggest a solution to find a mail message in the selected folder by its unique message id?

 

Thanks


I found a solution:

This method search on the selected folder for a message with specified uid...

public ImapMailboxMessage SearchMailByUID(string uid)
        {
            if (!(Connection.ConnectionState == ConnectionState.Open))
                NoOpenConnection();
            Connection.Write(string.Format("search all header message-id \"<{0}>\"\r\n", uid.ToString()));
            string response = Connection.Read();
            if (response.StartsWith("*"))
            {
                Connection.Read();
                MatchCollection matches = Regex.Matches(response, @"\d+");
                if (matches.Count > 0)
                {
                   int[] ids = new int[1];
                    for (int i = 0; i < matches.Count; i++)
                        ids[i] = Convert.ToInt16(matches[i].Value);

                    return Fetch(ids);
                }
            }
            return new ImapMailbox().Messages[0];
        }

 

Thanks;