This page contains automated test results for code from O'Reilly's Ruby Cookbook. If this code looks interesting or useful, you might want to buy the whole book.

Reading Mail with POP3 (written by John Wells)
CodeExpectedActual
require 'net/pop'
conn = Net::POP3.new('mail.myhost.com')
conn.start('username', 'password')
require 'net/pop'
conn = Net::POP3.new('mail.myhost.com')
conn.start('username', 'password')
conn.mails.each do |msg|
   File.open(msg.uidl, 'w') { |f| f.write msg.pop }
   # msg.delete
end
conn.finish
conn = Net::POP3.new('mail.myhost.com')
conn.start('username', 'password')
ids = conn.mails.collect {|msg| msg.uidl if msg.pop.match('jabba')}
conn.finish
["UID2-1141260595", "UID3-1141260595"]
Error! (Exception?) Here's stdout:
Net::POPAuthenticationError: -ERR incorrect password or account name
	from /usr/lib/ruby/1.8/net/pop.rb:862:in `check_response_auth'
	from /usr/lib/ruby/1.8/net/pop.rb:764:in `auth'
	from /usr/lib/ruby/1.8/net/pop.rb:445:in `do_start'
	from /usr/lib/ruby/1.8/net/pop.rb:432:in `start'
	from (irb):3
Net::POPAuthenticationError: -ERR incorrect password or account name
	from /usr/lib/ruby/1.8/net/pop.rb:862:in `check_response_auth'
	from /usr/lib/ruby/1.8/net/pop.rb:764:in `auth'
	from /usr/lib/ruby/1.8/net/pop.rb:445:in `do_start'
	from /usr/lib/ruby/1.8/net/pop.rb:432:in `start'
	from (irb):6
IOError: POP session not opened yet
	from /usr/lib/ruby/1.8/net/pop.rb:475:in `command'
	from /usr/lib/ruby/1.8/net/pop.rb:488:in `n_mails'
	from /usr/lib/ruby/1.8/net/pop.rb:507:in `mails'
	from (irb):7
IOError: POP session not yet started
	from /usr/lib/ruby/1.8/net/pop.rb:459:in `finish'
	from (irb):11
Net::POPAuthenticationError: -ERR incorrect password or account name
	from /usr/lib/ruby/1.8/net/pop.rb:862:in `check_response_auth'
	from /usr/lib/ruby/1.8/net/pop.rb:764:in `auth'
	from /usr/lib/ruby/1.8/net/pop.rb:445:in `do_start'
	from /usr/lib/ruby/1.8/net/pop.rb:432:in `start'
	from (irb):13
IOError: POP session not opened yet
	from /usr/lib/ruby/1.8/net/pop.rb:475:in `command'
	from /usr/lib/ruby/1.8/net/pop.rb:488:in `n_mails'
	from /usr/lib/ruby/1.8/net/pop.rb:507:in `mails'
	from (irb):14
IOError: POP session not yet started
	from /usr/lib/ruby/1.8/net/pop.rb:459:in `finish'
	from (irb):15
conn2 = Net::POP3.new('mail.myhost.com')
conn.start('username', 'password')
conn.each_mail {|msg| puts msg.pop if msg.uidl=='UID3-1141260595'}
conn.finish
Return-Path: <jabba@huttfoundation.org>
X-Original-To: username@my.mailhost.com
Delivered-To: username@localhost
...
Error! (Exception?) Here's stdout:
Net::POPAuthenticationError: -ERR incorrect password or account name
	from /usr/lib/ruby/1.8/net/pop.rb:862:in `check_response_auth'
	from /usr/lib/ruby/1.8/net/pop.rb:764:in `auth'
	from /usr/lib/ruby/1.8/net/pop.rb:445:in `do_start'
	from /usr/lib/ruby/1.8/net/pop.rb:432:in `start'
	from (irb):17
IOError: POP session not opened yet
	from /usr/lib/ruby/1.8/net/pop.rb:475:in `command'
	from /usr/lib/ruby/1.8/net/pop.rb:488:in `n_mails'
	from /usr/lib/ruby/1.8/net/pop.rb:507:in `mails'
	from /usr/lib/ruby/1.8/net/pop.rb:528:in `each_mail'
	from (irb):18
IOError: POP session not yet started
	from /usr/lib/ruby/1.8/net/pop.rb:459:in `finish'
	from (irb):19