Class: Mailer::Mailbox
- Inherits:
-
Object
- Object
- Mailer::Mailbox
- Defined in:
- lib/mailer/mailbox.rb
Constant Summary collapse
- CONFIGS =
[:server, :port, :email, :password]
Instance Attribute Summary collapse
-
#log_file ⇒ Object
readonly
Returns the value of attribute log_file.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
Instance Method Summary collapse
-
#check ⇒ Object
opens the mail box and returns the mails as a collection.
- #empty! ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(configs = {}) ⇒ Mailbox
constructor
A new instance of Mailbox.
-
#open ⇒ Object
opens the mailbox returning the pop3 mailbox object.
Constructor Details
#initialize(configs = {}) ⇒ Mailbox
Returns a new instance of Mailbox.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/mailer/mailbox.rb', line 14 def initialize(configs={}) @logger = Log4r::Logger.new("[mailer]") @logger.add(Log4r::StdoutOutputter.new('console')) configs.each do |config, value| instance_variable_set("@#{config.to_s}", value) end if @log_file begin @logger.add(Log4r::FileOutputter.new('fileOutputter', { :filename => @log_file, :trunc => false, :formatter => Log4r::PatternFormatter.new(:pattern => "[%l] %d :: %m") })) rescue Exception => err end end Net::POP3.enable_ssl(OpenSSL::SSL::VERIFY_NONE) configs end |
Instance Attribute Details
#log_file ⇒ Object (readonly)
Returns the value of attribute log_file.
12 13 14 |
# File 'lib/mailer/mailbox.rb', line 12 def log_file @log_file end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
12 13 14 |
# File 'lib/mailer/mailbox.rb', line 12 def logger @logger end |
Instance Method Details
#check ⇒ Object
opens the mail box and returns the mails as a collection
46 47 48 49 50 51 52 |
# File 'lib/mailer/mailbox.rb', line 46 def check start_pop do |box| if block_given? yield box.mails end end end |
#empty! ⇒ Object
60 61 62 63 64 |
# File 'lib/mailer/mailbox.rb', line 60 def empty! start_pop do |box| box.mails.each {|mail| mail.delete!} end end |
#empty? ⇒ Boolean
54 55 56 57 58 |
# File 'lib/mailer/mailbox.rb', line 54 def empty? start_pop do |box| box.mails.empty? end end |
#open ⇒ Object
opens the mailbox returning the pop3 mailbox object
39 40 41 42 43 |
# File 'lib/mailer/mailbox.rb', line 39 def open start_pop do |box| yield box end end |