Пример #1
0
            public override bool FilterHeaderList(HeaderList headerList, Stream stream)
            {
                Header header = headerList.FindFirst(HeaderId.ContentTransferEncoding);

                if (header != null)
                {
                    ContentTransferEncoding encodingType = MimePart.GetEncodingType(header.FirstRawToken);
                    if (encodingType == ContentTransferEncoding.EightBit || encodingType == ContentTransferEncoding.Binary)
                    {
                        ContentTypeHeader typeHeader = headerList.FindFirst(HeaderId.ContentType) as ContentTypeHeader;
                        bool flag;
                        bool flag2;
                        EightToSevenBitConverter.Analyse(typeHeader, out this.embedded, out flag, out flag2);
                        for (MimeNode mimeNode = headerList.FirstChild; mimeNode != null; mimeNode = mimeNode.NextSibling)
                        {
                            if (HeaderId.ContentTransferEncoding == (mimeNode as Header).HeaderId)
                            {
                                if (flag || this.embedded)
                                {
                                    this.encoder = null;
                                }
                                else if (flag2)
                                {
                                    stream.Write(EightToSevenBitConverter.CteQP, 0, EightToSevenBitConverter.CteQP.Length);
                                    this.encoder = new QPEncoder();
                                }
                                else
                                {
                                    stream.Write(EightToSevenBitConverter.CteBase64, 0, EightToSevenBitConverter.CteBase64.Length);
                                    this.encoder = new Base64Encoder();
                                }
                            }
                            else
                            {
                                mimeNode.WriteTo(stream);
                            }
                        }
                        stream.Write(MimeString.CrLf, 0, MimeString.CrLf.Length);
                        return(true);
                    }
                }
                return(false);
            }
Пример #2
0
        public static void Convert(Stream source, Stream destination)
        {
            int i = 0;

            byte[][] array  = null;
            byte[]   array2 = null;
            using (Stream stream = new SuppressCloseStream(source))
            {
                using (MimeReader mimeReader = new MimeReader(stream, true, DecodingOptions.Default, MimeLimits.Unlimited, true, false))
                {
                    while (mimeReader.ReadNextPart())
                    {
                        while (i >= mimeReader.Depth)
                        {
                            byte[] array3 = array[--i];
                            if (array3 != null)
                            {
                                destination.Write(array3, 0, array3.Length - 2);
                                destination.Write(MimeString.TwoDashesCRLF, 0, MimeString.TwoDashesCRLF.Length);
                            }
                        }
                        if (i > 0)
                        {
                            byte[] array3 = array[i - 1];
                            if (array3 != null)
                            {
                                destination.Write(array3, 0, array3.Length);
                            }
                        }
                        HeaderList        headerList        = HeaderList.ReadFrom(mimeReader);
                        ContentTypeHeader contentTypeHeader = headerList.FindFirst(HeaderId.ContentType) as ContentTypeHeader;
                        bool flag;
                        bool flag2;
                        bool flag3;
                        EightToSevenBitConverter.Analyse(contentTypeHeader, out flag, out flag2, out flag3);
                        Header header = headerList.FindFirst(HeaderId.ContentTransferEncoding);
                        if (flag2 || flag)
                        {
                            if (header != null)
                            {
                                headerList.RemoveChild(header);
                            }
                            headerList.WriteTo(destination);
                            byte[] array3;
                            if (flag)
                            {
                                array3 = null;
                                destination.Write(MimeString.CrLf, 0, MimeString.CrLf.Length);
                            }
                            else
                            {
                                array3 = MimePart.GetBoundary(contentTypeHeader);
                            }
                            if (array == null)
                            {
                                array = new byte[4][];
                            }
                            else if (array.Length == i)
                            {
                                byte[][] array4 = new byte[array.Length * 2][];
                                Array.Copy(array, 0, array4, 0, i);
                                array = array4;
                            }
                            array[i++] = array3;
                        }
                        else
                        {
                            Stream stream2 = null;
                            try
                            {
                                stream2 = mimeReader.GetRawContentReadStream();
                                if (header != null && stream2 != null)
                                {
                                    ContentTransferEncoding encodingType = MimePart.GetEncodingType(header.FirstRawToken);
                                    if (encodingType == ContentTransferEncoding.EightBit || encodingType == ContentTransferEncoding.Binary)
                                    {
                                        if (flag3)
                                        {
                                            header.RawValue = MimeString.QuotedPrintable;
                                            stream2         = new EncoderStream(stream2, new QPEncoder(), EncoderStreamAccess.Read);
                                        }
                                        else
                                        {
                                            header.RawValue = MimeString.Base64;
                                            stream2         = new EncoderStream(stream2, new Base64Encoder(), EncoderStreamAccess.Read);
                                        }
                                    }
                                }
                                headerList.WriteTo(destination);
                                destination.Write(MimeString.CrLf, 0, MimeString.CrLf.Length);
                                if (stream2 != null)
                                {
                                    DataStorage.CopyStreamToStream(stream2, destination, long.MaxValue, ref array2);
                                }
                            }
                            finally
                            {
                                if (stream2 != null)
                                {
                                    stream2.Dispose();
                                }
                            }
                        }
                    }
                    while (i > 0)
                    {
                        byte[] array3 = array[--i];
                        if (array3 != null)
                        {
                            destination.Write(array3, 0, array3.Length - 2);
                            destination.Write(MimeString.TwoDashesCRLF, 0, MimeString.TwoDashesCRLF.Length);
                        }
                    }
                }
            }
        }