Esempio n. 1
0
 /// <summary>
 /// Initializes the body
 /// </summary>
 /// <param name="body">The body text</param>
 ///
 ///
 public void SetBodyHtml(string body)
 {
     m_headers["MIME-Version"] = "1.0";
     m_headers["Content-Type"] = "text/html;\r\n charset=" + Config.defaultEncoding.BodyName;
     m_headers["Content-Transfer-Encoding"] = "base64";
     m_body = MimeEncoder.StringBase64(body, Config.defaultEncoding, 78);
 }
Esempio n. 2
0
        /// <summary>
        /// Constructs an attachment from a local file
        /// </summary>
        /// <param name="path">Path of local file to send</param>
        /// <param name="filename_send">The filename of the atachment</param>
        /// <param name="content_type">The Mime Content-Type </param>
        /// <param name="disposition">The Mime disposition</param>
        public MimeAttachment(string path, string filename_send, string content_type, MimeDisposition disposition)
        {
            m_headers["Content-Type"] = content_type + ";\r\n        name=\"" + filename_send + "\"" + endl;
            m_headers["Content-Transfer-Encoding"] = "Base64";
            if (disposition == MimeDisposition.attachment)
            {
                m_headers["Content-Disposition"] = "attachment;\r\n        filename=\"" + filename_send + "\"" + endl;
            }
            else
            {
                m_headers["Content-Disposition"] = "inline;\r\n        filename=\"" + filename_send + "\"" + endl;
            }

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

            System.IO.FileStream file = new System.IO.FileStream(path, System.IO.FileMode.Open,
                                                                 System.IO.FileAccess.Read);
            System.IO.BinaryReader read = new System.IO.BinaryReader(file);

            // Attachment limited to 2Go !
            Byte [] buf = read.ReadBytes((int)file.Length);
            read.Close();

            m_bodyBuilder.Append(MimeEncoder.ByteBase64(buf, 78));
            m_bodyBuilder.Append(endl);
            m_body        = m_bodyBuilder.ToString();
            m_bodyBuilder = null;
        }
Esempio n. 3
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. 4
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;
        }
Esempio n. 5
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;
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Constructs an attachment from a memory buffer
        /// </summary>
        /// <param name="name">The attachment name</param>
        /// <param name="filename_send">The attachment filename if need</param>
        /// <param name="content_type">The content type</param>
        /// <param name="buf">The buffer to send</param>
        /// <param name="disposition">The file disposition</param>
        public MimeAttachment(string name, string filename_send, string content_type, Byte[] buf, MimeDisposition disposition)
        {
            m_headers["Content-Type"] = content_type + ";\r\n        name=\"" + name + "\"" + endl;
            m_headers["Content-Transfer-Encoding"] = "Base64";

            if (disposition == MimeDisposition.attachment)
            {
                m_headers["Content-Disposition"] = "attachment;\r\n        filename=\"" + filename_send + "\"" + endl;
            }
            else
            {
                m_headers["Content-Disposition"] = "inline;\r\n        filename=\"" + filename_send + "\"" + endl;
            }


            m_bodyBuilder = new StringBuilder();
            m_bodyBuilder.Append(endl);
            m_bodyBuilder.Append(MimeEncoder.ByteBase64(buf, 78));
            m_bodyBuilder.Append(endl);
            m_body        = m_bodyBuilder.ToString();
            m_bodyBuilder = null;
        }