123456789_123456789_123456789_123456789_123456789_

Class: Net::POP3Command

Do not use. This class is for internal use only.
Relationships & Source Files
Inherits: Object
Defined in: lib/net/pop.rb

Overview

internal use only

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(sock) ⇒ POP3Command

[ GitHub ]

  
# File 'lib/net/pop.rb', line 891

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

Instance Attribute Details

#socket (readonly)

[ GitHub ]

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

attr_reader :socket

Instance Method Details

#apop(account, password)

[ GitHub ]

  
# File 'lib/net/pop.rb', line 911

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)

[ GitHub ]

  
# File 'lib/net/pop.rb', line 904

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

#check_response(res) (private)

Raises:

[ GitHub ]

  
# File 'lib/net/pop.rb', line 1000

def check_response(res)
  raise POPError, res unless /\A\+OK/i =~ res
  res
end

#check_response_auth(res) (private)

[ GitHub ]

  
# File 'lib/net/pop.rb', line 1005

def check_response_auth(res)
  raise POPAuthenticationError, res unless /\A\+OK/i =~ res
  res
end

#critical (private)

[ GitHub ]

  
# File 'lib/net/pop.rb', line 1010

def critical
  return '+OK dummy ok response' if @error_occurred
  begin
    return yield()
  rescue Exception
    @error_occurred = true
    raise
  end
end

#dele(num)

[ GitHub ]

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

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

#get_response(fmt, *fargs) (private)

[ GitHub ]

  
# File 'lib/net/pop.rb', line 991

def get_response(fmt, *fargs)
  @socket.writeline sprintf(fmt, *fargs)
  recv_response()
end

#getok(fmt, *fargs) (private)

[ GitHub ]

  
# File 'lib/net/pop.rb', line 986

def getok(fmt, *fargs)
  @socket.writeline sprintf(fmt, *fargs)
  check_response(recv_response())
end

#inspect

[ GitHub ]

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

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

#list

[ GitHub ]

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

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

#quit

[ GitHub ]

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

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

#recv_response (private)

[ GitHub ]

  
# File 'lib/net/pop.rb', line 996

def recv_response
  @socket.readline
end

#retr(num, &block)

[ GitHub ]

  
# File 'lib/net/pop.rb', line 952

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

#rset

[ GitHub ]

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

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

#stat

[ GitHub ]

  
# File 'lib/net/pop.rb', line 934

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)

[ GitHub ]

  
# File 'lib/net/pop.rb', line 945

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

#uidl(num = nil)

[ GitHub ]

  
# File 'lib/net/pop.rb', line 963

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