Class: Net::POP3Command

Inherits:
Object
  • Object
show all
Defined in:
lib/net/pop.rb

Overview

:nodoc: internal use only

Instance Method Summary collapse

Constructor Details

#initialize(sock) ⇒ POP3Command

Returns a new instance of POP3Command.



749
750
751
752
753
754
# File 'lib/net/pop.rb', line 749

def initialize( sock )
  @socket = sock
  @error_occured = false
  res = check_response(critical { recv_response() })
  @apop_stamp = res.slice(/<.+>/)
end

Instance Method Details

#apop(account, password) ⇒ Object



767
768
769
770
771
772
773
774
775
# File 'lib/net/pop.rb', line 767

def apop( , password )
  raise POPAuthenticationError, 'not APOP server; cannot login' \
                                                  unless @apop_stamp
  check_response_auth(critical {
    get_response('APOP %s %s',
                 ,
                 Digest::MD5.hexdigest(@apop_stamp + password))
  })
end

#auth(account, password) ⇒ Object



760
761
762
763
764
765
# File 'lib/net/pop.rb', line 760

def auth( , password )
  check_response_auth(critical {
    check_response_auth(get_response('USER %s', ))
    get_response('PASS %s', password)
  })
end

#dele(num) ⇒ Object



815
816
817
# File 'lib/net/pop.rb', line 815

def dele( num )
  check_response(critical { get_response('DELE %d', num) })
end

#inspectObject



756
757
758
# File 'lib/net/pop.rb', line 756

def inspect
  "#<#{self.class} socket=#{@socket}>"
end

#listObject



777
778
779
780
781
782
783
784
785
786
787
788
# File 'lib/net/pop.rb', line 777

def list
  critical {
    getok 'LIST'
    list = []
    @socket.each_list_item do |line|
      m = /\A(\d+)[ \t]+(\d+)/.match(line) or
              raise POPBadResponse, "bad response: #{line}"
      list.push  [m[1].to_i, m[2].to_i]
    end
    return list
  }
end

#quitObject



836
837
838
# File 'lib/net/pop.rb', line 836

def quit
  check_response(critical { get_response('QUIT') })
end

#retr(num, &block) ⇒ Object



808
809
810
811
812
813
# File 'lib/net/pop.rb', line 808

def retr( num, &block )
  critical {
    getok('RETR %d', num)
    @socket.each_message_chunk(&block)
  }
end

#rsetObject



797
798
799
# File 'lib/net/pop.rb', line 797

def rset
  check_response(critical { get_response 'RSET' })
end

#statObject



790
791
792
793
794
795
# File 'lib/net/pop.rb', line 790

def stat
  res = check_response(critical { get_response('STAT') })
  m = /\A\+OK\s+(\d+)\s+(\d+)/.match(res) or
          raise POPBadResponse, "wrong response format: #{res}"
  [m[1].to_i, m[2].to_i]
end

#top(num, lines = 0, &block) ⇒ Object



801
802
803
804
805
806
# File 'lib/net/pop.rb', line 801

def top( num, lines = 0, &block )
  critical {
    getok('TOP %d %d', num, lines)
    @socket.each_message_chunk(&block)
  }
end

#uidl(num = nil) ⇒ Object



819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
# File 'lib/net/pop.rb', line 819

def uidl( num = nil )
  if num
    res = check_response(critical { get_response('UIDL %d', num) })
    return res.split(/ /)[1]
  else
    critical {
      getok('UIDL')
      table = {}
      @socket.each_list_item do |line|
        num, uid = line.split
        table[num.to_i] = uid
      end
      return table
    }
  end
end