Method: Client#process_email
- Defined in:
- lib/client.rb
#process_email(mail, uid) ⇒ Object
Process each email downloaded from imap-server and creates meta file that will be sent over to the navi-ai service. Meta will content information like: [‘from’, ‘to’, ‘cc’, …, ‘body_url’]. This information is then used by navi-ai to parse the body content.
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/client.rb', line 122 def process_email(mail, uid) = Hash.new custom_uid = (Time.now.to_f * 1000).to_s + "_" + mail.__id__.to_s invalid_to_email = mail.to.nil? || !mail.to.is_a?(Array) invalid_cc_email = mail.cc.nil? || !mail.cc.is_a?(Array) unless mail.from.nil? if defined? mail.from.first ["from"] = mail.from.first else ["from"] = mail.from end end ["to"] = invalid_to_email ? mail.to : mail.to.join(";") ["cc"] = mail.cc.join(";") unless invalid_cc_email ["subject"] = mail.subject ["date"] = mail.date.to_s if mail.multipart? for i in 0...mail.parts.length m = download(mail.parts[i], custom_uid) .merge!(m) unless m.nil? end else m = download(mail, custom_uid) .merge!(m) unless m.nil? end save(, "meta/#{uid.to_s + '_' + custom_uid}") end |