Module: Ronin::Network::IMAP

Included in:
Net, Mixins::IMAP, Support
Defined in:
lib/ronin/network/imap.rb

Overview

Provides helper methods for communicating with IMAP services.

Constant Summary

DEFAULT_PORT =

Default IMAP port

143

Class Method Summary (collapse)

Instance Method Summary (collapse)

Class Method Details

+ (Integer) default_port

The default Ronin IMAP port.

Returns:

  • (Integer)

    The default Ronin IMAP port.



39
40
41
# File 'lib/ronin/network/imap.rb', line 39

def self.default_port
  @default_port ||= DEFAULT_PORT
end

+ (Object) default_port=(port)

Sets the default Ronin IMAP port.

Parameters:

  • port (Integer)

    The new default Ronin IMAP port.



51
52
53
# File 'lib/ronin/network/imap.rb', line 51

def self.default_port=(port)
  @default_port = port
end

Instance Method Details

- (Net::IMAP) imap_connect(host, options = {}) {|session| ... }

Creates a connection to the IMAP server.

Parameters:

  • host (String)

    The host to connect to.

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

Yields:

  • (session)

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

Yield Parameters:

  • session (Net::IMAP)

    The newly created IMAP session object.

Returns:

  • (Net::IMAP)

    The newly created IMAP session object.



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/ronin/network/imap.rb', line 92

def imap_connect(host,options={})
  host   = host.to_s
  port   = (options[:port] || IMAP.default_port)
  certs  = options[:certs]
  auth   = options[:auth]
  user   = options[:user]
  passwd = options[:password]

  if options[:ssl]
    ssl        = true
    ssl_certs  = options[:ssl][:certs]
    ssl_verify = SSL::VERIFY[options[:ssl][:verify]]
  else
    ssl        = false
    ssl_certs  = nil
    ssl_verify = false
  end

  session = Net::IMAP.new(host,port,ssl,ssl_certs,ssl_verify)

  if user
    if auth == :cram_md5
      session.authenticate('CRAM-MD5',user,passwd)
    else
      session.authenticate('LOGIN',user,passwd)
    end
  end

  yield session if block_given?
  return session
end

- (nil) imap_session(host, options = {}) {|session| ... }

Starts an IMAP session with the IMAP server.

Parameters:

  • host (String)

    The host to connect to.

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

    Additional options.

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.

Returns:

  • (nil)

See Also:

  • imap_connect


146
147
148
149
150
151
152
153
154
155
# File 'lib/ronin/network/imap.rb', line 146

def imap_session(host,options={})
  session = imap_connect(host,options)

  yield session if block_given?

  session.logout if options[:user]
  session.close
  session.disconnect
  return nil
end