Class: Mailer::Mailbox

Inherits:
Object
  • Object
show all
Defined in:
lib/mailer/mailbox.rb

Constant Summary collapse

CONFIGS =
[:server, :port, :email, :password]

Instance Attribute Summary collapse

Instance Method Summary collapse

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_fileObject (readonly)

Returns the value of attribute log_file.



12
13
14
# File 'lib/mailer/mailbox.rb', line 12

def log_file
  @log_file
end

#loggerObject (readonly)

Returns the value of attribute logger.



12
13
14
# File 'lib/mailer/mailbox.rb', line 12

def logger
  @logger
end

Instance Method Details

#checkObject

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

Returns:

  • (Boolean)


54
55
56
57
58
# File 'lib/mailer/mailbox.rb', line 54

def empty?
  start_pop do |box|
    box.mails.empty?
  end
end

#openObject

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