From d769f27e9eb00a7e17903b611ba4fe3e5cb57001 Mon Sep 17 00:00:00 2001 From: Reinier Balt Date: Thu, 3 Jul 2014 23:24:29 +0200 Subject: [PATCH] change message gateway to save received email as attachment to the todo --- app/models/message_gateway.rb | 9 ++++++++- config/routes.rb | 1 + 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/models/message_gateway.rb b/app/models/message_gateway.rb index 28bb298c..7b321dc6 100644 --- a/app/models/message_gateway.rb +++ b/app/models/message_gateway.rb @@ -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}" diff --git a/config/routes.rb b/config/routes.rb index 02cdb3de..71b5b1e4 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -90,6 +90,7 @@ Rails.application.routes.draw do get 'convert_to_project' # TODO: convert to PUT/POST delete 'remove_predecessor' # TODO: convert to PUT/POST post 'change_context' + get 'attachment' end collection do get 'done'