Connecting to Yahoo! mail from Ruby

做~自己de王妃 提交于 2019-12-11 07:39:42

问题


I try to connect to 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?


回答1:


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


来源:https://stackoverflow.com/questions/7254229/connecting-to-yahoo-mail-from-ruby

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!