Quantcast
Channel: ImapX 2
Viewing all articles
Browse latest Browse all 1952

New Post: Pagination of messages

$
0
0
I've modified my Folder.SearchMessageIds to allow for paging:
public long[] SearchMessageIds(string query = "ALL", int skip = -1, int count = -1)
        {
            if (_client.SelectedFolder != this && !Select())
                throw new OperationFailedException("The folder couldn't be selected for search.");

            // Examine the folder before searching
            Examine();

            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];

            IEnumerable<long> results = result.Groups[1].Value.Trim().Split(' ').Select(long.Parse).OrderByDescending(_ => _);
            if (skip > 0)
                results = results.Skip(skip);
            if (count > 0)
                results = results.Take(count);
            return results.ToArray();
        }
I would like to see a modification like this in the main source so I would not have to have my own fork separated from other bug fixes and so on that come to the main repo

Viewing all articles
Browse latest Browse all 1952

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>