Skip to content
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

ArgumentNullException (message) during AuthenticateAsync #774

Closed
jonathanduke opened this issue Nov 8, 2018 · 3 comments
Closed

ArgumentNullException (message) during AuthenticateAsync #774

jonathanduke opened this issue Nov 8, 2018 · 3 comments
Labels
bug Something isn't working

Comments

@jonathanduke
Copy link

Describe the bug
After updating to 2.0.7 from 2.0.6, I now get an ArgumentNullException during a call to AuthenticateAsync. This appears to be due to a null check on the message argument to the AuthenticatedEventArgs constructor that was recently added.

To Reproduce
Steps to reproduce the behavior:

  1. Initialize an ImapClient.
  2. Wire up an empty event handler to the Authenticated event. (The exception does not occur if this is not done.)
  3. Call ConnectAsync to connect to your desired mail server.
  4. Call AuthenticateAsync to authenticate with a server that does not return a proper message.
  5. ArgumentNullException will be thrown.

Workaround
Do not subscribe to the Authenticated event on the mail client, since the exception will not be thrown if the event is not fired in OnAuthenticate.

Suggested fix
line 1305 of MailService.cs, in OnAuthenticated:
handler (this, new AuthenticatedEventArgs (message ?? ""));

(rather than submit a pull request I figured an issue was more appropriate so that you can evaluate if this is the best fix and if this same type of error may have been introduced elsewhere)

Expected behavior
As before, I would expect OnAuthenticated to fire the Authenticated event without an exception. If the Message property needs to be non-null, then either the constructor should set it to an empty string rather than throwing an argument exception, or the MailService should set it before passing a null message to the constructor in the OnAuthenticated method. Possibly something else should be done in ImapClient's AuthenticateAsync method when ic.ResponseText is null, but MailService still needs to handle it gracefully or the potential for the exception would still exist in Pop3Client and SmtpClient as well.

Additional context
I am currently authenticating against FastMail's IMAP server, which may be doing something weird that is causing the message to be null. Nevertheless, I am not really interested in the message but just that authentication completed successfully, so the exception caught me by surprise.

jstedfast added a commit that referenced this issue Nov 8, 2018
@jstedfast
Copy link
Owner

Wow, awesome bug report :)

Thanks!

@jonathanduke
Copy link
Author

Looks good. Thanks for the awesome library!

@jstedfast jstedfast added the bug Something isn't working label Dec 1, 2018
@jstedfast
Copy link
Owner

Okay, MASSIVE new 2.1.0 release has been pushed. I would recommend reading the ReleaseNotes.md.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants