Esempio n. 1
0
        private static void DumpMessages(List<string> paramNames, ImapClient client, ImapFolder f, string upperCmd)
        {
            long lowUid = 1;
            long highUid = f.UidNext;

            string dumpRange = upperCmd.Substring("DUMP".Length).Trim();
            var rangeArgs = dumpRange.Split(new char[] { ':', ' ', '-' }, StringSplitOptions.RemoveEmptyEntries);
            if (rangeArgs.Length > 0)
            {
                if (!long.TryParse(rangeArgs[0], out lowUid))
                {
                    lowUid = 1;
                }
            }

            if (rangeArgs.Length > 1)
            {
                if (!long.TryParse(rangeArgs[1], out highUid))
                {
                    highUid = f.UidNext;
                }
            }

            System.Console.WriteLine("Fetching UIDs in range [{0}:{1}] from folder [\"{2}\"]...",
                lowUid, highUid, client.SelectedFolder.Name);

            long[] msUids = client.FetchUids(lowUid, highUid, true).ToArray();

            System.Console.WriteLine("Fetching [{0}] headers...", msUids.Length);

            const int HeaderBlockSize = 1000;

            for (int i = 0; i < msUids.Length; i += HeaderBlockSize)
            {
                int j = i + HeaderBlockSize;

                if (j >= msUids.Length)
                {
                    j = msUids.Length - 1;
                }

                ImapFetchOption opts =
                    ImapFetchOption.Envelope
                    | ImapFetchOption.BodyStructure
                    | ImapFetchOption.Flags;

                ImapMessage[] ms = client.FetchMessages(msUids[i], msUids[j], opts, paramNames).ToArray();

                foreach (ImapMessage m in ms)
                {
                    DumpMessageInfo(m);
                    System.Console.WriteLine();
                }
            }
        }