Module: Ronin::Support::Network::IMAP::Mixin
- Defined in:
- lib/ronin/support/network/imap/mixin.rb
Overview
Provides helper methods for communicating with IMAP services.
Constant Summary collapse
- DEFAULT_PORT =
Default IMAP port
143
- AUTH_TYPES =
Authentication types.
{ login: 'LOGIN', cram_md5: 'CRAM_MD5' }
Instance Method Summary collapse
-
#imap_connect(host, user:, password:, port: DEFAULT_PORT, ssl: nil, auth: :login) {|imap| ... } ⇒ Net::IMAP?
Creates a connection to the IMAP server.
Instance Method Details
#imap_connect(host, user:, password:, port: DEFAULT_PORT, ssl: nil, auth: :login) {|imap| ... } ⇒ Net::IMAP?
Creates a connection to the IMAP server.
91 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 123 124 125 126 127 128 |
# File 'lib/ronin/support/network/imap/mixin.rb', line 91 def imap_connect(host, user: , password: , port: DEFAULT_PORT, ssl: nil, auth: :login) host = DNS::IDN.to_ascii(host) auth_type = AUTH_TYPES.fetch(auth) do raise(ArgumentError,"auth: must be either :login or :cram_md5") end case ssl when Hash ssl = true ssl_certs = ssl[:certs] ssl_verify = Network::SSL::VERIFY[ssl[:verify]] when TrueClass ssl = true ssl_certs = nil ssl_verify = nil else ssl = false ssl_certs = nil ssl_verify = false end imap = Net::IMAP.new(host,port,ssl,ssl_certs,ssl_verify) imap.authenticate(auth_type,user,passwd) if block_given? yield imap imap.logout imap.close imap.disconnect else return imap end end |