From: Shannon Fang Date: 2003-08-21T00:12:53+09:00 Subject: Re: socket emergency Hi Guy and all Rubyists, Thank you very much for all the help. For me, it is not very convenient to use net/pop in this client application. However I also tried that one. The result is failure. Please refer to the following code: irb(main):001:0> require 'net/pop' => true irb(main):002:0> Net::POP3.start('127.0.0.1', 110, 'xrfang@172.18.2.1','xrfang') { |pop| irb(main):003:1* if pop.mails.empty? irb(main):004:2> puts 'no mail.' irb(main):005:2> else irb(main):006:2* i=0 irb(main):007:2> pop.each_mail do |m| irb(main):008:3* puts m.pop irb(main):009:3> m.delete irb(main):010:3> i += 1 irb(main):011:3> end irb(main):012:2> puts "#{pop.mails.size} mails popped." irb(main):013:2> end irb(main):014:1> } TimeoutError: socket read timeout (60 sec) from c:/ruby/lib/ruby/1.6/net/protocol.rb:618:in `on_read_timeout' from c:/ruby/lib/ruby/1.6/net/protocol.rb:612:in `rbuf_fill' from c:/ruby/lib/ruby/1.6/net/protocol.rb:551:in `readuntil' from c:/ruby/lib/ruby/1.6/net/protocol.rb:577:in `read_pendstr' from c:/ruby/lib/ruby/1.6/net/pop.rb:562:in `retr' from c:/ruby/lib/ruby/1.6/net/pop.rb:561:in `atomic' from c:/ruby/lib/ruby/1.6/net/pop.rb:561:in `retr' from c:/ruby/lib/ruby/1.6/net/pop.rb:481:in `pop' from (irb):8 from (irb):7:in `each' from c:/ruby/lib/ruby/1.6/net/pop.rb:421:in `each_mail' from (irb):7 from (irb):2:in `start' from c:/ruby/lib/ruby/1.6/net/protocol.rb:71:in `start' from c:/ruby/lib/ruby/1.6/net/protocol.rb:71:in `start' from (irb):2 irb(main):015:0> I don't know what on earth is it doing :-(((( thanks! Shannon >From: ts >Reply-To: ruby-talk@ruby-lang.org >To: ruby-talk@ruby-lang.org (ruby-talk ML) >CC: ruby-talk@ruby-lang.org >Subject: Re: socket emergency >Date: Thu, 21 Aug 2003 00:03:45 +0900 > > >>>>> "S" == Shannon Fang writes: > >S> It hangs here. > > Have you tried with the module 'net/pop' to see if it do the same ? > >=== Enshort Code > >The example above is very verbose. You can enshort code by using >some utility methods. At first, block form of Net::POP3.start can >alternates POP3.new, POP3#start and POP3#finish. > > require 'net/pop' > > Net::POP3.start('pop.example.com', 110, > 'YourAccount', 'YourPassword') {|pop| > if pop.mails.empty? > puts 'no mail.' > else > i = 0 > pop.each_mail do |m| # or "pop.mails.each ..." > File.open("inbox/#{i}", 'w') {|f| > f.write m.pop > } > m.delete > i += 1 > end > puts "#{pop.mails.size} mails popped." > end > } > > > >Guy Decoux > _________________________________________________________________ It's fast, it's easy and it's free. Get MSN Messenger today! http://www.msn.co.uk/messenger