Class: RbEAI::GetEmailLogic
- Inherits:
-
Object
- Object
- RbEAI::GetEmailLogic
- Defined in:
- lib/rbeai/GetLogic.rb
Overview
<protocol def=“email”>
<location address="" port=""/>
<account name="" pwd=""/>
<pattern>out.xml</pattern>
</protocol>
Instance Method Summary collapse
- #getFiles ⇒ Object
-
#initialize(protNode, task) ⇒ GetEmailLogic
constructor
A new instance of GetEmailLogic.
Constructor Details
#initialize(protNode, task) ⇒ GetEmailLogic
Returns a new instance of GetEmailLogic.
100 101 102 103 104 105 106 107 108 109 |
# File 'lib/rbeai/GetLogic.rb', line 100 def initialize(protNode, task) @task = task location = XPath.first(protNode, "./location") account = XPath.first(protNode, "./account") @address = location.attributes["address"] @port = location.attributes["port"] @name = account.attributes["name"] @pwd = account.attributes["pwd"] @pattern = task.pattern end |
Instance Method Details
#getFiles ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/rbeai/GetLogic.rb', line 111 def getFiles() files = [] pop = Net::POP3.new(@address) pop.start(@name, @pwd) if pop.mails.empty? puts 'No mail.' else i = 1 pop.each_mail do |m| str = m.pop i = i + 1 begin email = RMail::Parser.read(str) aux = true _parseMail(email, @pattern, "mail_#{i}").each do |file| _persistAndDelete(m, str, "mail_#{i}.txt") if aux aux = false files << file end rescue Exception puts $! end end puts "#{pop.mails.size} mails popped." end pop.finish return files end |