Ejemplo 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;
        }
Ejemplo 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;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// The method builds the mime src (the valid RFC2822  address)
        /// </summary>
        protected void Save()
        {
            if (m_name.Length > 0)
            {
                if (QPEncoder.IsAscii(m_name))
                {
                    m_src = m_name + " " + m_mailbox;
                }
                else
                {
                    m_src = MimeWordEncoder.Encode(m_name, Config.defaultEncoding, EncodingIdentifier.Base64) + " " + m_mailbox;
                }
            }
            else
            {
                m_src = m_mailbox;
            }

            m_valid = true;
        }
Ejemplo n.º 4
0
        /// <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;
            }
        }