Module: Ronin::Network::Mixins::IMAP

Includes:
Mixin
Defined in:
lib/ronin/network/mixins/imap.rb

Overview

Adds IMAP convenience methods and connection parameters to a class.

Defines the following parameters:

  • host (String) - IMAP host.
  • port (Integer) - IMAP port.
  • imap_auth (String) - IMAP authentication method.
  • imap_user (String) - IMAP user to login as.
  • imap_password (String) - IMAP password to login with.

Instance Method Summary collapse

Methods included from Mixin

included

Instance Method Details

#imap_connect(options = {}, &block) ⇒ Object (protected)

Creates a connection to the IMAP server. The host, port, imap_auth, imap_user and imap_password parameters will also be used to make the connection.

Parameters:

  • options (Hash) (defaults to: {})

    Additional options.

Options Hash (options):

  • :port (Integer) — default: IMAP.default_port

    The port the IMAP server is running on.

  • :certs (String)

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

  • :auth (Symbol)

    The type of authentication to perform when connecting to the server. May be either :login or :cram_md5.

  • :user (String)

    The user to authenticate as when connecting to the server.

  • :password (String)

    The password to authenticate with when connecting to the server.

  • Indicates (Boolean)

    wether or not to use SSL when connecting to the server.



100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/ronin/network/mixins/imap.rb', line 100

def imap_connect(options={},&block)
  options[:port] ||= self.port
  options[:auth] ||= self.imap_auth
  options[:user] ||= self.imap_user
  options[:password] ||= self.imap_password

  if self.port
    print_info "Connecting to #{self.host}:#{self.port} ..."
  else
    print_info "Connecting to #{self.host} ..."
  end

  return ::Net.imap_connect(self.host,options,&block)
end

#imap_session(options = {}) {|session| ... } ⇒ Object (protected)

Starts a session with the IMAP server. The host, port, imap_auth, imap_user and imap_password parameters will also be used to make the connection.

Yields:

  • (session)

    If a block is given, it will be passed the newly created IMAP session. After the block has returned, the session will be closed.

Yield Parameters:

  • session (Net::IMAP)

    The newly created IMAP session object.

See Also:



132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/ronin/network/mixins/imap.rb', line 132

def imap_session(options={})
  imap_connect(options) do |sess|
    yield sess if block_given?

    print_info "Logging out ..."

    sess.close
    sess.logout

    if self.port
      print_info "Disconnecting from #{self.host}:#{self.port}"
    else
      print_info "Disconnecting from #{self.host}"
    end
  end
end