Exemple #1
0
        public virtual async Task <MailMessage[]> GetMessagesAsync(string start, string end, bool uid, Scope scope, bool setseen)
        {
            var x = new List <MailMessage>();

            await GetMessagesAsync(start, end, uid, scope, setseen,
                                   async (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"]);
                }

                await _Stream.EnsureBufferAsync(mail.Size);
                mail.Load(_Stream, scope, mail.Size);

                foreach (var key in imapHeaders.Keys.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());
        }
        public virtual async Task<MailMessage[]> GetMessagesAsync(string start, string end, bool uid, Scope scope, bool setseen)
        {
            var x = new List<MailMessage>();

            await GetMessagesAsync(start, end, uid, scope, setseen,
                async (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"]);

                    await _Stream.EnsureBufferAsync(mail.Size);
                    mail.Load(_Stream, scope, mail.Size);

                    foreach (var key in imapHeaders.Keys.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();
        }