Esempio n. 1
0
        // ----------------------- ToMimeString ---------------------------
        public string ToMimeString(string InCharSet)
        {
            string friendlyResults = null;
            string addressResults  = null;
            string results         = null;

            // message line encode the friendly name.
            if (Stringer.IsNotEmpty(FriendlyName))
            {
                MimeHeaderLineBuilder friendly = new MimeHeaderLineBuilder( );
                friendly.Traits
                .SetEncoderCharSet(InCharSet)
                .SetOtherEncodeChars("<>\"\'");
                friendly.Append(FriendlyName);
                friendlyResults = friendly.ToEncodedString( );
            }

            // message line encode the email address
            MimeHeaderLineBuilder lb = new MimeHeaderLineBuilder( );

            lb.Traits
            .SetEncoderCharSet(InCharSet);
            lb.Append(" <" + Address + ">");
            addressResults = lb.ToEncodedString( );

            results =
                MimeCommon.ConcatMessageLine(lb.Traits, friendlyResults, addressResults);
            return(results);
        }
Esempio n. 2
0
        // --------------------------- ToMessageHeaderString -------------------------
        // The email address and friendly name in the form specified for an internet
        // message header.
        // Use the CharSet to Quoted-Printable encode the friendly name if need be.
        public string ToMessageHeaderString(string InCharSet)
        {
            StringBuilder sb = new StringBuilder(512);

            if (Stringer.IsNotEmpty(FriendlyName))
            {
                string mhs = null;
                QuotedPrintableTraits traits =
                    new QuotedPrintableTraits( )
                    .SetCharSet(InCharSet)
                    .SetOtherEncodeChars("\"");
                mhs = MessageHeaderString.EncodeAsRequired(FriendlyName, traits);
                sb.Append(mhs);
                sb.Append(" <" + Address + ">");
            }
            else
            {
                sb.Append("<" + Address + ">");
            }
            return(sb.ToString( ));
        }
Esempio n. 3
0
        /// <summary>Returns the MailMessage as a RFC 822 formatted message</summary>
        public override string ToString()
        {
            StringBuilder sb = new StringBuilder(60000);

            sb.Append("Reply-To: " + ReplyTo.ToMessageHeaderString(charset));
            sb.Append(SmtpConstants.CrLf);
            sb.Append("From: " + From.ToMessageHeaderString(charset));
            sb.Append(SmtpConstants.CrLf);

            if (1 == 2)
            {
                if (Stringer.IsNotEmpty(ReplyTo.FriendlyName))
                {
                    string rt = MessageHeaderString.EncodeAsRequired(
                        Stringer.Enquote(ReplyTo.FriendlyName, '"', QuoteEncapsulation.Escape),
                        new QuotedPrintableTraits( ));
                    sb.Append("Reply-To: ");
                    sb.Append(rt);
                    sb.Append(" <" + ReplyTo.Address + ">" + SmtpConstants.CrLf);
                    string debug = sb.ToString( );
                }
                else
                {
                    sb.Append("Reply-To: <" + ReplyTo.Address + ">" + SmtpConstants.CrLf);
                }

                // from email address.
                if (Stringer.IsNotEmpty(From.FriendlyName))
                {
                    string rt = MessageHeaderString.EncodeAsRequired(
                        Stringer.Enquote(From.FriendlyName, '"', QuoteEncapsulation.Escape),
                        new QuotedPrintableTraits( ));
                    sb.Append("From: ");
                    sb.Append(rt);
                    sb.Append(" <" + From.Address + ">" + SmtpConstants.CrLf);
                }
                else
                {
                    sb.Append("From: <" + From.Address + ">" + SmtpConstants.CrLf);
                }
            }

            sb.Append("To: " + CreateAddressList(mToRecipients) + "\r\n");

            if (CCRecipients.Count != 0)
            {
                sb.Append("CC: " + CreateAddressList(CCRecipients) + "\r\n");
            }

            if (subject != null && subject.Length > 0)
            {
                StringBuilder cleanSubject = new StringBuilder(subject);
                cleanSubject.Replace("\r\n", null);
                cleanSubject.Replace("\n", null);

                sb.Append("Subject: " + MailEncoder.ConvertHeaderToQP(cleanSubject.ToString(), charset) + "\r\n");
            }

            sb.Append("Date: " + DateTime.Now.ToUniversalTime().ToString("R") + "\r\n");
            sb.Append(SmtpConfig.X_MAILER_HEADER + "\r\n");

            if (notification)
            {
                if (ReplyTo.FriendlyName != null && ReplyTo.FriendlyName.Length != 0)
                {
                    sb.Append("Disposition-Notification-To: " + MailEncoder.ConvertHeaderToQP(ReplyTo.FriendlyName, charset) + " <" + ReplyTo.Address + ">\r\n");
                }
                else
                {
                    sb.Append("Disposition-Notification-To: <" + ReplyTo.Address + ">\r\n");
                }
            }

            if (priority != null)
            {
                sb.Append("X-Priority: " + priority + "\r\n");
            }

            if (customHeaders != null)
            {
                for (IEnumerator i = customHeaders.GetEnumerator(); i.MoveNext();)
                {
                    MailHeader m = (MailHeader)i.Current;

                    if (m.name.Length >= 0 && m.body.Length >= 0)
                    {
                        sb.Append(m.name + ":" + MailEncoder.ConvertHeaderToQP(m.body, charset) + "\r\n");
                    }
                    else
                    {
                        // TODO: Check if below is within RFC spec.
                        sb.Append(m.name + ":\r\n");
                    }
                }
            }

            sb.Append("MIME-Version: 1.0\r\n");
            sb.Append(GetMessageBody());

            return(sb.ToString());
        }
