This project is read-only.

Fetching the CC & BCC email list.

Jun 27, 2009 at 12:05 PM

How can I fetch the no of email id's mention in CC & BCC.

I tried it but i am getting only one Email ID. I want to fetch all the CC & BCC email id's.

Jun 27, 2009 at 1:34 PM
Edited Sep 3, 2009 at 3:13 PM

How can I fetch the no of email id's mention in CC & BCC.

I tried it but i am getting only one Email ID. I want to fetch all the CC & BCC email id's.

Sep 3, 2009 at 2:55 PM

I found the problem and fixed it.

Tested this with MS Exchange 2007 IMAPS

code fix:(ImapAddressCollection.cs)

 

private ImapAddressList CreateCollection(string AddressList)
        {
            AddressList = Regex.Replace(AddressList, "\\\\\"", "'");
            AddressList = Regex.Replace(AddressList, @"\.\.", ".");
            //if (AddressList.Contains("Carleton"))
            //    throw new Exception();
            ImapAddressList Addresses = new ImapAddressList();
            string re1 = "(\\()";     // Any Single Character 1
            string re2 = ".*?"; // Non-greedy match on filler
            string re3 = "(\\))";     // Any Single Character 2
            Regex r = new Regex(re1 + re2 + re3, RegexOptions.IgnoreCase | RegexOptions.Singleline);
            MatchCollection matches = r.Matches(AddressList);
            //MatchCollection matches = Regex.Matches(AddressList, @"\(((?>\((?<LEVEL>)|\)(?<-LEVEL>)|(?! \( | \) ).)+(?(LEVEL)(?!)))\)$");
           
            foreach (Match match in matches)
            {
                StringBuilder displayName = new StringBuilder("");
                StringBuilder email = new StringBuilder("");
                
                string value = match.Groups[0].ToString().Trim();
                value = value.Replace("(", string.Empty);
                value = value.Replace(")", string.Empty);
                
                // Display Name
                if (!(value.StartsWith("NIL")))
                {
                    Match sub;
                    if ((sub = Regex.Match(value, @"^{(\d+)}(.*)")).Success) {
                        value = "\"" + sub.Groups[2].Value.Insert(Convert.ToInt32(sub.Groups[1].Value), "\"");
                    }
                    sub = Regex.Match(value, @"""([^""]+)""");
                    displayName.Append(sub.Groups[1].ToString());
                    value = value.Substring(sub.Length).Trim();
                }
                else
                    value = value.Substring(3).Trim();
                // Display Name Extended
                if (!(value.StartsWith("NIL")))
                {
                    Match sub;
                    if ((sub = Regex.Match(value, @"^{(\d+)}(.*)")).Success)
                    {
                        value = "\"" + sub.Groups[2].Value.Insert(Convert.ToInt32(sub.Groups[1].Value), "\"");
                    }
                    sub = Regex.Match(value, @"""([^""]+)""");
                    displayName.Append(" " + sub.Groups[1].ToString());
                    value = value.Substring(sub.Length).Trim();
                }
                else
                    value = value.Substring(3).Trim();
                // Email Prefix
                if (!(value.StartsWith("NIL")))
                {
                    Match sub;
                    if ((sub = Regex.Match(value, @"^{(\d+)}(.*)")).Success)
                    {
                        value = "\"" + sub.Groups[2].Value.Insert(Convert.ToInt32(sub.Groups[1].Value), "\"");
                    }
                    sub = Regex.Match(value, @"""([^""]+)""");
                    email.Append(sub.Groups[1].ToString());
                    value = value.Substring(sub.Length).Trim();
                }
                else
                    value = value.Substring(3).Trim();
                // Email Suffix
                if (!(value.StartsWith("NIL")))
                {
                    Match sub;
                    if ((sub = Regex.Match(value, @"^{(\d+)}(.*)")).Success)
                    {
                        value = "\"" + sub.Groups[2].Value.Insert(Convert.ToInt32(sub.Groups[1].Value), "\"");
                    }
                    sub = Regex.Match(value, @"""([^""]+)""");
                    email.Append("@" + sub.Groups[1].ToString());
                    value = value.Substring(sub.Length).Trim();
                }
                else
                    value = value.Substring(3).Trim();
                if (email.ToString().IndexOf('@') < 0)
                    email = new StringBuilder("undisclosed-recipients@localhost");
                ImapAddress address = new ImapAddress(email.ToString(), ImapDecode.Decode(displayName.ToString()));
                Addresses.Add(address);
                //return Addresses; // not sure how this got here.
            }
            return Addresses;
        }

 

 

 

