Contrary to some of the posts here I have to agree with mmutz, you cannot parse emails with a regex... see this article:
https://www.rfc-editor.org/rfc/rfc2822#section-3.4.1
3.4.1. Addr-spec specification
An addr-spec is a specific Internet
identifier that contains a locally
interpreted string followed by the
at-sign character ("@", ASCII value
64) followed by an Internet domain.
The idea of "locally interpreted" means that only the receiving server is expected to be able to parse it.
If I were going to try and solve this I would find the "To" line contents, break it apart and attempt to parse each segment with System.Net.Mail.MailAddress.
static void Main()
{
string input = @"Thread-Topic: test subject
Thread-Index: AcwE4mK6Jj19Hgi0SV6yYKvj2/HJbw==
From: ""Lastname, Firstname"" <firstname_lastname@domain.com>
To: <testto@domain.com>, ""Yes, this is valid""@[emails are hard to parse!], testto1@domain.com, testto2@domain.com
Cc: <testcc@domain.com>, test3@domain.com
X-OriginalArrivalTime: 27 Apr 2011 13:52:46.0235 (UTC) FILETIME=[635226B0:01CC04E2]";
Regex toline = new Regex(@"(?im-:^To\s*:\s*(?<to>.*)$)");
string to = toline.Match(input).Groups["to"].Value;
int from = 0;
int pos = 0;
int found;
string test;
while(from < to.Length)
{
found = (found = to.IndexOf(',', from)) > 0 ? found : to.Length;
from = found + 1;
test = to.Substring(pos, found - pos);
try
{
System.Net.Mail.MailAddress addy = new System.Net.Mail.MailAddress(test.Trim());
Console.WriteLine(addy.Address);
pos = found + 1;
}
catch (FormatException)
{
}
}
}
Output from the above program:
testto@domain.com
"Yes, this is valid"@[emails are hard to parse!]
testto1@domain.com
testto2@domain.com