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

ImapClient.ConnectAsync fails in v4.2.0: Syntax error in CAPABILITIES. Unexpected token: '+' #1654

Closed
dsuesstr opened this issue Oct 5, 2023 · 10 comments
Labels
bug Something isn't working

Comments

@dsuesstr
Copy link

dsuesstr commented Oct 5, 2023

The ImapClient fails on ConnectAsync after we updated the nuget from 4.1.0 to 4.2.0 with the message:

Syntax error in CAPABILITIES. Unexpected token: '+'

We tested with different servers (e.g. outlook.office365.com)

Platform

  • OS: Windows
  • .NET Runtime: CoreCLR
  • .NET Framework: .NET 6
  • MailKit Version: 4.2

Exception
Syntax error in CAPABILITIES. Unexpected token: '+' ---> MailKit.Net.Imap.ImapProtocolException: Syntax error in CAPABILITIES. Unexpected token: '+'
ImapEngine.UpdateCapabilitiesAsync(ImapTokenType sentinel, CancellationToken cancellationToken)
ImapEngine.ProcessUntaggedResponseAsync(CancellationToken cancellationToken)
ImapCommand.StepAsync()
ImapEngine.IterateAsync()
ImapEngine.RunAsync(ImapCommand ic)
ImapClient.ConnectAsync(String host, Int32 port, SecureSocketOptions options, CancellationToken cancellationToken)
ImapClient.CreateImapClientAsync(CancellationToken cancellationToken) line 128

Code Snippets

using var imapClient = new ImapClient();
var port = _config.Port; // 993
var encryption = _config.Encryption; // SslOnConnect

await _imapClient.ConnectAsync(_config.Address, port, encryption, cancellationToken); // <-- throws exception
// ...
@dsuesstr dsuesstr changed the title ImapClient.ConnectAsync fails after update from 4.1.0 to 4.2.0 ImapClient.ConnectAsync fails after update from 4.1.0 to 4.2.0: Syntax error in CAPABILITIES Oct 5, 2023
@jstedfast
Copy link
Owner

Darn, was afraid of this... can you provide the protocol log so that I can fix this properly?

using var imapClient = new ImapClient(new ProtocolLogger ("imap.log"));

@jstedfast jstedfast added the bug Something isn't working label Oct 5, 2023
@dsuesstr
Copy link
Author

dsuesstr commented Oct 6, 2023

here's the log (Replaced the hostname with

Connected to imaps://<omittted>:993/
S: * OK IMAP4 ready
C: A00000000 CAPABILITY
S: * CAPABILITY IMAP4rev1 UIDPLUS IDLE LITERAL + QUOTA AUTH=PLAIN AUTH=LOGIN
S: A00000000 OK completed

@jstedfast jstedfast changed the title ImapClient.ConnectAsync fails after update from 4.1.0 to 4.2.0: Syntax error in CAPABILITIES ImapClient.ConnectAsync fails in v4.2.0: Syntax error in CAPABILITIES. Unexpected token: '+' Oct 6, 2023
@jstedfast
Copy link
Owner

Does this happen to be imaps://mail.infomaniak.com:993/ like in the other bug report I just marked as a duplicate of this one?

LITERAL + is a server bug because it SHOULD be LITERAL+ (i.e. no space).

That said, I'm sure I can whip up a fix for you guys.

@jstedfast
Copy link
Owner

In about an hour (maybe less), https://www.myget.org/feed/mimekit/package/nuget/MailKit should have a v4.2.0.836 that you can install to test this fix.

Let me know if you run into any other issues.

Thanks!

@jpmaistrebazin
Copy link

No we get a new exception

System.InvalidCastException: Unable to cast object of type 'System.Char' to type 'System.String'.
at MailKit.Net.Imap.ImapEngine.UpdateCapabilitiesAsync(ImapTokenType sentinel, CancellationToken cancellationToken)
at MailKit.Net.Imap.ImapEngine.ProcessUntaggedResponseAsync(CancellationToken cancellationToken)
at MailKit.Net.Imap.ImapCommand.StepAsync()
at MailKit.Net.Imap.ImapEngine.IterateAsync()
at MailKit.Net.Imap.ImapEngine.RunAsync(ImapCommand ic)
at MailKit.Net.Imap.ImapClient.PostConnectAsync(Stream stream, String host, Int32 port, SecureSocketOptions options, Boolean starttls, CancellationToken cancellationToken)
at MailKit.Net.Imap.ImapClient.ConnectAsync(String host, Int32 port, SecureSocketOptions options, CancellationToken cancellationToken)
at RsSolutions.Motor.Test.EmailTest.Connect_Test() in /Users/jean-philippe/_work/rs-motor/rs-motor-api/RsSolutions.Motor.Test/EmailTest.cs:line 21

@jstedfast
Copy link
Owner

d'oh, thanks.

@jstedfast
Copy link
Owner

Just pushed a fix for that. It should be v4.2.0.837 when it gets uploaded to myget

@jpmaistrebazin
Copy link

jpmaistrebazin commented Oct 6, 2023

It works, I don't have any exception, thank for your reactivity

@dsuesstr
Copy link
Author

@jstedfast thanks for the fix (or workaround). works for us too.
And yes, it is the same mail host (infomaniak) :). I'll also create a ticket with them.

@jstedfast
Copy link
Owner

This was released as part of MailKit v4.3.0

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

3 participants