change message gateway to save received email as attachment to the todo

This commit is contained in:
Reinier Balt 2014-07-03 23:24:29 +02:00
parent 8c17578f38
commit d769f27e9e
2 changed files with 9 additions and 1 deletions

View file

@ -18,7 +18,14 @@ class MessageGateway < ActionMailer::Base
if saved
Rails.logger.info "Saved email as todo for user #{user.login} in context #{context.name}"
saved = attach_email_to_todo(todo, email)
attachment = todo.attachments.build
tmp = Tempfile.new(['attachment', '.eml'], cr_newline: false)
tmp.write email.raw_source.gsub(/\r\n?/, "\n") # replace \r with \n
Rails.logger.info "Saved received email to #{tmp.path}"
attachment.file = tmp
tmp.close
saved = attachment.save!
tmp.unlink
if saved
Rails.logger.info "Saved email as todo for user #{user.login} in context #{context.name}"