lib/ronin/network/mixins/esmtp.rb in ronin-support-0.3.0 vs lib/ronin/network/mixins/esmtp.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/esmtp' -require 'ronin/ui/output/helpers' -require 'ronin/mixin' -require 'parameters' - module Ronin module Network module Mixins # # Adds ESMTP convenience methods and connection parameters to a class. @@ -36,48 +33,35 @@ # * `esmtp_login` (`String`) - ESMTP authentication method to use. # * `esmtp_user` (`String`) - ESMTP user to login as. # * `esmtp_password` (`String`) - ESMTP password to login with. # module ESMTP - include Mixin + include Mixin, Network::ESMTP - mixin UI::Output::Helpers, Parameters + # ESMTP host + parameter :host, :type => String, + :description => 'ESMTP host' - mixin do - # ESMTP host - parameter :host, :type => String, - :description => 'ESMTP host' + # ESMTP port + parameter :port, :type => Integer, + :description => 'ESMTP port' - # ESMTP port - parameter :port, :type => Integer, - :description => 'ESMTP port' + # ESMTP authentication method to use + parameter :esmtp_login, :type => String, + :description => 'ESMTP authentication method to use' - # ESMTP authentication method to use - parameter :esmtp_login, :type => String, - :description => 'ESMTP authentication method to use' + # ESMTP user to login as + parameter :esmtp_user, :type => String, + :description => 'ESMTP user to login as' - # ESMTP user to login as - parameter :esmtp_user, :type => String, - :description => 'ESMTP user to login as' + # ESMTP password to login with + parameter :esmtp_password, :type => String, + :description => 'ESMTP password to login with' - # ESMTP password to login with - parameter :esmtp_password, :type => String, - :description => 'ESMTP password to login with' - end - protected # - # @see Ronin::Network::SMTP.message. - # - # @api public - # - def esmtp_message(options={},&block) - Network::SMTP.message(options,&block) - end - - # # Creates a connection to the ESMTP server. The `host`, `port`, # `esmtp_login`, `esmtp_user` and `esmtp_password` parameters # will also be used to connect to the ESMTP server. # # @param [Hash] options @@ -110,22 +94,13 @@ # The ESMTP enabled session. # # @api public # def esmtp_connect(options={},&block) - options[:port] ||= self.port - options[:login] ||= self.esmtp_login - options[:user] ||= self.esmtp_user - options[:password] ||= self.esmtp_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.esmtp_connect(self.host,options,&block) + return super(self.host,esmtp_merge_options(options),&block) end # # Starts a session with the ESMTP server. The `host`, `port`, # `esmtp_login`, `esmtp_user` and `esmtp_password` parameters @@ -145,20 +120,42 @@ # @see esmtp_connect # # @api public # def esmtp_session(options={}) - esmtp_connect(options) do |sess| + super(esmtp_merge_options(options)) do |sess| yield sess if block_given? - sess.close - - if self.port - print_info "Disconnecting from #{self.host}:#{self.port}" - else - print_info "Disconnecting from #{self.host}" - end + print_info "Logging out ..." end + + print_info "Disconnected from #{host_port}" + return nil + end + + private + + # + # Merges the ESMTP parameters into the options for {Network::ESMTP} + # methods. + # + # @param [Hash] options + # The original options. + # + # @return [Hash] + # The merged options. + # + # @since 0.4.0 + # + # @api private + # + def esmtp_merge_options(options={}) + options[:port] ||= self.port + options[:login] ||= self.esmtp_login + options[:user] ||= self.esmtp_user + options[:password] ||= self.esmtp_password + + return options end end end end end