Esempio n. 1
0
 private void BuildMultiPartMessage(MimeEntity entity, MailMessageEx message)
 {
     foreach (MimeEntity entity2 in entity.Children)
     {
         if (entity2 != null)
         {
             if (string.Equals(entity2.ContentType.MediaType, MediaTypes.MultipartAlternative, StringComparison.InvariantCultureIgnoreCase) || string.Equals(entity2.ContentType.MediaType, MediaTypes.MultipartMixed, StringComparison.InvariantCultureIgnoreCase))
             {
                 this.BuildMultiPartMessage(entity2, message);
             }
             else if (!IsAttachment(entity2) && (string.Equals(entity2.ContentType.MediaType, MediaTypes.TextPlain) || string.Equals(entity2.ContentType.MediaType, MediaTypes.TextHtml)))
             {
                 message.AlternateViews.Add(this.CreateAlternateView(entity2));
                 this.SetMessageBody(message, entity2);
             }
             else if (string.Equals(entity2.ContentType.MediaType, MediaTypes.MessageRfc822, StringComparison.InvariantCultureIgnoreCase) && string.Equals(entity2.ContentDisposition.DispositionType, "attachment", StringComparison.InvariantCultureIgnoreCase))
             {
                 message.Children.Add(this.ToMailMessageEx(entity2));
             }
             else if (IsAttachment(entity2))
             {
                 message.Attachments.Add(this.CreateAttachment(entity2));
             }
         }
     }
 }
Esempio n. 2
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());
        }
Esempio n. 3
0
        private MailMessageEx ToMailMessageEx(MimeEntity entity)
        {
            if (entity == null)
            {
                return(null);
            }
            MailMessageEx message = MailMessageEx.CreateMailMessageFromEntity(entity);

            if (!string.IsNullOrEmpty(entity.ContentType.Boundary))
            {
                message = MailMessageEx.CreateMailMessageFromEntity(entity);
                this.BuildMultiPartMessage(entity, message);
                return(message);
            }
            if (string.Equals(entity.ContentType.MediaType, MediaTypes.MessageRfc822, StringComparison.InvariantCultureIgnoreCase))
            {
                if (entity.Children.Count < 0)
                {
                    throw new Pop3Exception("Invalid child count on message/rfc822 entity.");
                }
                message = MailMessageEx.CreateMailMessageFromEntity(entity.Children[0]);
                this.BuildMultiPartMessage(entity, message);
                return(message);
            }
            message = MailMessageEx.CreateMailMessageFromEntity(entity);
            this.BuildSinglePartMessage(entity, message);
            return(message);
        }
Esempio n. 4
0
 public static void PopulateAddressList(string addressList, MailAddressCollection recipients)
 {
     foreach (MailAddress current in MailMessageEx.GetMailAddresses(addressList))
     {
         recipients.Add(current);
     }
 }
Esempio n. 5
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);
        }
Esempio n. 6
0
        private void SetMessageBody(MailMessageEx message, MimeEntity child)
        {
            Encoding encoding = child.GetEncoding();

            message.Body         = this.DecodeBytes(child.Content.ToArray(), encoding);
            message.BodyEncoding = encoding;
            message.IsBodyHtml   = string.Equals(MediaTypes.TextHtml, child.ContentType.MediaType, StringComparison.InvariantCultureIgnoreCase);
        }
Esempio n. 7
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);
        }
Esempio n. 8
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;
        }
Esempio n. 9
0
 private void BuildSinglePartMessage(MimeEntity entity, MailMessageEx message)
 {
     this.SetMessageBody(message, entity);
 }