Exemplo n.º 1
0
 private void Initialise()
 {
     this._blindedCarbonCopies              = new EmailAddressCollection();
     this._carbonCopies                     = new EmailAddressCollection();
     this._contentTransferEncoding          = EContentTransferEncoding.SevenBit;
     this._contentType                      = new Net.Common.ContentType();
     this._extraHeaders                     = new ExtraHeadersDictionary();
     this._isDefaultContentTransferEncoding = true;
     this._isDefaultContentType             = true;
     this._keywords = new List <string>();
     this._replyTo  = new EmailAddressCollection();
     this._resentBlindedCarbonCopies = new EmailAddressCollection();
     this._resentCarbonCopies        = new EmailAddressCollection();
     this._resentTo           = new EmailAddressCollection();
     this._comments           = string.Empty;
     this._contentDescription = string.Empty;
     this._contentId          = string.Empty;
     this._inReplyTo          = string.Empty;
     this._messageId          = string.Empty;
     this._received           = string.Empty;
     this._references         = string.Empty;
     this._resentMessageId    = string.Empty;
     this._subject            = string.Empty;
     this._text         = string.Empty;
     this._textEncoding = Encoding.UTF8;
     this._to           = new EmailAddressCollection();
     this._importance   = MailImportance.Normal;
 }
Exemplo n.º 2
0
        public virtual MultiPart Parse(IMessageReader reader, EContentTransferEncoding contentTransferEncoding, string boundary, string uid, string attachmentDirectory, PopMessage parentMessage, ContentType contentType)
        {
            byte[]    buffer;
            MultiPart part = new MultiPart();
            string    str2 = contentType.Attributes["boundary"];

            this._childrenReachedFinalBoundary = false;
            do
            {
                buffer = reader.ReadLine();
            }while (buffer != null && this._defaultEncoding.GetString(buffer, 0, buffer.Length) != ("--" + str2));
            do
            {
                string     source = Utils.ReadHeaders(reader);
                MIMEHeader header = new MIMEHeaderParser().Parse(source);
                if (reader.EndOfMessage)
                {
                    break;
                }
                IPart part2 = this.ParsePart(reader, header.ContentID, header.ContentType, header.ContentDisposition, header.ContentTransferEncoding, uid, attachmentDirectory, str2, parentMessage);
                part2.Header = header;
                part2.Header.ContentTransferEncoding = header.IsDefaultContentTransferEncoding ? contentTransferEncoding : header.ContentTransferEncoding;
                part.Parts.Add(part2);
            }while (!this._childrenReachedFinalBoundary);
            while (!reader.EndOfMessage)
            {
                buffer = reader.ReadLine();
                if (buffer == null)
                {
                    this.RaiseFinalBoundaryReached();
                    return(part);
                }
                EBoundaryType type = BoundaryChecker.CheckBoundary(buffer, boundary);
                if (type != EBoundaryType.NotBoundary)
                {
                    if (type == EBoundaryType.Final)
                    {
                        this.RaiseFinalBoundaryReached();
                    }
                    return(part);
                }
            }
            return(part);
        }
Exemplo n.º 3
0
        public string Parse(byte[] source, EContentTransferEncoding contentTransferEncoding, string charset)
        {
            Encoding encoding;

            switch (contentTransferEncoding)
            {
            case EContentTransferEncoding.Base64:
                return(MailMessageRFCDecoder.GetStringFromBase64(source, charset));

            case EContentTransferEncoding.QuotedPrintable:
                return(MailMessageRFCDecoder.GetStringFromQuotedPrintable(source, charset));
            }
            try
            {
                encoding = Encoding.GetEncoding(charset);
            }
            catch (ArgumentException)
            {
                return(Encoding.UTF8.GetString(source, 0, source.Length));
            }
            return(encoding.GetString(source, 0, source.Length));
        }
Exemplo n.º 4
0
        public virtual IPart ParsePart(IMessageReader reader, string contentId, ContentType contentType, ContentDisposition contentDisposition, EContentTransferEncoding contentTransferEncoding, string uid, string attachmentDirectory, string boundary, PopMessage parentMessage)
        {
            if (PartUtils.IsMultipart(contentType))
            {
                MultiPartParser parser = new MultiPartParser();
                parser.FinalBoundaryReached += new EventHandler(this.childParser_FinalBoundaryReached);
                return(parser.Parse(reader, contentTransferEncoding, boundary, uid, attachmentDirectory, parentMessage, contentType));
            }
            if (PartUtils.IsTextPart(contentType, contentDisposition))
            {
                string         charset = contentType.Attributes.ContainsKey("charset") ? contentType.Attributes["charset"] : "us-ascii";
                TextPartParser parser2 = new TextPartParser(charset);
                parser2.FinalBoundaryReached += new EventHandler(this.childParser_FinalBoundaryReached);
                return(parser2.Parse(reader, contentType, contentDisposition, contentTransferEncoding, boundary));
            }
            if (PartUtils.IsMessagePart(contentType) && (contentType.SubType == "delivery-status"))
            {
                MessageDeliveryStatusPartParser parser3 = new MessageDeliveryStatusPartParser();
                parser3.FinalBoundaryReached += new EventHandler(this.childParser_FinalBoundaryReached);
                return(parser3.Parse(reader, contentType, contentDisposition, contentTransferEncoding, boundary));
            }
            if (PartUtils.IsMessagePart(contentType) && (contentType.SubType == "disposition-notification"))
            {
                MessageDispositionNotificationPartParser parser4 = new MessageDispositionNotificationPartParser();
                parser4.FinalBoundaryReached += new EventHandler(this.childParser_FinalBoundaryReached);
                return(parser4.Parse(reader, contentType, contentDisposition, contentTransferEncoding, boundary));
            }
            if (PartUtils.IsMessagePart(contentType))
            {
                MessagePartParser parser5 = new MessagePartParser();
                parser5.FinalBoundaryReached += new EventHandler(this.childParser_FinalBoundaryReached);
                return(parser5.Parse(reader, contentType, contentDisposition, contentTransferEncoding, boundary, uid, attachmentDirectory));
            }
            attachmentDirectory = Path.Combine(attachmentDirectory, MailClient.MessageFolderPrefix + IOUtil.FormatFileSystemName(uid));
            ContentPartParser parser6 = new ContentPartParser(attachmentDirectory);

            parser6.FinalBoundaryReached += new EventHandler(this.childParser_FinalBoundaryReached);
            ContentPart part2      = (ContentPart)parser6.Parse(reader, contentType, contentDisposition, contentTransferEncoding, boundary);
            IPart       part       = part2;
            Attachment  attachment = new Attachment(part2.DiskFilename, contentId, contentType, attachmentDirectory, part2.Size)
            {
                DiskFilename        = part2.DiskFilename,
                TransferFilename    = part2.TransferFilename,
                AttachmentDirectory = attachmentDirectory,
                ContentID           = contentId,
                ContentType         = contentType
            };

            if (!attachment.TransferFilenameExtension.Equals(".octet-stream", StringComparison.OrdinalIgnoreCase))
            {
                parentMessage.Attachments.Add(attachment);
            }
            return(part);
        }
Exemplo n.º 5
0
        public virtual IPart Parse(IMessageReader reader, ContentType contentType, ContentDisposition contentDisposition, EContentTransferEncoding contentTransferEncoding, string boundary)
        {
            this.ContentWriter.Open();
            if (contentTransferEncoding == EContentTransferEncoding.Base64)
            {
                this.ParseFromBase64(reader, contentType, contentDisposition, boundary);
            }
            else if (contentTransferEncoding == EContentTransferEncoding.QuotedPrintable)
            {
                this.ParseFromQuotedPrintable(reader, contentType, contentDisposition, boundary);
            }
            else
            {
                this.ParseUnencoded(reader, contentType, contentDisposition, boundary);
            }
            IPart part = this.CreatePart(contentType, contentDisposition);

            this.ContentWriter.Close();
            return(part);
        }
Exemplo n.º 6
0
        public IPart Parse(IMessageReader reader, ContentType contentType, ContentDisposition contentDisposition, EContentTransferEncoding contentTransferEncoding, string boundary, string uid, string attachmentDirectory)
        {
            BoundedMessageReader reader2;
            MessagePart          part = new MessagePart();

            if (contentTransferEncoding == EContentTransferEncoding.Base64)
            {
                reader2 = new Base64MessageReader(reader, boundary);
            }
            else if (contentTransferEncoding == EContentTransferEncoding.QuotedPrintable)
            {
                reader2 = new QuotedPrintableMessageReader(reader, boundary);
            }
            else
            {
                reader2 = new UnencodedMessageReader(reader, boundary);
            }
            PopMessage message = new MailMessageParser().Parse(reader2, uid, attachmentDirectory);

            part.Message = message;
            if (reader2.FinalBoundaryReached)
            {
                this.RaiseFinalBoundaryReached();
            }
            return(part);
        }