Esempio n. 1
0
        void AddAddresses(Header header, InternetAddressList list)
        {
            int length = header.RawValue.Length;
            List <InternetAddress> parsed;
            int index = 0;

            // parse the addresses in the new header and add them to our address list
            if (!InternetAddressList.TryParse(Headers.Options, header.RawValue, ref index, length, false, false, out parsed))
            {
                return;
            }

            list.Changed -= InternetAddressListChanged;
            list.AddRange(parsed);
            list.Changed += InternetAddressListChanged;
        }
Esempio n. 2
0
        static bool TryParseGroup(ParserOptions options, byte[] text, int startIndex, ref int index, int endIndex, string name, int codepage, bool throwOnError, out InternetAddress address)
        {
            Encoding encoding = Encoding.GetEncoding(codepage);
            List <InternetAddress> members;

            address = null;

            // skip over the ':'
            index++;
            if (index >= endIndex)
            {
                if (throwOnError)
                {
                    throw new ParseException(string.Format("Incomplete address group at offset {0}", startIndex), startIndex, index);
                }

                return(false);
            }

            if (InternetAddressList.TryParse(options, text, ref index, endIndex, true, throwOnError, out members))
            {
                address = new GroupAddress(encoding, name, members);
            }
            else
            {
                address = new GroupAddress(encoding, name);
            }

            if (index >= endIndex || text[index] != (byte)';')
            {
                if (throwOnError)
                {
                    throw new ParseException(string.Format("Expected to find ';' at offset {0}", index), startIndex, index);
                }

                while (index < endIndex && text[index] != (byte)';')
                {
                    index++;
                }
            }
            else
            {
                index++;
            }

            return(true);
        }
Esempio n. 3
0
        static byte[] EncodeAddressHeader(ParserOptions options, FormatOptions format, Encoding charset, string field, string value)
        {
            var encoded    = new StringBuilder(" ");
            int lineLength = field.Length + 2;
            InternetAddressList list;

            if (!InternetAddressList.TryParse(options, value, out list))
            {
                return((byte[])format.NewLineBytes.Clone());
            }

            list.Encode(format, encoded, ref lineLength);
            encoded.Append(format.NewLine);

            if (format.International)
            {
                return(Encoding.UTF8.GetBytes(encoded.ToString()));
            }

            return(Encoding.ASCII.GetBytes(encoded.ToString()));
        }