// -------------------------- ToSendString --------------------------------
        public string ToSendString( )
        {
            StringBuilder sb = new StringBuilder(512);

            if (FriendlyName != null)
            {
                sb.Append(
                    Stringer.Enquote(FriendlyName, '"', QuoteEncapsulation.Escape) +
                    " ");
            }
            sb.Append('<');
            sb.Append(Address);
            sb.Append('>');
            return(sb.ToString( ));
        }
        /// <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());
        }
Beispiel #3
0
        public static void ReadXml(
            out List <string> OutList, XmlReader InReader, string InListName, string InEntryName)
        {
            List <string> l1 = new List <string>();
            int           ix;

            string[] nameStack = new string[10];

            // the current node must be the ListName node.
            if ((InReader.NodeType == XmlNodeType.Element) && (InReader.Name == InListName))
            {
            }
            else
            {
                throw new ApplicationException(
                          "ReadXml method expects current node to be " +
                          "named " + Stringer.Enquote(InListName, '\''));
            }

            int  startDepth = InReader.Depth;
            bool fExit      = false;

            while (true)
            {
                switch (InReader.NodeType)
                {
                case XmlNodeType.Element:

                    // save the element name in stack of element names.
                    ix            = InReader.Depth - startDepth;
                    nameStack[ix] = InReader.Name;
                    break;

                case XmlNodeType.Text:

                    ix = InReader.Depth - startDepth;
                    if ((ix > 1) && (nameStack[ix - 2] == InListName))
                    {
                        string elemName = nameStack[ix - 1];
                        if (elemName == InEntryName)
                        {
                            string s1 = InReader.Value;
                            l1.Add(s1);
                        }
                    }
                    break;

                case XmlNodeType.EndElement:
                    if (InReader.Name == InListName)
                    {
                        fExit = true;
                    }
                    break;
                }
                if (fExit == true)
                {
                    break;
                }

                // read the next node in the xml document.
                bool rc = InReader.Read();

                // error if eof. should find the Field end element first.
                if (rc == false)
                {
                    throw new ApplicationException(
                              "ReadXml method did not find " + Stringer.Enquote(InListName, '\'') + " end element");
                }
            }
            OutList = l1;
        }
Beispiel #4
0
        /// <summary>
        /// Read the Point property element from the XmlReader stream.
        /// </summary>
        /// <param name="OutSize"></param>
        /// <param name="reader"></param>
        /// <param name="InPropertyName"></param>
        public static void ReadXml(out Point OutPoint, XmlReader reader, string InPropertyName)
        {
            int ix;

            string[] nameStack = new string[10];
            int      pointX    = 0;
            int      pointY    = 0;

            // the current node must be the FormatField.ClassName node.
            if ((reader.NodeType == XmlNodeType.Element) && (reader.Name == InPropertyName))
            {
            }
            else
            {
                throw new ApplicationException(
                          "ReadXml method expects current node to be " +
                          "named " + Stringer.Enquote(InPropertyName, '\''));
            }

            int  startDepth = reader.Depth;
            bool fExit      = false;

            while (true)
            {
                switch (reader.NodeType)
                {
                case XmlNodeType.Element:

                    // save the element name in stack of element names.
                    ix            = reader.Depth - startDepth;
                    nameStack[ix] = reader.Name;
                    break;

                case XmlNodeType.Text:

                    ix = reader.Depth - startDepth;
                    if ((ix > 1) && (nameStack[ix - 2] == InPropertyName))
                    {
                        string elemName = nameStack[ix - 1];
                        if (elemName == "X")
                        {
                            pointX = Int32.Parse(reader.Value);
                        }
                        else if (elemName == "Y")
                        {
                            pointY = Int32.Parse(reader.Value);
                        }
                    }
                    break;

                case XmlNodeType.EndElement:
                    if (reader.Name == InPropertyName)
                    {
                        fExit = true;
                    }
                    break;
                }
                if (fExit == true)
                {
                    break;
                }

                // read the next node in the xml document.
                bool rc = reader.Read();

                // error if eof. should find the Field end element first.
                if (rc == false)
                {
                    throw new ApplicationException(
                              "ReadXml method did not find " + Stringer.Enquote(InPropertyName, '\'') + " end element");
                }
            }
            OutPoint = new Point(pointX, pointY);
        }
Beispiel #5
0
        /// <summary>
        /// Enquote a string with single quotes.
        /// </summary>
        /// <param name="Value"></param>
        /// <returns></returns>
        public static string SingleEnquote(this string Value)
        {
            string s1 = Stringer.Enquote(Value, '\'');

            return(s1);
        }
Beispiel #6
0
        public static string DoubleEnquote(this string Value, QuoteEncapsulation QuoteEncapsulation)
        {
            string s1 = Stringer.Enquote(Value, '\"', QuoteEncapsulation);

            return(s1);
        }