Class: Net::POP3Command

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

Overview

:nodoc: internal use only

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sock) ⇒ POP3Command

Returns a new instance of POP3Command.



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

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

Instance Attribute Details

#socketObject (readonly)

Returns the value of attribute socket



897
898
899
# File 'lib/net/pop.rb', line 897

def socket
  @socket
end

Instance Method Details

#apop(account, password) ⇒ Object



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

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



903
904
905
906
907
908
# File 'lib/net/pop.rb', line 903

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

#dele(num) ⇒ Object



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

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

#inspectObject



899
900
901
# File 'lib/net/pop.rb', line 899

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

#listObject



920
921
922
923
924
925
926
927
928
929
930
931
# File 'lib/net/pop.rb', line 920

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



979
980
981
# File 'lib/net/pop.rb', line 979

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

#retr(num, &block) ⇒ Object



951
952
953
954
955
956
# File 'lib/net/pop.rb', line 951

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

#rsetObject



940
941
942
# File 'lib/net/pop.rb', line 940

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

#statObject



933
934
935
936
937
938
# File 'lib/net/pop.rb', line 933

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



944
945
946
947
948
949
# File 'lib/net/pop.rb', line 944

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

#uidl(num = nil) ⇒ Object



962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
# File 'lib/net/pop.rb', line 962

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