Class: Net::POP3Command

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

Overview

:nodoc: internal use only

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (POP3Command) initialize(sock)

A new instance of POP3Command



869
870
871
872
873
874
# File 'lib/net/pop.rb', line 869

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

Instance Attribute Details

- (Object) socket (readonly)

Returns the value of attribute socket



876
877
878
# File 'lib/net/pop.rb', line 876

def socket
  @socket
end

Instance Method Details

- (Object) apop(account, password)



889
890
891
892
893
894
895
896
897
# File 'lib/net/pop.rb', line 889

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

- (Object) auth(account, password)



882
883
884
885
886
887
# File 'lib/net/pop.rb', line 882

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

- (Object) dele(num)



937
938
939
# File 'lib/net/pop.rb', line 937

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

- (Object) inspect



878
879
880
# File 'lib/net/pop.rb', line 878

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

- (Object) list



899
900
901
902
903
904
905
906
907
908
909
910
# File 'lib/net/pop.rb', line 899

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

- (Object) quit



958
959
960
# File 'lib/net/pop.rb', line 958

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

- (Object) retr(num, &block)



930
931
932
933
934
935
# File 'lib/net/pop.rb', line 930

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

- (Object) rset



919
920
921
# File 'lib/net/pop.rb', line 919

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

- (Object) stat



912
913
914
915
916
917
# File 'lib/net/pop.rb', line 912

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

- (Object) top(num, lines = 0, &block)



923
924
925
926
927
928
# File 'lib/net/pop.rb', line 923

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

- (Object) uidl(num = nil)



941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
# File 'lib/net/pop.rb', line 941

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