Пример #1
0
 /// <summary>
 /// Delivery Status information, as defined in RFC 3464:
 ///
 /// https://tools.ietf.org/html/rfc3464
 /// </summary>
 /// <param name="Text">Text representation of the status message.</param>
 /// <param name="PerMessage">Information about message</param>
 /// <param name="PerRecipients">Information about recipients</param>
 public DeliveryStatus(string Text, PerMessageFields PerMessage,
                       PerRecipientFields[] PerRecipients)
 {
     this.text          = Text;
     this.perMessage    = PerMessage;
     this.perRecipients = PerRecipients;
 }
Пример #2
0
        /// <summary>
        /// Decodes an object.
        /// </summary>
        /// <param name="ContentType">Internet Content Type.</param>
        /// <param name="Data">Encoded object.</param>
        /// <param name="Encoding">Any encoding specified. Can be null if no encoding specified.</param>
        /// <param name="Fields">Any content-type related fields and their corresponding values.</param>
        ///	<param name="BaseUri">Base URI, if any. If not available, value is null.</param>
        /// <returns>Decoded object.</returns>
        /// <exception cref="ArgumentException">If the object cannot be decoded.</exception>
        public object Decode(string ContentType, byte[] Data, Encoding Encoding, KeyValuePair <string, string>[] Fields, Uri BaseUri)
        {
            string          Dsn      = (Encoding ?? Encoding.ASCII).GetString(Data);
            List <string[]> Sections = new List <string[]>();
            List <string>   Section  = new List <string>();

            foreach (string Row in Dsn.Replace("\r\n", "\n").Replace("\r", "\n").Split('\n'))
            {
                if (string.IsNullOrEmpty(Row))
                {
                    if (Section.Count > 0)
                    {
                        Sections.Add(Section.ToArray());
                        Section.Clear();
                    }
                }
                else
                {
                    if (Row[0] <= ' ' && Section.Count > 0)
                    {
                        Section[Section.Count - 1] += Row;
                    }
                    else
                    {
                        Section.Add(Row);
                    }
                }
            }

            if (Section.Count > 0)
            {
                Sections.Add(Section.ToArray());
                Section.Clear();
            }

            PerMessageFields PerMessage;

            PerRecipientFields[] PerRecipients;
            int i, c = Sections.Count;

            if (c == 0)
            {
                PerMessage    = new PerMessageFields(new string[0]);
                PerRecipients = new PerRecipientFields[0];
            }
            else
            {
                PerMessage    = new PerMessageFields(Sections[0]);
                PerRecipients = new PerRecipientFields[c - 1];

                for (i = 1; i < c; i++)
                {
                    PerRecipients[i - 1] = new PerRecipientFields(Sections[i]);
                }
            }

            return(new DeliveryStatus(Dsn, PerMessage, PerRecipients));
        }