Esempio n. 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;
        }
Esempio n. 2
0
        /// <summary>
        /// Constructs an attahcment from string
        /// </summary>
        /// <param name="body">A string containing the attachment body text</param>
        /// <param name="type">The Content-Type of the attachement</param>
        /// <remarks>
        /// This method initializes a body text with utf8 charset, base64 transfer encoding and inline disposition.
        /// </remarks>
        public MimeAttachment(string body, MimeTextContentType type)
        {
            System.Text.Encoding encoding;

            if (QPEncoder.IsAscii(body))
            {
                encoding = System.Text.Encoding.ASCII;
            }
            else
            {
                encoding = Config.defaultEncoding;
            }

            m_headers["Content-Type"] = MimeConstant.GetContentTypeId(type) + "; charset=\"" +
                                        encoding.BodyName + "\" ";

            if (encoding == System.Text.Encoding.ASCII)
            {
                m_headers["Content-Transfer-Encoding"] = MimeConstant.GetTransferEncodingId(MimeTransferEncoding.Ascii7Bit);
            }
            else
            {
                m_headers["Content-Transfer-Encoding"] = MimeConstant.GetTransferEncodingId(MimeTransferEncoding.Base64);
            }

            m_headers["Content-Disposition"] = "inline;\r\n";

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

            if (encoding == System.Text.Encoding.ASCII)
            {
                m_bodyBuilder.Append(body);
            }
            else
            {
                m_bodyBuilder.Append(MimeEncoder.StringBase64(body, Config.defaultEncoding, 78));
            }

            m_bodyBuilder.Append(endl);
            m_body        = m_bodyBuilder.ToString();
            m_bodyBuilder = null;
        }