private ImapAddressList CreateCollection(string AddressList)

        {

            AddressList = Regex.Replace(AddressList, "\\\\\"", "'");

            AddressList = Regex.Replace(AddressList, @"\.\.", ".");

            //if (AddressList.Contains("Carleton"))

            //    throw new Exception();

            ImapAddressList Addresses = new ImapAddressList();

	    //BEGIN FIX PART A

            string re1 = "(\\()";     // Any Single Character 1

            string re2 = ".*?"; // Non-greedy match on filler

            string re3 = "(\\))";     // Any Single Character 2

            Regex r = new Regex(re1 + re2 + re3, RegexOptions.IgnoreCase | RegexOptions.Singleline);

            MatchCollection matches = r.Matches(AddressList);

            //MatchCollection matches = Regex.Matches(AddressList, @"\(((?>\((?<LEVEL>)|\)(?<-LEVEL>)|(?! \( | \) ).)+(?(LEVEL)(?!)))\)mce_markerquot;);

            //END FIX PART A

           

            foreach (Match match in matches)

            {

                StringBuilder displayName = new StringBuilder("");

                StringBuilder email = new StringBuilder("");

                //START FIX PART B

		//string value = match.Groups[1].ToString().Trim();    

                string value = match.Groups[0].ToString().Trim();

                value = value.Replace("(", string.Empty);

                value = value.Replace(")", string.Empty);

                //END FIX PART B

                // Display Name

                if (!(value.StartsWith("NIL")))

                {

                    Match sub;

                    if ((sub = Regex.Match(value, @"^{(\d+)}(.*)")).Success) {

                        value = "\"" + sub.Groups[2].Value.Insert(Convert.ToInt32(sub.Groups[1].Value), "\"");

                    }

                    sub = Regex.Match(value, @"""([^""]+)""");

                    displayName.Append(sub.Groups[1].ToString());

                    value = value.Substring(sub.Length).Trim();

                }

                else

                    value = value.Substring(3).Trim();

                // Display Name Extended

                if (!(value.StartsWith("NIL")))

                {

                    Match sub;

                    if ((sub = Regex.Match(value, @"^{(\d+)}(.*)")).Success)

                    {

                        value = "\"" + sub.Groups[2].Value.Insert(Convert.ToInt32(sub.Groups[1].Value), "\"");

                    }

                    sub = Regex.Match(value, @"""([^""]+)""");

                    displayName.Append(" " + sub.Groups[1].ToString());

                    value = value.Substring(sub.Length).Trim();

                }

                else

                    value = value.Substring(3).Trim();

                // Email Prefix

                if (!(value.StartsWith("NIL")))

                {

                    Match sub;

                    if ((sub = Regex.Match(value, @"^{(\d+)}(.*)")).Success)

                    {

                        value = "\"" + sub.Groups[2].Value.Insert(Convert.ToInt32(sub.Groups[1].Value), "\"");

                    }

                    sub = Regex.Match(value, @"""([^""]+)""");

                    email.Append(sub.Groups[1].ToString());

                    value = value.Substring(sub.Length).Trim();

                }

                else

                    value = value.Substring(3).Trim();

                // Email Suffix

                if (!(value.StartsWith("NIL")))

                {

                    Match sub;

                    if ((sub = Regex.Match(value, @"^{(\d+)}(.*)")).Success)

                    {

                        value = "\"" + sub.Groups[2].Value.Insert(Convert.ToInt32(sub.Groups[1].Value), "\"");

                    }

                    sub = Regex.Match(value, @"""([^""]+)""");

                    email.Append("@" + sub.Groups[1].ToString());

                    value = value.Substring(sub.Length).Trim();

                }

                else

                    value = value.Substring(3).Trim();

                if (email.ToString().IndexOf('@') < 0)

                    email = new StringBuilder("undisclosed-recipients@localhost");

                ImapAddress address = new ImapAddress(email.ToString(), ImapDecode.Decode(displayName.ToString()));

                Addresses.Add(address);

                //return Addresses; // not sure how this got here.

            }

            return Addresses;

        }

 

 

 

 

Sep 3, 2009 at 3:11 PM

Thanks gyratefiber....

I will put this code in my project. & Let you know the status....

thanks again....

Sep 3, 2009 at 3:36 PM

 

There is actually a bug i just found.

If the displayname of the email had a "(" or a ")" then it would return null.

Replace my FIX A with :

 

            string re1 = "(\\()";	// Any Single Character 1
            string re2 = "(\")";	// Any Single Character 2
            string re3 = ".*?";	// Non-greedy match on filler
            string re4 = "\"";	// Uninteresting: c
            string re5 = ".*?";	// Non-greedy match on filler
            string re6 = "\"";	// Uninteresting: c
            string re7 = ".*?";	// Non-greedy match on filler
            string re8 = "\"";	// Uninteresting: c
            string re9 = ".*?";	// Non-greedy match on filler
            string re10 = "\"";	// Uninteresting: c
            string re11 = ".*?";	// Non-greedy match on filler
            string re12 = "(\")";	// Any Single Character 3
            string re13 = "(\\))";	// Any Single Character 4

            Regex r = new Regex(re1 + re2 + re3 + re4 + re5 + re6 + re7 + re8 + re9 + re10 + re11 + re12 + re13, RegexOptions.IgnoreCase | RegexOptions.Singleline);


            MatchCollection matches = r.Matches(AddressList);

and my fix B with :

 

                string value = match.Groups[0].ToString().Trim();
                value = value.Substring(0, value.Length - 1); // Removes last ")"
                value = value.Substring(1, value.Length - 1); // Removes first "("

 

Cheers!