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'