Example #1
0
        public virtual void GetMessages(string start, string end, bool uid, bool uidsonly, bool headersonly, bool setseen, Action <MailMessage> processCallback)
        {
            GetMessages(start, end, uid, uidsonly, headersonly, setseen, (stream, size, imapHeaders) =>
            {
                var mail = new MailMessage {
                    Encoding = Encoding
                };
                mail.Size = size;

                if (imapHeaders["UID"] != null)
                {
                    mail.Uid = imapHeaders["UID"];
                }

                if (imapHeaders["Flags"] != null)
                {
                    mail.SetFlags(imapHeaders["Flags"]);
                }

                mail.Load(_Stream, headersonly, mail.Size);

                foreach (var key in imapHeaders.AllKeys.Except(new[] { "UID", "Flags", "BODY[]", "BODY[HEADER]" }, StringComparer.OrdinalIgnoreCase))
                {
                    mail.Headers.Add(key, new HeaderValue(imapHeaders[key]));
                }

                processCallback(mail);

                return(mail);
            });
        }
Example #2
0
        public virtual MailMessage[] GetMessages(string start, string end, bool uid, bool headersonly, bool setseen)
        {
            var x = new List <MailMessage>();

            GetMessages(start, end, uid, false, headersonly, setseen, (stream, size, imapHeaders) =>
            {
                var mail = new MailMessage {
                    Encoding = Encoding
                };
                mail.Size = size;

                if (imapHeaders["UID"] != null)
                {
                    mail.Uid = imapHeaders["UID"];
                }

                if (imapHeaders["Flags"] != null)
                {
                    mail.SetFlags(imapHeaders["Flags"]);
                }

                mail.Load(_Stream, headersonly, mail.Size);

                foreach (var key in imapHeaders.AllKeys.Except(new[] { "UID", "Flags", "BODY[]", "BODY[HEADER]" }, StringComparer.OrdinalIgnoreCase))
                {
                    mail.Headers.Add(key, new HeaderValue(imapHeaders[key]));
                }

                x.Add(mail);

                return(mail);
            });

            return(x.ToArray());
        }