Module: Ronin::Support::Network::POP3::Mixin

Defined in:
lib/ronin/support/network/pop3/mixin.rb

Overview

Provides helper methods for communicating with POP3 services.

Constant Summary collapse

DEFAULT_PORT =

Default POP3 port

110

Instance Method Summary collapse

Instance Method Details

#pop3_connect(host, port: DEFAULT_PORT, ssl: nil, user:, password:) {|pop3| ... } ⇒ Net::POP3?

Creates a connection to the POP3 server.

Parameters:

  • host (String)

    The host to connect to.

  • port (Integer) (defaults to: DEFAULT_PORT)

    The port the POP3 server is running on.

  • ssl (Boolean, Hash) (defaults to: nil)

    Additional SSL options.

  • user (String)

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

  • password (String)

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

Options Hash (ssl:):

  • :verify (Boolean)

    Specifies that the SSL certificate should be verified.

  • :certs (String)

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

Yields:

  • (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.

Yield Parameters:

  • pop3 (Net::POP3)

    The newly created POP3 session.

Returns:

  • (Net::POP3, nil)

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



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# 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