MailKit icon indicating copy to clipboard operation
MailKit copied to clipboard

Can't Get Folders in Outlook.

Open yuribb opened this issue 10 years ago • 6 comments

Hello, I'm trying to authenticate with OAuth2. During the authentication process i see in LogProtocol following strings:

"Outlook.com IMAP4rev1 server version 17.4.0.0 ready (BLU452-IMAP255)

[email protected] DEBUG 2016-01-20 10:03:26,559 5671ms ImapProtocolLogger LogClient - client: A00000000 CAPABILITY

[email protected] DEBUG 2016-01-20 10:03:26,574 5687ms ImapProtocolLogger LogServer - server: * CAPABILITY IMAP4rev1 CHILDREN ID NAMESPACE UIDPLUS UNSELECT AUTH=PLAIN AUTH=XOAUTH2 SASL-IR

[email protected] DEBUG 2016-01-20 10:03:26,668 5781ms ImapProtocolLogger LogServer - server: A00000000 OK CAPABILITY completed

[email protected] DEBUG 2016-01-20 10:03:26,668 5781ms Email-Service MoveNext - Auth to [email protected] [email protected] DEBUG 2016-01-20 10:03:26,684 5796ms ImapProtocolLogger LogClient - client: A00000001 AUTHENTICATE XOAUTH2 %AccessTokenHere%

[email protected] DEBUG 2016-01-20 10:03:34,121 13234ms ImapProtocolLogger LogServer - server: A00000001 OK AUTHENTICATE completed.

[email protected] DEBUG 2016-01-20 10:03:34,137 13249ms ImapProtocolLogger LogClient - client: A00000002 CAPABILITY

[email protected] DEBUG 2016-01-20 10:03:34,434 13546ms ImapProtocolLogger LogServer - server: * CAPABILITY IMAP4 IMAP4rev1 AUTH=PLAIN AUTH=XOAUTH2 SASL-IR UIDPLUS MOVE ID UNSELECT CLIENTACCESSRULES CLIENTNETWORKPRESENCELOCATION CHILDREN IDLE NAMESPACE LITERAL+ A00000002 OK CAPABILITY completed.

[email protected] DEBUG 2016-01-20 10:03:34,434 13546ms ImapProtocolLogger LogClient - client: A00000003 NAMESPACE

[email protected] DEBUG 2016-01-20 10:03:34,730 13843ms ImapProtocolLogger LogServer - server: A00000003 BAD User is authenticated but not connected.

[email protected] DEBUG 2016-01-20 10:03:34,730 13843ms ImapProtocolLogger LogClient - client: A00000004 LIST "" "INBOX"

[email protected] DEBUG 2016-01-20 10:03:35,027 14140ms ImapProtocolLogger LogServer - server: A00000004 BAD User is authenticated but not connected.

 BYE Connection closed. 14"

After that i'm trying to get Folders from imap client, but PersonalNamespace, OtherNamespace, SharedNamespace, SpecialFodlers ansd Inbox return null. I would like to know whether it is related to MailKit or Imap?

yuribb avatar Jan 21 '16 14:01 yuribb

This is a bug in your IMAP server.

Notice that right after MailKit authenticates with A00000001 AUTHENTICATE XOAUTH2 %AccessTokenHere%, the server says that you are authenticated (A00000001 OK AUTHENTICATE completed.).

Then, later, when MailKit sends the NAMESPACE command, the server responds with:

A00000003 BAD User is authenticated but not connected.

That doesn't make any sense. Obviously the client is connected or else it wouldn't be able to send a command! Nor would it be able to receive the response!

jstedfast avatar Jan 21 '16 15:01 jstedfast

Here's something you can try as a possible work-around:

client.Connect ("imap.outlook.com", 993, true);

// disable SASL-IR, perhaps that is breaking Outlook.com's authentication state?
client.Capabilties &= ~ImapCapabilties.SaslIR;

client.Authenticate ("username", "access_token");

jstedfast avatar Jan 21 '16 15:01 jstedfast

Thank you for your quick reply. I will try to use your work-around.

yuribb avatar Jan 21 '16 16:01 yuribb

Did it work for you?

jstedfast avatar Jan 22 '16 00:01 jstedfast

Sorry about long answer. It didn't work for me.

yuribb avatar Jan 25 '16 14:01 yuribb

Perhaps the problem is that MailKit is re-querying the CAPABILITIES? According to the specification, a client is supposed to requery the CAPABILITIES after successfully authenticating, but perhaps Outlook.com is broken and resets its state when the client queries for the CAPABILITIES?

Just a guess.

You could test this theory by commenting out line 999 and 1000 in ImapClient.cs:

https://github.com/jstedfast/MailKit/blob/master/MailKit/Net/Imap/ImapClient.cs#L999

jstedfast avatar Jan 25 '16 16:01 jstedfast