-
-
Notifications
You must be signed in to change notification settings - Fork 372
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MailboxAddress.TryParse not respecting parser options #465
Comments
Apply the following patch to your local checkout:
Now try running the unit tests and see all the things that break. This is a non-trivial problem to fix. Dare I say, impossible to fix without introducing far worse breakages. |
I never should have added that option because I can't make it work the way you expect it to work due to real-world inputs that MimeKit must handle. |
You can VERY EASILY change your code to do the following: if (addr.IndexOf ('@') != -1 && MailboxAddress.TryParse (addr, out mailbox)) {
// do stuff
} |
Sounds good, I will make an extension method for it. I suppose we could
remove that flag from the parser options since it is not supported. That
would be a breaking compile change but shouldn't be a breaking behavior
change. Thoughts?
…-- Jeff
On Wed, Feb 20, 2019 at 3:29 PM Jeffrey Stedfast ***@***.***> wrote:
You can VERY EASILY change your code to do the following:
if (addr.IndexOf ('@') != -1 && MailboxAddress.TryParse (addr, out mailbox)) {
// do stuff
}
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#465 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABNoGJ3L_ogjfpL5K9Js0LbW87DrUGRUks5vPcw3gaJpZM4bBrDa>
.
|
The option is still used to make adjustments to the parser behavior, just not the way you are expecting. I would say the option is misleadingly named. Here's the unit test: [Test]
public void TestParseMailboxWithUnquotedCommaInName ()
{
const string text = "Worthington, Warren <[email protected]>";
InternetAddress addr;
AssertParse (text);
// default options should parse this as a single mailbox address
addr = InternetAddress.Parse (text);
Assert.AreEqual ("Worthington, Warren", addr.Name);
// this should fail when we allow mailbox addresses w/o a domain
var options = ParserOptions.Default.Clone ();
options.AllowAddressesWithoutDomain = true;
try {
addr = InternetAddress.Parse (options, text);
Assert.Fail ("Should not have parsed \"{0}\" with AllowAddressesWithoutDomain = true", text);
} catch (ParseException pex) {
Assert.AreEqual (text.IndexOf (','), pex.TokenIndex, "TokenIndex");
Assert.AreEqual (text.IndexOf (','), pex.ErrorIndex, "ErrorIndex");
} catch (Exception ex) {
Assert.Fail ("Should not have thrown {0}", ex.GetType ().Name);
}
} |
…Options.AllowAdddressesWithoutDomain ParserOptions.AllowUnquotedCommasInAddresses is now effectively the same as the old version of AllowAddressesWithoutDomain (but inverted). ParserOptions.AllowAdddressesWithoutDomain now works as people expected it to work. Fixes issue #465
The following code is returning true when it should be returning false:
bool result = MailboxAddress.TryParse(ParserOptions.Default, "asdasdadsasd", out _);
result = MailboxAddress.TryParse("asdasdadsasd", out _);
// result is true for both, however ParserOptions.Default.AllowAddressesWithoutDomain is false by default.
Issue #331 was closed, but this bug remains for over a year.
The text was updated successfully, but these errors were encountered: