示例#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
        /// <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);
        }
示例#3
0
        /// <summary>
        /// Creates the mail message from entity.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <returns></returns>
        public static MailMessageEx CreateMailMessageFromEntity(MimeEntity entity)
        {
            MailMessageEx message = new MailMessageEx();
            string        value;

            foreach (string key in entity.Headers.AllKeys)
            {
                value = entity.Headers[key];
                if (value.Equals(string.Empty))
                {
                    value = " ";
                }

                message.Headers.Add(key.ToLowerInvariant(), value);

                switch (key.ToLowerInvariant())
                {
                case MailHeaders.Bcc:
                    MailMessageEx.PopulateAddressList(value, message.Bcc);
                    break;

                case MailHeaders.Cc:
                    MailMessageEx.PopulateAddressList(value, message.CC);
                    break;

                case MailHeaders.From:
                    message.From = MailMessageEx.CreateMailAddress(value);
                    break;

                case MailHeaders.ReplyTo:
                    message.ReplyTo = MailMessageEx.CreateMailAddress(value);
                    break;

                case MailHeaders.Subject:
                    message.Subject = value;
                    break;

                case MailHeaders.To:
                    MailMessageEx.PopulateAddressList(value, message.To);
                    break;
                }
            }

            return(message);
        }