Esempio n. 4
0
        /// <summary>Returns the MailMessage as a RFC 822 formatted message</summary>
        public override string ToString()
        {
            StringBuilder         sb = new StringBuilder(60000);
            MimeHeaderLineBuilder lb = new MimeHeaderLineBuilder( );

            lb.Traits.SetEncoderCharSet(charset);

            // reply to email address
            sb.Append(
                MimeCommon.ConcatMessageLine(
                    lb.Traits,
                    "Reply-To:",
                    ReplyTo.ToMimeString(lb.Traits.EncoderCharSet),
                    MimeConstants.CrLf));

            // BgnTemp debug.  an already encoded from email address.
            if (mEncodedFromAddress != null)
            {
                sb.Append(mEncodedFromAddress + MimeConstants.CrLf);
            }
            else
            {
                // EndTemp debug.

                // send from email address
                sb.Append(
                    MimeCommon.ConcatMessageLine(
                        lb.Traits,
                        "From:",
                        From.ToMimeString(lb.Traits.EncoderCharSet),
                        MimeConstants.CrLf));
            }

            // send to email address
            sb.Append(
                MimeCommon.ConcatMessageLine(
                    lb.Traits,
                    "To:",
                    ToRecipients.ToMessageHeaderString(lb.Traits.EncoderCharSet),
                    MimeConstants.CrLf));

//			sb.Append( "Reply-To: " ) ;
//			sb.Append( ReplyTo.ToMimeString( charset )) ;
//			sb.Append( SmtpConstants.CrLf ) ;

//			sb.Append( "From: " + From.ToMimeStringToMessageHeaderString( charset )) ;
//			sb.Append( SmtpConstants.CrLf ) ;
//			sb.Append( "To: " + ToRecipients.ToMessageHeaderString( charset )) ;
//			sb.Append( SmtpConstants.CrLf ) ;

            if (CCRecipients.Count > 0)
            {
                sb.Append("CC: " + CCRecipients.ToMessageHeaderString(charset));
                sb.Append(SmtpConstants.CrLf);
            }

            if (BCCRecipients.Count > 0)
            {
                sb.Append("BCC: " + BCCRecipients.ToMessageHeaderString(charset));
                sb.Append(SmtpConstants.CrLf);
            }

            // message subject line.
            if (Stringer.IsNotEmpty(Subject))
            {
                lb.Clear( );
                lb.Append("Subject: ");
                lb.Append(Subject);
                sb.Append(lb.ToEncodedString( ) + MimeConstants.CrLf);
            }

            // BgnTemp debug.  an already encoded subject line.
            if (mEncodedSubject != null)
            {
                sb.Append(mEncodedSubject + MimeConstants.CrLf);
            }
            // EndTemp debug.

            // send timestamp
            lb
            .Clear( )
            .Append("Date: " + DateTime.Now.ToUniversalTime().ToString("R"));
            sb.Append(lb.ToEncodedString( ) + MimeConstants.CrLf);

            sb.Append(SmtpConfig.X_MAILER_HEADER + "\r\n");

            if (notification)
            {
                if (ReplyTo.FriendlyName != null && ReplyTo.FriendlyName.Length != 0)
                {
                    sb.Append("Disposition-Notification-To: " + MailEncoder.ConvertHeaderToQP(ReplyTo.FriendlyName, charset) + " <" + ReplyTo.Address + ">\r\n");
                }
                else
                {
                    sb.Append("Disposition-Notification-To: <" + ReplyTo.Address + ">\r\n");
                }
            }

            if (priority != null)
            {
                sb.Append("X-Priority: " + priority + "\r\n");
            }

            if (customHeaders != null)
            {
                for (IEnumerator i = customHeaders.GetEnumerator(); i.MoveNext();)
                {
                    MailHeader m = (MailHeader)i.Current;

                    if (m.name.Length >= 0 && m.body.Length >= 0)
                    {
                        sb.Append(m.name + ":" + MailEncoder.ConvertHeaderToQP(m.body, charset) + "\r\n");
                    }
                    else
                    {
                        // TODO: Check if below is within RFC spec.
                        sb.Append(m.name + ":\r\n");
                    }
                }
            }

            sb.Append("MIME-Version: 1.0\r\n");
            sb.Append(GetMessageBody());

            return(sb.ToString());
        }