Method: Client#process_email

Defined in:
lib/client.rb

#process_email(mail, uid, stamp = nil) ⇒ 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.



159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
# File 'lib/client.rb', line 159

def process_email(mail, uid, stamp = nil)
  meta = Hash.new
  custom_uid = (Time.now.to_f * 1000).to_s + "_" + mail.__id__.to_s

  meta["from"] = mail[:from].to_s
  meta["to"] = mail[:to].to_s
  meta["cc"] = mail[:cc].to_s
  meta["subject"] = mail.subject
  meta["date"] = mail.date.to_s

  if mail.multipart?
    for i in 0...mail.parts.length
      m = download(mail.parts[i], custom_uid)
      meta.merge!(m) unless m.nil?
    end
  else
    m = download(mail, custom_uid)
    meta.merge!(m) unless m.nil?
  end

  if stamp.nil?
    save(meta, "meta/#{uid.to_s + '_' + custom_uid}")
  else
    save(meta, "meta/#{uid.to_s + '_' + custom_uid}", stamp)
  end

end