Пример #1
0
        public MailMessageEx Top(int messageId, int lineCount)
        {
            if (messageId < 1)
            {
                throw new ArgumentOutOfRangeException("messageId");
            }

            if (lineCount < 0)
            {
                throw new ArgumentOutOfRangeException("lineCount");
            }

            RetrResponse response;

            using (TopCommand command = new TopCommand(_clientStream, messageId, lineCount))
            {
                response = ExecuteCommand <RetrResponse, TopCommand>(command);
            }

            MimeReader    reader  = new MimeReader(response.MessageLines);
            MimeEntity    entity  = reader.CreateMimeEntity();
            MailMessageEx message = entity.ToMailMessageEx();

            message.Octets        = response.Octets;
            message.MessageNumber = messageId;
            return(entity.ToMailMessageEx());
        }
Пример #2
0
 public static void PopulateAddressList(string addressList, MailAddressCollection recipients)
 {
     foreach (MailAddress current in MailMessageEx.GetMailAddresses(addressList))
     {
         recipients.Add(current);
     }
 }
Пример #3
0
        public static MailMessageEx CreateMailMessageFromEntity(MimeEntity entity)
        {
            MailMessageEx mailMessageEx = new MailMessageEx();

            string[] allKeys = entity.Headers.AllKeys;
            for (int i = 0; i < allKeys.Length; i++)
            {
                string text  = allKeys[i];
                string text2 = entity.Headers[text];
                if (text2.Equals(string.Empty))
                {
                    text2 = " ";
                }
                mailMessageEx.Headers.Add(text.ToLowerInvariant(), text2);
                string a;
                if ((a = text.ToLowerInvariant()) != null)
                {
                    if (!(a == "bcc"))
                    {
                        if (!(a == "cc"))
                        {
                            if (!(a == "from"))
                            {
                                if (!(a == "reply-to"))
                                {
                                    if (!(a == "subject"))
                                    {
                                        if (a == "to")
                                        {
                                            MailMessageEx.PopulateAddressList(text2, mailMessageEx.To);
                                        }
                                    }
                                    else
                                    {
                                        mailMessageEx.Subject = text2;
                                    }
                                }
                                else
                                {
                                    mailMessageEx.ReplyTo = MailMessageEx.CreateMailAddress(text2);
                                }
                            }
                            else
                            {
                                mailMessageEx.From = MailMessageEx.CreateMailAddress(text2);
                            }
                        }
                        else
                        {
                            MailMessageEx.PopulateAddressList(text2, mailMessageEx.CC);
                        }
                    }
                    else
                    {
                        MailMessageEx.PopulateAddressList(text2, mailMessageEx.Bcc);
                    }
                }
            }
            return(mailMessageEx);
        }
Пример #4
0
        /// <summary>
        /// Retrs the mail message ex.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <returns></returns>
        public MailMessageEx RetrMailMessageEx(Pop3ListItem item)
        {
            MailMessageEx message = RetrMimeEntity(item).ToMailMessageEx();

            if (message != null)
            {
                message.MessageNumber = item.MessageId;
            }
            return(message);
        }
Пример #5
0
        private static IEnumerable <MailAddress> GetMailAddresses(string addressList)
        {
            Regex regex = new Regex("(['\"]{1,}.+['\"]{1,}\\s+)?<?[\\w\\.\\-]+@[^\\.][\\w\\.\\-]+\\.[a-z]{2,}>?");

            foreach (Match match in regex.Matches(addressList))
            {
                yield return(MailMessageEx.CreateMailAddress(match.Value));
            }
            yield break;
        }
Пример #6
0
 public static List <MailMessageEx> Receive(string hostname, int port, bool useSsl, string username, string password)
 {
     using (Pop3Client client = new Pop3Client(hostname, port, useSsl, username, password))
     {
         client.Trace += new Action <string>(Console.WriteLine);
         client.Authenticate();
         client.Stat();
         List <MailMessageEx> maillist = new List <MailMessageEx>();
         MailMessageEx        message  = null;
         foreach (Pop3ListItem item in client.List())
         {
             message = client.RetrMailMessageEx(item);
             if (message != null)
             {
                 client.Dele(item);
                 maillist.Add(message);
             }
         }
         client.Noop();
         client.Rset();
         client.Quit();
         return(maillist);
     }
 }