コード例 #1
0
        // Extracts the content out of ITextBody.
        private static string ParseTextBody(Entity mimeBody)
        {
            if (!(mimeBody.Body is ITextBody))
            {
                return(string.Empty);
            }

            ITextBody    textBody  = (ITextBody)mimeBody.Body;
            MemoryStream memStream = new MemoryStream();

            textBody.WriteTo(memStream);
            memStream.Seek(0, SeekOrigin.Begin);
            string encoding = mimeBody.ContentTransferEncoding.ToLower();

            byte[] buffer = new byte[memStream.Length];
            int    bytesRead;

            if (encoding == "quoted-printable")
            {
                QuotedPrintableInputStream qpStream = new QuotedPrintableInputStream(memStream);
                bytesRead = qpStream.Read(buffer, 0, buffer.Length);
            }
            else if (encoding == "base64" || encoding == "base-64")
            {
                Base64InputStream b64Stream = new Base64InputStream(memStream);
                bytesRead = b64Stream.Read(buffer, 0, buffer.Length);
            }
            else
            {
                bytesRead = memStream.Read(buffer, 0, buffer.Length);
            }

            return(mimeBody.CurrentEncoding.GetString(buffer, 0, bytesRead));
        }
コード例 #2
0
        // Extracts the content out of ITextBody.
        private static string ParseTextBody(Entity mimeBody)
        {
            if (!(mimeBody.Body is ITextBody))
            {
                return string.Empty;
            }

            ITextBody textBody = (ITextBody)mimeBody.Body;
            MemoryStream memStream = new MemoryStream();
            textBody.WriteTo(memStream);
            memStream.Seek(0, SeekOrigin.Begin);
            string encoding = mimeBody.ContentTransferEncoding.ToLower();
            byte[] buffer = new byte[memStream.Length];
            int bytesRead;
            if (encoding == "quoted-printable")
            {
                QuotedPrintableInputStream qpStream = new QuotedPrintableInputStream(memStream);
                bytesRead = qpStream.Read(buffer, 0, buffer.Length);
            }
            else if (encoding == "base64" || encoding == "base-64")
            {
                Base64InputStream b64Stream = new Base64InputStream(memStream);
                bytesRead = b64Stream.Read(buffer, 0, buffer.Length);
            }
            else
            {
                bytesRead = memStream.Read(buffer, 0, buffer.Length);
            }

            if (bytesRead > 0)
            {
                return mimeBody.CurrentEncoding.GetString(buffer, 0, bytesRead);
            }
            else
            {
                return string.Empty;
            }
        }