Class: MailProcessor::Pop3

Inherits:
Base
  • Object
show all
Defined in:
lib/mail_processor/pop3.rb

Instance Method Summary collapse

Methods inherited from Base

log, #log

Constructor Details

#initialize(options = {}, &block) ⇒ Pop3

Returns a new instance of Pop3.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/mail_processor/pop3.rb', line 10

def initialize options = {}, &block
  @attributes = {
    :address => "pop.gmail.com",
    :port => 110, # 995,
    :username => nil,
    :password => nil,
    # Must have ruby 1.9 to use this
    :use_ssl => false, # true 
  }
  merge_to_attributes(options)

  instance_eval &block if block_given?
  self
end

Instance Method Details

#address(v = nil) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/mail_processor/pop3.rb', line 26

def address v = nil
  if v
    @attributes[:address] = v
  else
    @attributes[:address]
  end
end

#password(v = nil) ⇒ Object



53
54
55
56
57
58
59
# File 'lib/mail_processor/pop3.rb', line 53

def password v = nil
  if v
    @attributes[:password] = v
  else
    @attributes[:password]
  end
end

#port(v = nil) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/mail_processor/pop3.rb', line 35

def port v = nil
  if v
    @attributes[:port] = v
  else
    @attributes[:port]
  end
end

#process(options = {}, &block) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/mail_processor/pop3.rb', line 76

def process(options = {}, &block)
  a = @attributes.merge(options)

  didWork = false
  Net::POP3.enable_ssl(OpenSSL::SSL::VERIFY_NONE) if a[:use_ssl]
  pop = Net::POP3.new(a[:address], a[:port])
  pop.start(a[:username], a[:password])
  if pop.mails.empty?
    log.info 'No mail.'
  else
    pop.each_mail do |m|
      yield m.pop
      m.delete
    end
    log.info "Processed #{pop.mails.size} mails."
    pop.finish
    didWork = true
  end

  didWork
end

#use_ssl(v = nil) ⇒ Object



67
68
69
70
71
72
73
# File 'lib/mail_processor/pop3.rb', line 67

def use_ssl v = nil
  if v
    @attributes[:use_ssl] = v
  else
    @attributes[:use_ssl]
  end
end

#use_ssl?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/mail_processor/pop3.rb', line 62

def use_ssl?
  @attributes[:use_ssl]
end

#username(v = nil) ⇒ Object



44
45
46
47
48
49
50
# File 'lib/mail_processor/pop3.rb', line 44

def username v = nil
  if v
    @attributes[:username] = v
  else
    @attributes[:username]
  end
end