lib/ronin/network/mixins/imap.rb in ronin-support-0.3.0 vs lib/ronin/network/mixins/imap.rb in ronin-support-0.4.0.rc1
- old
+ new
@@ -15,16 +15,13 @@
#
# 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/mixins/mixin'
require 'ronin/network/imap'
-require 'ronin/ui/output/helpers'
-require 'ronin/mixin'
-require 'parameters'
-
module Ronin
module Network
module Mixins
#
# Adds IMAP convenience methods and connection parameters to a class.
@@ -36,36 +33,32 @@
# * `imap_auth` (`String`) - IMAP authentication method.
# * `imap_user` (`String`) - IMAP user to login as.
# * `imap_password` (`String`) - IMAP password to login with.
#
module IMAP
- include Mixin
+ include Mixin, Network::IMAP
- mixin UI::Output::Helpers, Parameters
+ # IMAP host
+ parameter :host, :type => String,
+ :description => 'IMAP host'
- mixin do
- # IMAP host
- parameter :host, :type => String,
- :description => 'IMAP host'
+ # IMAP port
+ parameter :port, :type => Integer,
+ :description => 'IMAP port'
- # IMAP port
- parameter :port, :type => Integer,
- :description => 'IMAP port'
+ # IMAP auth
+ parameter :imap_auth, :type => String,
+ :description => 'IMAP authentication method'
- # IMAP auth
- parameter :imap_auth, :type => String,
- :description => 'IMAP authentication method'
+ # IMAP user to login as
+ parameter :imap_user, :type => String,
+ :description => 'IMAP user to login as'
- # IMAP user to login as
- parameter :imap_user, :type => String,
- :description => 'IMAP user to login as'
+ # IMAP password to login with
+ parameter :imap_password, :type => String,
+ :description => 'IMAP password to login with'
- # IMAP password to login with
- parameter :imap_password, :type => String,
- :description => 'IMAP password to login with'
- end
-
protected
#
# Creates a connection to the IMAP server. The `host`, `port`,
# `imap_auth`, `imap_user` and `imap_password` parameters
@@ -96,22 +89,13 @@
# server.
#
# @api public
#
def imap_connect(options={},&block)
- options[:port] ||= self.port
- options[:auth] ||= self.imap_auth
- options[:user] ||= self.imap_user
- options[:password] ||= self.imap_password
+ print_info "Connecting to #{host_port} ..."
- 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)
+ return super(self.host,imap_merge_options(options),&block)
end
#
# Starts a session with the IMAP server. The `host`, `port`,
# `imap_auth`, `imap_user` and `imap_password` parameters
@@ -128,23 +112,42 @@
# @see imap_connect
#
# @api public
#
def imap_session(options={})
- imap_connect(options) do |sess|
+ super(imap_merge_options(options)) do |sess|
yield sess if block_given?
print_info "Logging out ..."
+ end
- sess.close
- sess.logout
+ print_info "Disconnected from #{host_port}"
+ return il
+ end
- if self.port
- print_info "Disconnecting from #{self.host}:#{self.port}"
- else
- print_info "Disconnecting from #{self.host}"
- end
- end
+ private
+
+ #
+ # Merges the IMAP parameters into the options for {Network::IMAP}
+ # methods.
+ #
+ # @param [Hash] options
+ # The original options.
+ #
+ # @return [Hash]
+ # The merged options.
+ #
+ # @since 0.4.0
+ #
+ # @api private
+ #
+ def imap_merge_options(options={})
+ options[:port] ||= self.port
+ options[:auth] ||= self.imap_auth
+ options[:user] ||= self.imap_user
+ options[:password] ||= self.imap_password
+
+ return options
end
end
end
end
end