Imap :: new上的参数太多

时间:2012-02-15 12:32:42

标签: ruby imap gmail-imap

我正在尝试以下操作,但Imap::new抱怨参数太多

require 'rubygems'
require 'highline/import'
require 'net/imap'

puts "username"
username = gets
password = ask("Enter password: ") { |q| q.echo = false }

imap = Net::IMAP.new('imap.gmail.com', {:port => '993', :ssl => true})

puts "connecting to imap server"

imap.login(username, password)
imap.select('INBOX')
imap.select('INBOX')
imap.search(["NOT", "DELETED"]).each do |message_id|
    envelope = imap.fetch(message_id, "ENVELOPE")[0].attr["ENVELOPE"]
    puts "#{envelope.from[0].name}: \t#{envelope.subject}"
    i += 1
    Process.exit if i>10
end

错误:

/Users/username/.rbenv/versions/1.9.2-p290/lib/ruby/1.9.1/net/imap.rb:1101:in `get_tagged_response': Too many arguments provided ci7if1523987wib.93 (Net::IMAP::BadResponseError)
    from /Users/username/.rbenv/versions/1.9.2-p290/lib/ruby/1.9.1/net/imap.rb:1153:in `block in send_command'
    from /Users/username/.rbenv/versions/1.9.2-p290/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'
    from /Users/username/.rbenv/versions/1.9.2-p290/lib/ruby/1.9.1/net/imap.rb:1135:in `send_command'
    from /Users/username/.rbenv/versions/1.9.2-p290/lib/ruby/1.9.1/net/imap.rb:419:in `login'
    from pull.rb:13:in main

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

这应该可以解决问题

imap = Net::IMAP.new('host', 993, true) // host, port, ssl
imap.login('IMAP_USERNAME', 'IMAP_PASSWORD')
imap.select('INBOX')

顺便说一句。你选择了两次INBOX:)