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.exceptions.ProtocolError: Server replied with a response that violates the IMAP protocol #351

Closed
foxsam21 opened this issue May 11, 2018 · 7 comments
Assignees

Comments

@foxsam21
Copy link

Sometimes I get this error after new email is received.
imapclient.exceptions.ProtocolError: Server replied with a response that violates the IMAP protocol
I ran my code with debugging and the log is available here: https://pastebin.com/4Pc46YRD

I am connectting to gmail imap server and I am not sure how to fully reproduce this error. But it always happens eventually and only after mail is received.

@mjs
Copy link
Owner

mjs commented Aug 27, 2018

The debug output is super useful. Thanks for collecting it.

It looks like Gmail is sometimes not returning a valid untagged response (note how 14 FLAGS (\Seen)) doesn't begin with *). I'll have to double check the specs to make sure IMAPClient is doing everything right but we might have to make IMAPClient a bit more relaxed about what it accepts or something.

@mjs mjs self-assigned this Aug 27, 2018
@christianbur
Copy link

christianbur commented Sep 18, 2018

Here's a few more examples.
the problem concerns only with dovecot (mailcow) but not with gmx.de or gmail.com

2018-09-17 17:28:26,560 - Thread-mail_example.de_mx1 - DEBUG: IMAP IDLE response: []
2018-09-17 17:28:26,572 - Thread-mail_example.de_mx1 - DEBUG: < b'here'
2018-09-17 17:28:26,572 - Thread-mail_example.de_mx1 - ERROR: ERROR: Server replied with a response that violates the IMAP protocol

018-09-18 07:36:26,070 - Thread-mail_example.de_mx1 - DEBUG: IMAP IDLE response: []
2018-09-18 07:36:26,082 - Thread-mail_example.de_mx1 - DEBUG: < b' Still here'
2018-09-18 07:36:26,083 - Thread-mail_example.de_mx1 - ERROR: ERROR: Server replied with a response that violates the IMAP protocol

2018-09-18 20:20:26,817 - Thread-mail_example.de_mx2 - DEBUG: IMAP IDLE response: []
2018-09-18 20:20:26,830 - Thread-mail_example.de_mx2 - DEBUG: < b'till here'
2018-09-18 20:20:26,830 - Thread-mail_example.de_mx2 - ERROR: ERROR: Server replied with a response that violates the IMAP protocol

2018-09-18 20:16:26,090 - Thread-mail_test.de_mx1 - DEBUG: IMAP IDLE response: []
2018-09-18 20:16:26,105 - Thread-mail_test.de_mx1 - DEBUG: < b''
2018-09-18 20:16:26,106 - Thread-mail_test.de_mx1 - ERROR: ERROR: Server replied with a response that violates the IMAP protocol

2018-09-18 20:20:26,752 - Thread-mail_test.de_mx2 - DEBUG: IMAP IDLE response: []
2018-09-18 20:20:26,764 - Thread-mail_test.de_mx2 - DEBUG: < b'l here'
2018-09-18 20:20:26,765 - Thread-mail_test.de_mx2 - ERROR: ERROR: Server replied with a response that violates the IMAP protocol

@OnnoH
Copy link

OnnoH commented Jul 14, 2020

I get this exception when I issue a NOOP command to Gmail:

2020-07-14 14:22:49,616 - imapclient.imaplib - DEBUG - > b'BCLH7 NOOP'
2020-07-14 14:22:49,741 - imapclient.imaplib - DEBUG - < b'BCLH6 BAD Could not parse command'
2020-07-14 14:22:49,741 - imapclient.imaplib - DEBUG - 	matched b'(?P<tag>BCLH\\d+) (?P<type>[A-Z]+) (?P<data>.*)' => (b'BCLH6', b'BAD', b'Could not parse command')
2020-07-14 14:22:49,741 - imapclient.imaplib - DEBUG - BAD response: b'Could not parse command'
2020-07-14 14:22:49,741 - imapclient.imaplib - DEBUG - > b'BCLH8 LOGOUT'

@OnnoH
Copy link

OnnoH commented Jul 14, 2020

And something else with Outlook.com:

2020-07-14 16:42:14,223 - imapclient.imaplib - DEBUG - > b'FONL7 NOOP'
2020-07-14 16:42:14,251 - imapclient.imaplib - DEBUG - < b'FONL7 BAD Command received in Invalid state.'
2020-07-14 16:42:14,251 - imapclient.imaplib - DEBUG - 	matched b'(?P<tag>FONL\\d+) (?P<type>[A-Z]+) (?P<data>.*)' => (b'FONL7', b'BAD', b'Command received in Invalid state.')
2020-07-14 16:42:14,251 - imapclient.imaplib - DEBUG - BAD response: b'Command received in Invalid state.'
2020-07-14 16:42:14,251 - imapclient.imaplib - DEBUG - > b'FONL8 LOGOUT'

@mjs
Copy link
Owner

mjs commented Jul 19, 2020

It seems like you might be calling NOOP while idling. Is that possible? You need stop idling by calling idle_done before any other commands can be issued (including NOOP).

@mjs
Copy link
Owner

mjs commented Jul 19, 2020

It would be useful if you could provide a minimal code example that triggers the problem.

@mjs
Copy link
Owner

mjs commented Jan 16, 2021

Closing due to inactivity. Please reopen if this is still a problem for you and you are able to provide more detail.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants