# Saturday, September 20, 2008
Hi

Found a serious bug in .net 3.5 sp1 today concerning email addresses and international characters. The class MailAddressCollection used in MailMessage has a nice overload Add(string) which parses comma separated email addresses and creates MailAddress objects of these. A very nice thought.

When passing email addresses with international characters, this method throws an 'System.FormatException'. For example:

Normalbakke, Sølvi <solvi.normalbakke@abc.de>,"ulv, Per" <per.ulv@def.gh>

fails...

while

Luth, trude <trude.luth@abc.de>, Larsen, Kamuf <kamuf.larsen@ping.pong>

works.

The strange thing is that this code works correctly. No Exceptions...

MailAddress m = new MailAddress("Normalbakke, Sølvi <solvi.normalbakke@abc.de>").

I made this piece of ugly code to circumvent the bug. I know that there probably is a nasty regex that can do this more nicely, but the fact that you can have more or less any character in the display name of the address, makes this too hard to bother with. I spent an hour trying, without any success at least... Feel free to comment and improve.

                MailAddressCollection coll = new MailAddressCollection();
                string[] emails ="Normalbakke, Sølvi <solvi.normalbakke@abc.de>,\"ulv, Per\" <per.ulv@def.gh>".Split(',');
                for (int i = 0; i < emails.Length; i++)
                {
                    MailAddress address = null;
                    try
                    {
                        address = new MailAddress(emails[i]);
                    }
                    catch
                    {
                        address = new MailAddress(emails[i] + "," + emails[i + 1]);
                        i++;
                    }
                    coll .Add(address);
                }

The fact that MailAddress parses correctly, but not MailAddressCollection makes me think that the developers has duplicated some really closely related code here. tsk tsk...

Snorre Garmann

Saturday, September 20, 2008 12:54:05 PM (W. Europe Standard Time, UTC+01:00)
Comments are closed.
Search
Navigation
On this page....
Archives
<July 2010>
SunMonTueWedThuFriSat
27282930123
45678910
11121314151617
18192021222324
25262728293031
1234567
Aggregate Me!
Feed your aggregator (RSS 2.0)
Categories
Blogroll
Contact me
Send mail to the author(s) E-mail
Administration