public async Task<List<Body>> GetBodies(IByteStreamReader streamReader, ContentTypeFieldValue contentType, string transportEncoding)
        {
            var reader = new BufferedByteReader(streamReader);
           
            switch (contentType.Type)
            {
                case "multipart":
                    var bodyPartReader = new BodyReader(ContentType, Header.ContentTransferEncoding);

                    var bodies = await bodyPartReader.ReadBody(reader);
                    break;
                case "text":
                    var textString = "";
                    using (var memstream = await streamReader.GetMemoryStreamAsync())
                    {
                        using (var unEncoded = await MailMethods.UnEncode(memstream, Header.ContentTransferEncoding))
                        {
                            using (var textReader = new StreamReader(unEncoded, Encoding.GetEncoding(Header.ContentType.Charset)))
                            {
                                textString = await textReader.ReadToEndAsync();
                            }
                        }
                    }
                    var textBody = new Body();
                    textBody.Content = (new MemoryStream(Encoding.Unicode.GetBytes(textString)));
                    break;
                case "image":
                case "audio":
                case "video":
                case "application":
                    var binaryBody = new Body();
                    binaryBody.Content = await streamReader.GetMemoryStreamAsync());
                    break;
            }
        }
Exemple #2
0
        public async Task ReadHeader(BufferedByteReader reader)
        {
            var fieldName = new HeaderFieldName();

            var endType = FieldValue.EndType.None;
            var ignore  = new HeaderIgnoreFieldValue();

            while (endType != FieldValue.EndType.EndOfHeader)
            {
                var name = await fieldName.ReadFieldName(reader);

                switch (name)
                {
                case "From":
                    From    = new AddressListFieldValue();
                    endType = await From.ReadFieldValue(reader);

                    break;

                case "Sender":
                    var sender = new AddressListFieldValue();
                    endType = await sender.ReadFieldValue(reader);

                    Sender = sender.Adresses[0];
                    break;

                case "Reply-To":
                    ReplyTo = new AddressListFieldValue();
                    endType = await ReplyTo.ReadFieldValue(reader);

                    break;

                case "To":
                    To      = new AddressListFieldValue();
                    endType = await To.ReadFieldValue(reader);

                    break;

                case "CC":
                    Cc      = new AddressListFieldValue();
                    endType = await Cc.ReadFieldValue(reader);

                    break;

                case "Date":
                    var dateField = new DateFieldValue();
                    endType = await dateField.ReadFieldValue(reader);

                    OrigDate = dateField.Value;
                    break;

                case "Message-ID":
                    var ids = new IdentificationFieldValue();
                    endType = await ids.ReadFieldValue(reader);

                    MessageId = ids.Identifiers[0];
                    break;

                case "In-Reply-To":
                    InReplyTo = new IdentificationFieldValue();
                    endType   = await InReplyTo.ReadFieldValue(reader);

                    break;

                case "References":
                    References = new IdentificationFieldValue();
                    endType    = await References.ReadFieldValue(reader);

                    break;

                case "Subject":
                    var subject = new UnstructuredTextFieldValue();
                    endType = await subject.ReadFieldValue(reader);

                    Subject = subject.Value;
                    break;

                case "Comments":
                    var comments = new UnstructuredTextFieldValue();
                    endType = await comments.ReadFieldValue(reader);

                    Subject = comments.Value;
                    break;

                case "Content-type":
                    ContentType = new ContentTypeFieldValue();
                    endType     = await ContentType.ReadFieldValue(reader);

                    break;

                case "Content-transfer-encoding":
                    var contentTransferEncoding = new MimeFieldFieldValue();
                    ContentTransferEncoding = await contentTransferEncoding.ReadFieldValue(reader);

                    endType = contentTransferEncoding.TypOfEnd;
                    break;

                case "Content-ID":
                    var newid = new IdentificationFieldValue();
                    endType = await newid.ReadFieldValue(reader).ConfigureAwait(false);

                    ContentId = newid.Identifiers[0];
                    break;

                case "Content-description":
                    var description = new UnstructuredTextFieldValue();
                    endType = await description.ReadFieldValue(reader);

                    ContentDescription = description.Value;
                    break;

                default:
                    endType = await ignore.ReadFieldValue(reader);

                    break;
                }
            }
        }
        private readonly  byte[] _boundaryStart = new byte[4] { 13, 10, 45, 45 }; // "\r\n--"

        internal BodyReader(ContentTypeFieldValue contentType, string encoding, List<byte[]> boundaries)
        {
            Boundaries = boundaries;
        }
Exemple #4
0
        public async Task ReadHeader( BufferedByteReader reader)
        {
            var fieldName = new HeaderFieldName();

            var endType = FieldValue.EndType.None;
            var ignore = new HeaderIgnoreFieldValue();
            while (endType != FieldValue.EndType.EndOfHeader)
            {
                var name = await fieldName.ReadFieldName(reader);
                switch (name)
                {
                    case "From":
                        From = new AddressListFieldValue();
                        endType = await From.ReadFieldValue(reader);
                        break;
                    case "Sender":
                        var sender = new AddressListFieldValue();
                        endType = await sender.ReadFieldValue(reader);
                        Sender = sender.Adresses[0];
                        break;
                    case "Reply-To":
                        ReplyTo = new AddressListFieldValue();
                        endType = await ReplyTo.ReadFieldValue(reader);
                        break;
                    case "To":
                        To = new AddressListFieldValue();
                        endType = await To.ReadFieldValue(reader);
                        break;
                    case "CC":
                        Cc = new AddressListFieldValue();
                        endType = await Cc.ReadFieldValue(reader);
                        break;
                    case "Date":
                        var dateField = new DateFieldValue();
                        endType = await dateField.ReadFieldValue(reader);
                        OrigDate = dateField.Value;
                        break;
                    case "Message-ID":
                        var ids = new IdentificationFieldValue();
                        endType = await ids.ReadFieldValue(reader);
                        MessageId = ids.Identifiers[0];
                        break;
                    case "In-Reply-To":
                        InReplyTo = new IdentificationFieldValue();
                        endType = await InReplyTo.ReadFieldValue(reader);
                        break;
                    case "References":
                        References = new IdentificationFieldValue();
                        endType = await References.ReadFieldValue(reader);
                        break;
                    case "Subject":
                        var subject = new UnstructuredTextFieldValue();
                        endType = await subject.ReadFieldValue(reader);
                        Subject = subject.Value;
                        break;
                    case "Comments":
                        var comments = new UnstructuredTextFieldValue();
                        endType = await comments.ReadFieldValue(reader);
                        Subject = comments.Value;
                        break;
                    case "Content-type":
                        ContentType = new ContentTypeFieldValue();
                        endType = await ContentType.ReadFieldValue(reader);
                        break;
                    case "Content-transfer-encoding":
                        var contentTransferEncoding = new MimeFieldFieldValue();
                        ContentTransferEncoding = await contentTransferEncoding.ReadFieldValue(reader);
                        endType = contentTransferEncoding.TypOfEnd;
                        break;
                    case "Content-ID":
                        var newid = new IdentificationFieldValue();
                        endType = await newid.ReadFieldValue(reader).ConfigureAwait(false);
                        ContentId = newid.Identifiers[0];
                        break;
                    case "Content-description":
                        var description = new UnstructuredTextFieldValue();
                        endType = await description.ReadFieldValue(reader);
                        ContentDescription = description.Value;
                        break;
                    default:
                        endType = await ignore.ReadFieldValue(reader);
                        break;
                }
            }
        }