Ejemplo n.º 1
0
        public void DecodeData(Stream stream, Boolean isClose)
        {
            Byte[] bb = null;

            if (this.ContentTransferEncoding == TransferEncoding.Base64)
            {
                bb = Convert.FromBase64String(this.BodyData.Replace("\n", ""));
                BinaryWriter sw = null;
                try
                {
                    sw = new BinaryWriter(stream);
                    sw.Write(bb);
                    sw.Flush();
                }
                finally
                {
                    if (isClose == true)
                    {
                        sw.Close();
                    }
                }
            }
            else if (this.ContentTransferEncoding == TransferEncoding.QuotedPrintable)
            {
                StreamWriter sw = null;
                try
                {
                    sw = new StreamWriter(stream);
                    sw.Write(this.ContentEncoding.GetString(MailParser.FromQuotedPrintableText(this.BodyData)));
                    sw.Flush();
                }
                finally
                {
                    if (isClose == true)
                    {
                        sw.Close();
                    }
                }
            }
            else if (this.ContentTransferEncoding == TransferEncoding.SevenBit)
            {
                bb = Encoding.ASCII.GetBytes(this.BodyData);
                BinaryWriter sw = null;
                try
                {
                    sw = new BinaryWriter(stream);
                    sw.Write(bb);
                    sw.Flush();
                }
                finally
                {
                    if (isClose == true)
                    {
                        sw.Close();
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public void DecodeData(String filePath)
        {
            Byte[] bb = null;

            if (String.IsNullOrEmpty(this.ContentDisposition.Value) == true)
            {
                return;
            }

            if (this.ContentTransferEncoding == TransferEncoding.Base64)
            {
                bb = Convert.FromBase64String(this.BodyData.Replace("\n", "").Replace("\r", ""));
                using (BinaryWriter sw = new BinaryWriter(new FileStream(filePath, FileMode.Create)))
                {
                    sw.Write(bb);
                    sw.Flush();
                    sw.Close();
                }
            }
            else if (this.ContentTransferEncoding == TransferEncoding.QuotedPrintable)
            {
                using (StreamWriter sw = File.CreateText(filePath))
                {
                    sw.Write(this.ContentEncoding.GetString(MailParser.FromQuotedPrintableText(this.BodyData)));
                    sw.Flush();
                    sw.Close();
                }
            }
            else if (this.ContentTransferEncoding == TransferEncoding.SevenBit)
            {
                bb = Encoding.ASCII.GetBytes(this.BodyData);
                using (BinaryWriter sw = new BinaryWriter(new FileStream(filePath, FileMode.Create)))
                {
                    sw.Write(bb);
                    sw.Flush();
                    sw.Close();
                }
            }
        }
Ejemplo n.º 3
0
        /// バイナリデータをデコードして指定したストリームに出力します。
        /// <summary>
        /// Decode binary data and output to specify stream.
        /// バイナリデータをデコードして指定したストリームに出力します。
        /// </summary>
        /// <param name="stream">書込み先のストリームオブジェクトです。</param>
        /// <param name="isClose">ストリームに書き込んだあとにストリームを閉じるかどうかを示す値を設定します。</param>
        public void DecodeData(Stream stream, Boolean isClose)
        {
            Byte[]       bb = null;
            BinaryWriter sw = null;

            if (String.IsNullOrEmpty(this.ContentDisposition.Value) == true)
            {
                return;
            }

            if (this.ContentTransferEncoding == TransferEncoding.Base64)
            {
                bb = Convert.FromBase64String(this.BodyData.Replace("\n", "").Replace("\r", ""));
            }
            else if (this.ContentTransferEncoding == TransferEncoding.QuotedPrintable)
            {
                bb = MailParser.FromQuotedPrintableText(this.BodyData);
            }
            else if (this.ContentTransferEncoding == TransferEncoding.SevenBit)
            {
                bb = Encoding.ASCII.GetBytes(this.BodyData);
            }
            try
            {
                sw = new BinaryWriter(stream);
                sw.Write(bb);
                sw.Flush();
            }
            finally
            {
                if (isClose == true)
                {
                    sw.Close();
                }
            }
        }