ActiveUp.Net.Mail.Parser.ParseAddresses C# (CSharp) Méthode

ParseAddresses() public static méthode

Parses a string containing addresses in the following formats : "John Doe" <[email protected]>,"Mike Johns" <[email protected]> "John Doe" <[email protected]>;"Mike Johns" <[email protected]> <[email protected]> [email protected]
public static ParseAddresses ( string input ) : ActiveUp.Net.Mail.AddressCollection
input string A string containing addresses in the formats desribed above.
Résultat ActiveUp.Net.Mail.AddressCollection
        public static AddressCollection ParseAddresses(string input)
		{
            AddressCollection addresses = new AddressCollection();
			string[] comma_separated = input.Split(',');
			for(int i=0;i<comma_separated.Length;i++) 
				if(comma_separated[i].IndexOf("@")==-1 && comma_separated.Length>(i+1)) 
					comma_separated[i+1] = comma_separated[i]+comma_separated[i+1];

			for(int i=0;i<comma_separated.Length;i++) /*if(comma_separated[i].IndexOf("@")!=-1)*/ 
				addresses.Add(Parser.ParseAddress((comma_separated[i].IndexOf("<")!=-1 && comma_separated[i].IndexOf(":")!=-1 && comma_separated[i].IndexOf(":")<comma_separated[i].IndexOf("<")) ? ((comma_separated[i].Split(':')[0].IndexOf("\"")==-1) ? comma_separated[i].Split(':')[1] : comma_separated[i]) : comma_separated[i]));

			return addresses;
		}
		public static Address ParseAddress(string input)

Usage Example

Exemple #1
0
        public static void ParseHeader(ref Header header)
        {
            string hdr = System.Text.Encoding.ASCII.GetString(header.OriginalData);
            hdr = System.Text.RegularExpressions.Regex.Match(hdr, @"[\s\S]+?((?=\r?\n\r?\n)|\Z)").Value;
            hdr = Parser.Unfold(hdr);
            hdr = Codec.RFC2047Decode(hdr);
            System.Text.RegularExpressions.Match m = System.Text.RegularExpressions.Regex.Match(hdr, @"(?<=((\r?\n)|\n)|\A)\S+:(.|(\r?\n[\t ]))+(?=((\r?\n)\S)|\Z)");
            while(m.Success)
            {
                string name = FormatFieldName(m.Value.Substring(0, m.Value.IndexOf(':')));
                string value = m.Value.Substring(m.Value.IndexOf(":") + 1);
                if (name.Equals("received")) header.Trace.Add(Parser.ParseTrace(m.Value.Trim(' ')));
                else if (name.Equals("to")) header.To = Parser.ParseAddresses(value);
                else if (name.Equals("cc")) header.Cc = Parser.ParseAddresses(value);
                else if (name.Equals("bcc")) header.Bcc = Parser.ParseAddresses(value);
                else if (name.Equals("reply-to")) header.ReplyTo = Parser.ParseAddress(value);
                else if (name.Equals("from")) header.From = Parser.ParseAddress(value);
                else if (name.Equals("sender")) header.Sender = Parser.ParseAddress(value);
                else if (name.Equals("content-type")) header.ContentType = Parser.GetContentType(m.Value);
                else if (name.Equals("content-disposition")) header.ContentDisposition = Parser.GetContentDisposition(m.Value);

                header.HeaderFields.Add(name, value);
                header.HeaderFieldNames.Add(name, m.Value.Substring(0, m.Value.IndexOf(':')));
                m = m.NextMatch();
            }
        }
All Usage Examples Of ActiveUp.Net.Mail.Parser::ParseAddresses