Пример #1
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);
        }
Пример #2
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;
        }