Search Query Help

Topics: Help requests
Jan 21, 2014 at 3:23 PM
Edited Jan 21, 2014 at 3:33 PM
I am trying to search like
string FromEmailAddress="";

folder.Search("FROM \"" + FromEmailAddress + "\"", ImapX.Enums.MessageFetchMode.Full);
Its working well but slow if that email has 200 emails in account so i need only 1 latest email against that address. Possible?
Jan 22, 2014 at 6:19 AM
I fixed my self in source code like as below in folder.cs
internal long[] SearchMessageIds(string query = "ALL", int count = -1)
            if (_client.SelectedFolder != this && !Select())
                throw new OperationFailedException("The folder couldn't be selected for search.");

            if (query.ToUpper() == "ALL" && _client.Behavior.SearchAllNotSupported)
                query = "SINCE 0000-00-00";

            IList<string> data = new List<string>();
            if (!_client.SendAndReceive(string.Format(ImapCommands.Search, query), ref data))
                throw new ArgumentException("The search query couldn't be processed");

            var result = Expressions.SearchRex.Match(data.FirstOrDefault(Expressions.SearchRex.IsMatch) ?? "");
            if (!result.Success)
                //throw new OperationFailedException("The data returned from the server doesn't match the requirements");
                return new long[0];

            ////////////Edited by ME to get latest email
            long[] retcount;
            if (count < 0)
                retcount = result.Groups[1].Value.Trim().Split(' ').Select(long.Parse).ToArray();
                var arr = result.Groups[1].Value.Trim().Split(' ');
                retcount = arr.Reverse().Take(count).Select(long.Parse).ToArray();
            ////////////Edited by ME 
            return retcount;
            //return count < 0
            //    ? result.Groups[1].Value.Trim().Split(' ').Select(long.Parse).ToArray()
            //    : result.Groups[1].Value.Trim().Split(' ').OrderBy(_ => _).Take(count).Select(long.Parse).ToArray();
Jan 23, 2014 at 10:00 AM
Hi dotnetclassic,

thank you! Your fix is a bit complicated, actually it can be reduced to less changes. I will include it in the next update.


Jan 23, 2014 at 10:11 PM
is it possible to search messages containing a word into the subject ?

In other words, I would like to download all the UNSEEN message having a keyword into the subject.
Somethings like this:
folder.Search("UNSEEN SUBJECT '*myKeyword*'", ImapX.Enums.MessageFetchMode.Full);
note the use of the wildcard * before and after myKeyword
Jan 24, 2014 at 11:36 AM
Hi agilesferlix,

the wildcards are not needed here, simply search using this query:
folder.Search("UNSEEN SUBJECT \"myKeyword\"", ImapX.Enums.MessageFetchMode.Full);

Jan 24, 2014 at 1:55 PM
it works ! thank you !