https://redmine.ruby-lang.org/https://redmine.ruby-lang.org/favicon.ico?17113305112011-03-19T00:50:38ZRuby Issue Tracking SystemRuby master - Bug #4509: Net::IMAP::ResponseParseError: unexpected token CRLF (expected NUMBER) https://redmine.ruby-lang.org/issues/4509?journal_id=161382011-03-19T00:50:38Zdigger69 (Mark Nadig)mark@nadigs.net
<ul><li><strong>File</strong> <a href="/attachments/1546">bug4509.txt</a> <a class="icon-only icon-download" title="Download" href="/attachments/download/1546/bug4509.txt">bug4509.txt</a> added</li></ul><p>=begin<br>
[not sure what happened to body of submission - putting in as update]</p>
<p>To reproduce, create a free yahoo mail account. Using those credentials try this ruby code:</p>
<pre><code>require 'net/imap'
Net::IMAP.debug = true
conn = Net::IMAP.new('imap.mail.yahoo.com', 143, false)
conn.instance_eval { send_command('ID ("GUID" "1")') }
conn.authenticate('LOGIN', <username>, <password>)
conn.select("INBOX")
uids = conn.uid_search(['ALL'])
conn.logout
conn.disconnect
</code></pre>
<p>You should have at least one welcome email and the response from the conn.uid_search(['ALL']) will return "* SEARCH 1 \r\n" The trailing space before the CRLF seems unanticipated by search_response and causes the 'unexpected token' downstream in number. Here is my patch:</p>
<pre><code> def search_response # line 2706 imap.rb
token = match(T_ATOM)
name = token.value.upcase
token = lookahead
if token.symbol == T_SPACE
shift_token
data = []
while true
token = lookahead
</code></pre>
<p>#begin patch - yahoo IMAP was returning pattern " SEARCH 1 2 \r\n so was doing push on CRLF<br>
=begin before patch<br>
case token.symbol<br>
when T_CRLF<br>
break<br>
when T_SPACE<br>
shift_token<br>
end<br>
data.push(number)<br>
=end<br>
case token.symbol<br>
when T_CRLF<br>
break<br>
when T_SPACE<br>
shift_token<br>
else<br>
data.push(number)<br>
end<br>
#end patch<br>
end<br>
else<br>
data = []<br>
end<br>
return UntaggedResponse.new(name, data, @str)<br>
end</p>
<p>I confirmed this code is unchanged in p180 so didn't test it there. I hope this helps.<br>
=end</p> Ruby master - Bug #4509: Net::IMAP::ResponseParseError: unexpected token CRLF (expected NUMBER) https://redmine.ruby-lang.org/issues/4509?journal_id=162752011-04-04T22:34:52Zdigger69 (Mark Nadig)mark@nadigs.net
<ul></ul><p>=begin<br>
=== Better steps to repro<br>
I created a free account on yahoo to reproduce this error. Now, you can repro with these steps:<br>
(({require 'net/imap'<br>
conn = Net::IMAP.new('imap.mail.yahoo.com', 143, false)<br>
conn.instance_eval { send_command('ID ("GUID" "1")') }<br>
conn.authenticate('LOGIN', '<a href="mailto:bug.ruby@yahoo.com" class="email">bug.ruby@yahoo.com</a>', '!m@Pp@ssw0rd')<br>
conn.select("INBOX")<br>
uids = conn.uid_search(['ALL'])<br>
conn.logout<br>
conn.disconnect<br>
}))</p>
<p>Patch:<br>
def search_response # line 2706 imap.rb<br>
token = match(T_ATOM)<br>
name = token.value.upcase<br>
token = lookahead<br>
if token.symbol == T_SPACE<br>
shift_token<br>
data = []<br>
while true<br>
token = lookahead<br>
#begin patch - yahoo IMAP was returning pattern " SEARCH 1 2 \r\n so was doing push on CRLF<br>
=begin before patch<br>
case token.symbol<br>
when T_CRLF<br>
break<br>
when T_SPACE<br>
shift_token<br>
end<br>
data.push(number)<br>
=end<br>
case token.symbol<br>
when T_CRLF<br>
break<br>
when T_SPACE<br>
shift_token<br>
else<br>
data.push(number)<br>
end<br>
#end patch<br>
end<br>
else<br>
data = []<br>
end<br>
return UntaggedResponse.new(name, data, @str)<br>
end</p>
<p>=end</p> Ruby master - Bug #4509: Net::IMAP::ResponseParseError: unexpected token CRLF (expected NUMBER) https://redmine.ruby-lang.org/issues/4509?journal_id=162762011-04-04T22:40:49Zdigger69 (Mark Nadig)mark@nadigs.net
<ul></ul><p>=begin<br>
(({def a # test - why "Error: file empty." in bug report}))<br>
=end</p> Ruby master - Bug #4509: Net::IMAP::ResponseParseError: unexpected token CRLF (expected NUMBER) https://redmine.ruby-lang.org/issues/4509?journal_id=162772011-04-04T22:58:31Zdigger69 (Mark Nadig)mark@nadigs.net
<ul></ul><p>=begin<br>
=== Better steps to repro<br>
I created a free account on yahoo to reproduce this error. Now, you can repro with these steps:</p>
<p>require 'net/imap'<br>
conn = Net::IMAP.new('imap.mail.yahoo.com', 143, false)<br>
conn.instance_eval { send_command('ID ("GUID" "1")') }<br>
conn.authenticate('LOGIN', '<a href="mailto:bug.ruby@yahoo.com" class="email">bug.ruby@yahoo.com</a>', '!m@Pp@ssw0rd')<br>
conn.select("INBOX")<br>
uids = conn.uid_search(['ALL'])</p>
<p>This fails with "Net::IMAP::ResponseParseError: unexpected token CRLF (expected NUMBER)". I added the following patch locally and is working.</p>
<p>def search_response # line 2706 imap.rb<br>
token = match(T_ATOM)<br>
name = token.value.upcase<br>
token = lookahead<br>
if token.symbol == T_SPACE<br>
shift_token<br>
data = []<br>
while true<br>
token = lookahead<br>
#begin patch - yahoo IMAP was returning pattern " SEARCH 1 2 \r\n so was doing push on CRLF<br>
=begin before patch<br>
case token.symbol<br>
when T_CRLF<br>
break<br>
when T_SPACE<br>
shift_token<br>
end<br>
data.push(number)<br>
=end<br>
case token.symbol<br>
when T_CRLF<br>
break<br>
when T_SPACE<br>
shift_token<br>
else<br>
data.push(number)<br>
end<br>
#end patch<br>
end<br>
else<br>
data = []<br>
end<br>
return UntaggedResponse.new(name, data, @str)<br>
end</p>
<p>=end</p> Ruby master - Bug #4509: Net::IMAP::ResponseParseError: unexpected token CRLF (expected NUMBER) https://redmine.ruby-lang.org/issues/4509?journal_id=171792011-05-24T09:59:30Zghazel (Greg Hazel)ghazel@gmail.com
<ul></ul><p>I can reproduce this bug on 1.8.7 as well, and the exact same patch fixes the problem.</p> Ruby master - Bug #4509: Net::IMAP::ResponseParseError: unexpected token CRLF (expected NUMBER) https://redmine.ruby-lang.org/issues/4509?journal_id=171802011-05-24T10:09:45Zshugo (Shugo Maeda)
<ul><li><strong>Assignee</strong> set to <i>shugo (Shugo Maeda)</i></li></ul> Ruby master - Bug #4509: Net::IMAP::ResponseParseError: unexpected token CRLF (expected NUMBER) https://redmine.ruby-lang.org/issues/4509?journal_id=179952011-06-16T11:41:05Zshugo (Shugo Maeda)
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Closed</i></li><li><strong>% Done</strong> changed from <i>0</i> to <i>100</i></li></ul><p>This issue was solved with changeset r32114.<br>
Mark, thank you for reporting this issue.<br>
Your contribution to Ruby is greatly appreciated.<br>
May Ruby be with you.</p>
<hr>
<ul>
<li>lib/net/imap.rb (search_response): parses SEARCH responses from<br>
the Yahoo IMAP server correctly. patched by Mark Nadig. [Bug <a class="issue tracker-1 status-5 priority-4 priority-default closed" title="Bug: Net::IMAP::ResponseParseError: unexpected token CRLF (expected NUMBER) (Closed)" href="https://redmine.ruby-lang.org/issues/4509">#4509</a>]</li>
</ul>