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); }); }
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()); }
public virtual MailMessage GetMessage(string uid, bool headersOnly = false) { CheckConnectionStatus(); var line = SendCommandGetResponse(string.Format(headersOnly ? "TOP {0} 0" : "RETR {0}", uid)); var size = rxOctets.Match(line).Groups[1].Value.ToInt(); CheckResultOK(line); var msg = new MailMessage(); msg.Load(_Stream, headersOnly, size, '.'); msg.Uid = uid; var last = GetResponse(); if (string.IsNullOrEmpty(last)) { try { last = GetResponse(); } catch (System.IO.IOException) { // There was really nothing back to read from the remote server } } if (last != ".") { #if DEBUG System.Diagnostics.Debugger.Break(); #endif RaiseWarning(msg, "Expected \".\" in stream, but received \"" + last + "\""); } return(msg); }