-
Notifications
You must be signed in to change notification settings - Fork 29
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
"ResponseParseError: unexpected token NUMBER
(expected ATOM
)" on old exchange mail servers
#250
Comments
(Sorry for the slow reply) Yeah, every response must start with one of:
It boggles my mind how often servers, including the ones from the biggest software companies in the world, fail at the absolute basics of the protocol. I do think that Net::IMAP should be more resilient to buggy responses, in general. But I'm hesitant to include something this far out-of-spec into the parser... yet. I've actually been working through basic quoted string escape bugs from a certain fruit-named company's iMAP iServer, for the last week or so. Ultimately, I don't think I'll even be pushing a PR for that workaround either. 🙁 |
I do have other ideas for improving robustness:
So, although I'm reluctant to include it in the generic parser code, I'm curious to see what you came up with, and how you solved this for yourself. If you post something (in this ticket or in a PR), at the very least that documents the workaround for others who get to this issue via search engines. |
Oh, although I doubt that it makes any difference for this issue, you should use RFC4315 for UIDPLUS (or RFC9051, which includes UIDPLUS). RFC2359 is obsolete (and was already obsolete for a nearly decade by 2013). But it is sometimes informative to read the obsolete RFCs, especially when dealing with very old servers. 🙂 |
No worries :)
I have got it working using these changes. But i am not sure if there are any unwanted side effects with other servers and so on. diff --git a/lib/net/imap/response_parser.rb b/lib/net/imap/response_parser.rb
index 1aab798..d2dc08e 100644
--- a/lib/net/imap/response_parser.rb
+++ b/lib/net/imap/response_parser.rb
@@ -655,6 +655,7 @@ module Net
resp = case lookahead!(T_PLUS, T_STAR, *TAG_TOKENS).symbol
when T_PLUS then continue_req
when T_STAR then response_data
+ when T_LBRA then invalid_exchange_response
else response_tagged
end
accept_spaces # QUIRKY: Ignore trailing space (MS Exchange Server?)
@@ -776,6 +777,10 @@ module Net
alias comparator_data response_data__unhandled
alias message_data__converted response_data__unhandled
+ def invalid_exchange_response
+ UntaggedResponse.new(OK, resp_text, @str)
+ end
+
# RFC3501 & RFC9051:
# response-tagged = tag SP resp-cond-state CRLF
def response_tagged However i do not use this parser change anymore as i have seen that it seems to work with the @imap.select(source_mailbox)
response = @imap.uid_copy(uid_to_copy, destination_mailbox)
@imap.uid_store(uid_to_copy, '+FLAGS', [Net::IMAP::DELETED])
@imap.uid_expunge(uid_to_copy)
uid_after_copy = response.data.code.data.assigned_uids.first Ironically the Here the debug log for this:
That sounds interesting. Also the existing hacks in the |
Needed to work with an old exchange mail server. The
ID
command reports:("name" "Microsoft.Exchange.Imap4.Imap4Server" "version" "15.0")
which according to this microsoft document should be an Exchange 2013 server.After i sent an
UID MOVE
command it failed with the mentionedResponseParserError
.I enabled the debug logging and got the following output:
As i understand RFC 2359 there should be an
OK
in front of theCOPYUID
?Should the parser be able to handle such incorrect responses?
I have managed to build a hack for the parser locally to get it parsed and could submit a PR for the fix after some refactoring.
I have also checked against the Exchange implementation for Microsoft 365 and this does not have the error. The
ID
command reports:("name" "Microsoft.Exchange.Imap4.Imap4Server" "version" "15.20")
here.The text was updated successfully, but these errors were encountered: