lib/ronin/network/mixins/pop3.rb in ronin-support-0.3.0 vs lib/ronin/network/mixins/pop3.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/pop3' -require 'ronin/ui/output/helpers' -require 'ronin/mixin' -require 'parameters' - module Ronin module Network module Mixins # # Adds POP3 convenience methods and connection parameters to a class. @@ -35,32 +32,28 @@ # * `port` (`Integer`) - POP3 port. # * `pop3_user` (`String`) - POP3 user to login as. # * `pop3_password` (`String`) - POP3 password to login with. # module POP3 - include Mixin + include Mixin, Network::POP3 - mixin UI::Output::Helpers, Parameters + # POP3 host + parameter :host, :type => String, + :description => 'POP3 host' - mixin do - # POP3 host - parameter :host, :type => String, - :description => 'POP3 host' + # POP3 port + parameter :port, :type => Integer, + :description => 'POP3 port' - # POP3 port - parameter :port, :type => Integer, - :description => 'POP3 port' + # POP3 user + parameter :pop3_user, :type => String, + :description => 'POP3 user to login as' - # POP3 user - parameter :pop3_user, :type => String, - :description => 'POP3 user to login as' + # POP3 password + parameter :pop3_password, :type => String, + :description => 'POP3 password to login with' - # POP3 password - parameter :pop3_password, :type => String, - :description => 'POP3 password to login with' - end - protected # # Creates a connection to the POP3 server. The `host}, `port`, # `pop3_user` and `pop3_password` parameters will also be used @@ -91,21 +84,13 @@ # The newly created POP3 session. # # @api public # def pop3_connect(options={},&block) - options[:port] ||= self.port - options[:user] ||= self.pop3_user - options[:password] ||= self.pop3_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.pop3_connect(self.host,options,&block) + return super(self.host,pop3_merge_options(options),&block) end # # Starts a session with the POP3 server. The `host`, `port`, # `pop3_user` and `pop3_password` parameters will also be used @@ -122,19 +107,40 @@ # @see pop3_connect # # @api public # def pop3_session(options={}) - pop3_connect(options) do |sess| + super(options) do |sess| yield sess if block_given? - sess.finish - if @port - print_info "Disconnecting to #{self.host}:#{self.port}" - else - print_info "Disconnecting to #{self.host}" - end + print_info "Logging out ..." end + + print_info "Disconnected to #{host_port}" + end + + private + + # + # Merges the POP3 parameters into the options for {Network::POP3} + # methods. + # + # @param [Hash] options + # The original options. + # + # @return [Hash] + # The merged options. + # + # @since 0.4.0 + # + # @api private + # + def pop3_merge_options(options={}) + options[:port] ||= self.port + options[:user] ||= self.pop3_user + options[:password] ||= self.pop3_password + + return options end end end end end