mirror of
https://github.com/TracksApp/tracks.git
synced 2026-02-12 18:34:22 +01:00
refactor adding attachments in message_gateway
and remove gsub magic with correct tempfile parameter
This commit is contained in:
parent
a28edbd5d6
commit
d2a6af63bd
1 changed files with 19 additions and 9 deletions
|
|
@ -18,16 +18,9 @@ class MessageGateway < ActionMailer::Base
|
|||
if saved
|
||||
Rails.logger.info "Saved email as todo for user #{user.login} in context #{context.name}"
|
||||
|
||||
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
|
||||
saved = attach_email_to_todo(todo, email)
|
||||
|
||||
if saved
|
||||
if saved
|
||||
Rails.logger.info "Saved email as todo for user #{user.login} in context #{context.name}"
|
||||
end
|
||||
end
|
||||
|
|
@ -37,6 +30,23 @@ class MessageGateway < ActionMailer::Base
|
|||
|
||||
private
|
||||
|
||||
def attach_email_to_todo(todo, email)
|
||||
attachment = todo.attachments.build
|
||||
|
||||
# create temp file
|
||||
tmp = Tempfile.new(['attachment', '.eml'], universal_newline: true)
|
||||
tmp.write email.raw_source
|
||||
|
||||
# add temp file to attachment. paperclip will copy the file to the right location
|
||||
Rails.logger.info "Saved received email to #{tmp.path}"
|
||||
attachment.file = tmp
|
||||
tmp.close
|
||||
saved = attachment.save!
|
||||
|
||||
# delete temp file
|
||||
tmp.unlink
|
||||
end
|
||||
|
||||
def get_todo_params(email)
|
||||
params = {}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue