lib/ronin/network/extensions/imap/net.rb in ronin-support-0.3.0 vs lib/ronin/network/extensions/imap/net.rb in ronin-support-0.4.0.rc1

- old
+ new

@@ -16,111 +16,9 @@ # You should have received a copy of the GNU Lesser General Public License # along with Ronin Support. If not, see <http://www.gnu.org/licenses/>. # require 'ronin/network/imap' -require 'ronin/network/ssl' -require 'net/imap' - module Net - # - # Creates a connection to the IMAP server. - # - # @param [String] host - # The host to connect to. - # - # @param [Hash] options - # Additional options. - # - # @option options [Integer] :port (IMAP.default_port) - # The port the IMAP server is running on. - # - # @option options [String] :certs - # The path to the file containing CA certs of the server. - # - # @option options [Symbol] :auth - # The type of authentication to perform when connecting to the server. - # May be either `:login` or `:cram_md5`. - # - # @option options [String] :user - # The user to authenticate as when connecting to the server. - # - # @option options [String] :password - # The password to authenticate with when connecting to the server. - # - # @yield [session] - # If a block is given, it will be passed the newly created IMAP - # session. - # - # @yieldparam [Net::IMAP] session - # The newly created IMAP session object. - # - # @return [Net::IMAP] - # The newly created IMAP session object. - # - # @api public - # - def Net.imap_connect(host,options={}) - host = host.to_s - port = (options[:port] || Ronin::Network::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 = Ronin::Network::SSL::VERIFY[options[:ssl][:verify]] - else - ssl = false - 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 - - # - # Starts an IMAP session with the IMAP server. - # - # @param [String] host - # The host to connect to. - # - # @param [Hash] options - # Additional options. - # - # @yield [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. - # - # @yieldparam [Net::IMAP] session - # The newly created IMAP session object. - # - # @return [nil] - # - # @see Net.imap_connect - # - # @api public - # - def Net.imap_session(host,options={}) - session = Net.imap_connect(host,options) - - yield session if block_given? - - session.logout if options[:user] - session.close - session.disconnect - return nil - end + extend Ronin::Network::IMAP end