module Ronin::Support::Network::POP3::Mixin

Provides helper methods for communicating with POP3 services.

Constants

DEFAULT_PORT

Default POP3 port

Public Instance Methods

pop3_connect(host, port: DEFAULT_PORT, ssl: nil, user: , password: ) { |pop3| ... } click to toggle source

Creates a connection to the POP3 server.

@param [String] host

The host to connect to.

@param [Integer] port

The port the POP3 server is running on.

@param [Boolean, Hash] ssl

Additional SSL options.

@option ssl [Boolean] :verify

Specifies that the SSL certificate should be verified.

@option ssl [String] :certs

The path to the file containing CA certs of the server.

@param [String] user

The user to authenticate with when connecting to the POP3 server.

@param [String] password

The password to authenticate with when connecting to the POP3
server.

@yield [pop3]

If a block is given, it will be passed the newly created POP3
session. Once the block returns the POP3 session will be closed.

@yieldparam [Net::POP3] pop3

The newly created POP3 session.

@return [Net::POP3, nil]

The newly created POP3 session. If a block is given, `nil` will be
returned.

@api public

# File lib/ronin/support/network/pop3/mixin.rb, line 77
def pop3_connect(host, port: DEFAULT_PORT,
                       ssl:  nil,
                       user: ,
                       password: )
  host = DNS::IDN.to_ascii(host)

  case ssl
  when Hash
    ssl        = true
    ssl_certs  = ssl[:certs]
    ssl_verify = SSL::VERIFY[ssl[:verify]]
  when TrueClass
    ssl        = true
    ssl_certs  = nil
    ssl_verify = nil
  else
    ssl        = false
    ssl_certs  = nil
    ssl_verify = false
  end

  pop3 = Net::POP3.new(host,port)
  pop3.enable_ssl(ssl_verify,ssl_certs) if ssl
  pop3.start(user,password)

  if block_given?
    begin
      yield pop3
    ensure
      pop3.finish
    end
  else
    return pop3
  end
end