开发者

Connecting to Yahoo! mail from Ruby

I try to connect t开发者_JAVA百科o mail Yahoo! account from Ruby using both net/imap and net/pop. But I randomly get error EOFile (from IMAP) or Connection Refused/Reset by peer (from POP). Has anybody tried to connect to Yahoo! Mail and had some experiences about it?


There's a bug in ruby's net/imap library that is exposed when connecting to Yahoo. The fix is straightforward and described here:

http://redmine.ruby-lang.org/issues/4509

Basically, edit imap.rb and change the inner loop of search_response method from:

        token = lookahead
        case token.symbol
        when T_CRLF
          break
        when T_SPACE
          shift_token
        end
        data.push(number)

to:

        token = lookahead
        case token.symbol
        when T_CRLF
          break
        when T_SPACE
          shift_token
        else
          data.push(number)
        end

then test with the following 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', ARGV[0], ARGV[1] )
conn.select("INBOX")
uids = conn.uid_search(['ALL'])
puts uids.join(',')
conn.logout
conn.disconnect
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