require 'net/pop'

    pop = Net::POP3.new('pop3.126.com')
    pop.start('test', 'password')             # (1)
    if pop.mails.empty?
      puts 'No mail.'
    else
      i = 0
      # pop.each_mail do |m|   # or "pop.mails.each ..."   # (2)
      #   File.open("#{i}", 'w') do |f|
      #     f.write m.pop
      #   end
      #   m.delete
      #   i += 1
      # end
      pop.mails.each do |m|
          File.open("#{i}", 'w') do |f|
            f.write m.pop
          end        
      end
      puts "#{pop.mails.size} mails popped."
    end
    pop.finish