Populating the To MailAddressCollection

Nov 27, 2009 at 2:47 PM
Edited Nov 27, 2009 at 2:47 PM

Hi,

i have tested today your Mime Parser and i am very pleased by your work.

I just have found a little bug ( i guess ) about populating the To Mailadresscollection of the MailMessage.

Take a look at:

            if (message.To.Count == 0 && !string.IsNullOrEmpty(message.Headers["to"]))
            {
                string[] emails = message.Headers["to"].Split(',');
                for (int i = 0; i < emails.Length; i++)
                {
                    MailAddress address = null;
                    try
                    {
                        address = new MailAddress(emails[i]);
                        message.CC.Add(address);
                        // Should be:
                       // message.To.Add(address);
                    }
                    catch
                    {
                        try
                        {
                            address = new MailAddress(emails[i] + "," + emails[i + 1]);
                            i++;
                            message.CC.Add(address);
                            // Should be:
                            // message.To.Add(address);
                        }
                        catch
                        { }
                    }
                }
            }
Nov 28, 2009 at 7:13 PM
I'll take a look and adjust as necessary. I've made a good number of changes since we last communicated... Accommodating several new MIME types and such. When I get a chance I'll zip it up and send it to you.
Some of the changes may be specific to my needs, but address some other items in general. I had some issues with character sets, for instance... You can poke through when I send you the code.
I look forward to even more refinements between the two of us.
Jerry

From: [email removed]
Sent: Saturday, November 28, 2009 1:22 PM
To: [email removed]
Subject: Populating the To MailAddressCollection [mimeParser:76410]

From: Heslacher

Hi,

i have tested today your Mime Parser and i am very pleased by your work.

I just have found a little bug ( i guess ) about populating the To Mailadresscollection of the MailMessage.

Take a look at:

            if (message.To.Count == 0 && !string.IsNullOrEmpty(message.Headers["to"]))
            {
                string[] emails = message.Headers["to"].Split(',');
                for (int i = 0; i < emails.Length; i++)
                {
                    MailAddress address = null;
                    try
                    {
                        address = new MailAddress(emails[i]);
                        message.CC.Add(address);
                        // Should be:
                       // message.To.Add(address);
                    }
                    catch
                    {
                        try
                        {
                            address = new MailAddress(emails[i] + "," + emails[i + 1]);
                            i++;
                            message.CC.Add(address);
                            // Should be:
                            // message.To.Add(address);
                        }
                        catch
                        { }
                    }
                }
            }