/// <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; }
/// <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; }