예제 #1
0
        /// <summary>
        /// Constructs an attachment from a body string
        /// </summary>
        /// <param name="body">The body text</param>
        /// <param name="type">The content-type text</param>
        /// <param name="coding">The text Content-transfer-encoding</param>
        /// <param name="charset">The text charset</param>
        /// <example>
        /// <code>
        /// MimeAttachment m = new MimeAttachment ("hello", MimeTextContentType.TextPlain, MimeCharset.UTF8);
        /// </code>
        /// </example>
        public MimeAttachment(string body, MimeTextContentType type, MimeTransferEncoding coding, System.Text.Encoding charset)
        {
            m_headers["Content-Type"] = MimeConstant.GetContentTypeId(type) + "; charset=\"" +
                                        charset.BodyName + "\" ";

            m_headers["Content-Transfer-Encoding"] = MimeConstant.GetTransferEncodingId(coding);
            m_headers["Content-Disposition"]       = "inline;\r\n";

            m_bodyBuilder = new StringBuilder();
            m_bodyBuilder.Append(endl);

            if (charset == System.Text.Encoding.ASCII)
            {
                m_bodyBuilder.Append(body);
            }
            else
            {
                if (coding == MimeTransferEncoding.QuotedPrintable)
                {
                    m_bodyBuilder.Append(QPEncoder.Encode(body, charset));
                }
                else if (coding == MimeTransferEncoding.Base64)
                {
                    m_bodyBuilder.Append(MimeEncoder.StringBase64(body, charset, 78));
                }
                else
                {
                    m_bodyBuilder.Append(body);
                }
            }
            m_bodyBuilder.Append(endl);
            m_body        = m_bodyBuilder.ToString();
            m_bodyBuilder = null;
        }
예제 #2
0
파일: MimeMessage.cs 프로젝트: ewin66/Jep
        /// <summary>
        /// Initializes the body
        /// </summary>
        /// <param name="body">The body text</param>
        /// <param name="TransferEncoding">The Transfer encoding format</param>
        /// <param name="ContentType">The Mime content type</param>
        ///
        public void SetBody(string body, MimeTransferEncoding TransferEncoding, MimeTextContentType ContentType)
        {
            string type = "";

            switch (ContentType)
            {
            case MimeTextContentType.TextPlain:
                type = "text/plain";
                break;

            case MimeTextContentType.TextHtml:
                type = "text/html";
                break;

            default:
                throw (new MimeException("Unknown ContentType"));
            }
            m_headers["MIME-Version"] = "1.0";

            switch (TransferEncoding)
            {
            case MimeTransferEncoding.Ascii7Bit:
                m_headers["Content-Type"] = type + ";\r\n charset=us-ascii";
                m_headers["Content-Transfer-Encoding"] = "7bit";
                m_body = body;
                break;

            case MimeTransferEncoding.QuotedPrintable:
                m_headers["Content-Type"] = type + ";\r\n charset=" + Config.defaultEncoding.BodyName;
                m_headers["Content-Transfer-Encoding"] = "quoted-printable";
                m_body = QPEncoder.Encode(body, Config.defaultEncoding);
                break;

            case MimeTransferEncoding.Base64:
                m_headers["Content-Type"] = type + ";\r\n charset=" + Config.defaultEncoding.BodyName;
                m_headers["Content-Transfer-Encoding"] = "base64";
                m_body = MimeEncoder.StringBase64(body, Config.defaultEncoding, 78);
                break;
            }
        }