Socket emergency

I am very sorry as this is a typo again. Please see following code:

irb(main):001:0> require ‘socket’
=> true
irb(main):002:0> t= TCPSocket.new(‘127.0.0.1’, 110)
=> #TCPSocket:0x2aa0908
irb(main):003:0> t.gets
=> “+OK POP3 Server Ready\r\n”
irb(main):004:0> t.send(“USER xrfang@172.18.2.1\n”, 0)
=> 23
irb(main):005:0> t.gets
=> “+OK\r\n”
irb(main):006:0> t.send(“PASS xrfang\n”, 0)
=> 12
irb(main):007:0> t.gets
=> “+OK\r\n”
irb(main):008:0> t.send(“RETR 4\n”, 0)
=> 7
irb(main):009:0> t.gets
=> “+OK\r\n”
irb(main):010:0> t.gets

It hangs here.

Sincerely,
Shannon

···

From: ts decoux@moulon.inra.fr
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: Wed, 20 Aug 2003 22:39:32 +0900

irb(main):026:0> t.send(“RETR 1”, 0)
^^^^^^

You have forgotten \n

=> 6

Guy Decoux


Stay in touch with absent friends - get MSN Messenger
http://www.msn.co.uk/messenger

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