[Dnsmail-cvs] dnsmail/DnsMail MailInfo.cs,1.1,1.2
Brought to you by:
ethem
From: Ethem E. <et...@us...> - 2006-08-07 11:00:31
|
Update of /cvsroot/dnsmail/dnsmail/DnsMail In directory sc8-pr-cvs12.sourceforge.net:/tmp/cvs-serv19570/dnsmail/DnsMail Modified Files: MailInfo.cs Log Message: Encoding added. ToString() returns all headers. Index: MailInfo.cs =================================================================== RCS file: /cvsroot/dnsmail/dnsmail/DnsMail/MailInfo.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** MailInfo.cs 2 Mar 2006 17:01:09 -0000 1.1 --- MailInfo.cs 7 Aug 2006 11:00:27 -0000 1.2 *************** *** 3,7 **** --- 3,10 ---- { using System; + using System.Text; using System.Collections; + using HttpContext = System.Web.HttpContext; + using HttpRequest = System.Web.HttpRequest; public class MailInfo *************** *** 9,15 **** --- 12,22 ---- private const string LOCALHOST = "localhost"; internal static readonly string DefaultCharset = System.Text.Encoding.Default.BodyName; + private static readonly Encoding DefaultEncoder = Encoding.GetEncoding(DefaultCharset); + private string mailserver; private string mailserveruser; private string mailserverpass; + internal Encoding encoder = DefaultEncoder; + private MailInfo(bool useMailServer) { *************** *** 17,22 **** } ! public MailInfo() : this(false) {} ! public MailInfo(string from, string to, string subject, string body) : this(false) { From = from; --- 24,30 ---- } ! public MailInfo() : this(false) { } ! public MailInfo(string from, string to, string subject, string body) ! : this(false) { From = from; *************** *** 25,33 **** Body = body; } ! public MailInfo(string mailServer) : this(true) { SetUpMailServer(mailServer); } ! public MailInfo(string mailServer, string msUsername, string msPassword) : this(true) { SetUpMailServer(mailServer); --- 33,43 ---- Body = body; } ! public MailInfo(string mailServer) ! : this(true) { SetUpMailServer(mailServer); } ! public MailInfo(string mailServer, string msUsername, string msPassword) ! : this(true) { SetUpMailServer(mailServer); *************** *** 39,43 **** { if (server == null || server == string.Empty) ! this.mailserver = LOCALHOST; else this.mailserver = server.Trim(); --- 49,53 ---- { if (server == null || server == string.Empty) ! this.mailserver = LOCALHOST; else this.mailserver = server.Trim(); *************** *** 45,49 **** private RecipientCollection recipients; ! public RecipientCollection Recipients { get { return recipients; } --- 55,59 ---- private RecipientCollection recipients; ! public RecipientCollection Recipients { get { return recipients; } *************** *** 52,68 **** private ArrayList headers; ! public ArrayList Headers { ! get { if (headers == null) headers = new ArrayList(2); ! return headers; } } private ContentType ct = Erle.DnsMail.ContentType.Text; ! public ContentType ContentType { get { return ct; } --- 62,78 ---- private ArrayList headers; ! public ArrayList Headers { ! get { if (headers == null) headers = new ArrayList(2); ! return headers; } } private ContentType ct = Erle.DnsMail.ContentType.Text; ! public ContentType ContentType { get { return ct; } *************** *** 71,84 **** private string charset = DefaultCharset; ! public String Charset { ! get { return charset; } ! set ! { ! if (value!=null && value!=string.Empty) { value = value.Trim(); ! if( value!=string.Empty) ! charset = value; } } --- 81,104 ---- private string charset = DefaultCharset; ! public String Charset { ! get { return charset; } ! set ! { ! if (value != null && value != string.Empty) { value = value.Trim(); ! if (value != string.Empty) ! { ! try ! { ! Encoding enc = Encoding.GetEncoding(value); ! charset = value; ! encoder = enc; ! } ! catch ! { ! } ! } } } *************** *** 86,161 **** private string _mailFrom = string.Empty; ! public String From { ! get { return _mailFrom; } set { _mailFrom = value.Trim(); } } private string _mailFromName; ! public String FromName { ! get { return _mailFromName; } set { _mailFromName = value.Trim(); } } private string _mailReplyTo; ! public String ReplyTo { ! get { return _mailReplyTo; } set { _mailReplyTo = value.Trim(); } } private string _mailSubject; ! public String Subject { ! get { return _mailSubject; } set { _mailSubject = value.Trim(); } } private bool _senddata = true; ! public bool SendMail { ! get { return _senddata; } set { _senddata = value; } } internal bool sent; ! public bool Sent { ! get { return sent; } } private string _mailBody = string.Empty; ! public String Body { ! get { return _mailBody; } set { _mailBody = value; } } ! public string MailServer { ! get { return mailserver; } } ! public string MailServerUserName { ! get { return mailserveruser; } } public string MailServerPassword { ! get { return mailserverpass; } } ! internal bool UsernamePasswordOK { ! get { ! return ! ( ! mailserveruser != null && ! mailserverpass != null && ! mailserveruser != String.Empty && ! mailserverpass != String.Empty ! ); } } } --- 106,234 ---- private string _mailFrom = string.Empty; ! public String From { ! get { return _mailFrom; } set { _mailFrom = value.Trim(); } } private string _mailFromName; ! public String FromName { ! get { return _mailFromName; } set { _mailFromName = value.Trim(); } } private string _mailReplyTo; ! public String ReplyTo { ! get { return _mailReplyTo; } set { _mailReplyTo = value.Trim(); } } private string _mailSubject; ! public String Subject { ! get { return _mailSubject; } set { _mailSubject = value.Trim(); } } private bool _senddata = true; ! public bool SendMail { ! get { return _senddata; } set { _senddata = value; } } internal bool sent; ! public bool Sent { ! get { return sent; } } private string _mailBody = string.Empty; ! public String Body { ! get { return _mailBody; } set { _mailBody = value; } } ! public string MailServer { ! get { return mailserver; } } ! public string MailServerUserName { ! get { return mailserveruser; } } public string MailServerPassword { ! get { return mailserverpass; } } ! public override string ToString() { ! return ToString(From, 1); ! } ! ! public string ToString(string to, int rcptcount) ! { ! StringBuilder header = new StringBuilder(); ! String __sd = DateTime.Now.ToUniversalTime().ToString("R", System.Globalization.DateTimeFormatInfo.InvariantInfo); ! // Received, Date, X-Mailer, Standard Headers ! if (HttpContext.Current != null) { ! HttpRequest req = HttpContext.Current.Request; ! Object o = req.Headers["X-Forwarded-For"]; ! String userip = (o == null) ? req.UserHostAddress : o.ToString(); ! header.AppendFormat("Received: from [{0}]{1}\t by {2}{3}\t with HTTP", ! userip, "\r\n", req.Url.Host, "\r\n"); ! if (rcptcount == 1) ! header.AppendFormat("\r\n" + "\t for <{0}>", to); ! ! header.AppendFormat("; {0}" + "\r\n", __sd); } + header.AppendFormat("Date: {0}" + "\r\n", __sd); + header.Append("X-Mailer: Erle.DnsMail.v0.4.0.0" + "\r\n"); + + // Subject: + if ((Subject != null) && (Subject != string.Empty)) + header.Append("Subject: " + + MIME.BEncode(encoder.GetBytes(Subject), Charset) + + "\r\n"); + // From: + if (FromName == null || FromName == string.Empty) + header.AppendFormat("From: <{0}>" + "\r\n", From); + else + header.AppendFormat("From: \"{0}\" <{1}>" + "\r\n", + MIME.BEncode(encoder.GetBytes(FromName), Charset), + From); + // To: + if (rcptcount == 1) + header.AppendFormat("To: <{0}>" + "\r\n", to); + else + header.Append("To: <Undisclosed-Recipient:;>" + "\r\n"); + // Reply-To: + if (ReplyTo != null && ReplyTo != string.Empty) + header.Append("Reply-To: <" + ReplyTo + ">" + "\r\n"); + + // Custom headers: + foreach (String val in Headers) + { + if (val != null && val != String.Empty && + val.IndexOf(": ", 0, val.Length) != -1 && + val.IndexOf('\n', 0, val.Length) == -1 + ) header.Append(val.Trim() + "\r\n"); + } + + // Body + if (Body != null && Body.Length > 0) + { + header.Append("MIME-Version: 1.0" + "\r\n"); + header.AppendFormat("Content-Type: text/{0}; charset={1}" + "\r\n", + ContentType == ContentType.Html ? "html" : "plain", Charset); + header.Append("Content-Transfer-Encoding: quoted-printable" + "\r\n"); + } + header.Append("\r\n"); + return header.ToString(); } } |