c:/ruby/lib/ruby/1.8/net/protocol.rb:259:in do_write': undefined methodwrite’
for nil (NoMethodError)
from c:/ruby/lib/ruby/1.8/net/protocol.rb:242:in writeline' from c:/ruby/lib/ruby/1.8/net/protocol.rb:241:inwriting’
from c:/ruby/lib/ruby/1.8/net/protocol.rb:243:in writeline' from c:/ruby/lib/ruby/1.8/net/pop.rb:785:ingetok’
from c:/ruby/lib/ruby/1.8/net/pop.rb:745:in top' from c:/ruby/lib/ruby/1.8/net/pop.rb:744:incritical’
from c:/ruby/lib/ruby/1.8/net/pop.rb:747:in top' from c:/ruby/lib/ruby/1.8/net/pop.rb:657:intop’
from c:/ruby/lib/ruby/1.8/net/pop.rb:661:in header' from trypop.rb:10 from trypop.rb:10:ineach’
from trypop.rb:10
I’ve tried moving the “p mail.header” up as a block to the mailbox.start
call, thinking that maybe the mailbox was closed by the time I tried to
print the headers out, but it made no difference. Can anyone point me to
something obvious?
host = ‘pop.west.cox.net’
port = 110
user = ‘dhtapp’
pass = ‘Your Password’
pop = Net::POP3.new(host, port)
pop.start(user, pass) {
puts “# of mails: #{pop.mails.size}”
pop.each_mail do |mail|
puts mail.header
end
}
I’ve tried moving the “p mail.header” up as a block to the mailbox.start
call, thinking that maybe the mailbox was closed by the time I tried to
print the headers out, but it made no difference. Can anyone point me to
Yes, your first error is caused by calling I/O method after closing
POP3 connection. I can’t detect the reason of your second error.
I’ve tried moving the “p mail.header” up as a block to the mailbox.start
call, thinking that maybe the mailbox was closed by the time I tried to
print the headers out,
Certaily, this is correct. Net::POPMail objects download
the contents of the mail item on demand, using a reference
to the Net::POP3 object that they’re drawn from, so fetching
the headers or body will only work while the POP3 object is
still open (in your example, inside the mailbox.start
block). However…
but it made no difference. Can anyone point me to
something obvious?
I can’t see anything else obviously wrong with your code.
It should look something like this:
As to why I got an error even when I moved the print into the block, I’ll
chalk that up to a typo on my part, plus hastily mis-reporting to the group.
(It must’ve been a different error, which I neglected in my fatigue to
notice. I should’ve double-checked it before posting on it.)