mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-20 09:10:12 +01:00
refactor adding attachments in message_gateway
and remove gsub magic with correct tempfile parameter
This commit is contained in:
parent
ed9f429d4a
commit
25600e39f7
1 changed files with 3 additions and 15 deletions
|
|
@ -18,14 +18,7 @@ class MessageGateway < ActionMailer::Base
|
||||||
if saved
|
if saved
|
||||||
Rails.logger.info "Saved email as todo for user #{user.login} in context #{context.name}"
|
Rails.logger.info "Saved email as todo for user #{user.login} in context #{context.name}"
|
||||||
|
|
||||||
attachment = todo.attachments.build
|
saved = attach_email_to_todo(todo, email)
|
||||||
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
|
if saved
|
||||||
Rails.logger.info "Saved email as todo for user #{user.login} in context #{context.name}"
|
Rails.logger.info "Saved email as todo for user #{user.login} in context #{context.name}"
|
||||||
|
|
@ -41,8 +34,8 @@ class MessageGateway < ActionMailer::Base
|
||||||
attachment = todo.attachments.build
|
attachment = todo.attachments.build
|
||||||
|
|
||||||
# create temp file
|
# create temp file
|
||||||
tmp = Tempfile.new(['attachment', '.eml'], {universal_newline: true})
|
tmp = Tempfile.new(['attachment', '.eml'], universal_newline: true)
|
||||||
tmp.write email.raw_source.gsub(/\r/, "")
|
tmp.write email.raw_source
|
||||||
|
|
||||||
# add temp file to attachment. paperclip will copy the file to the right location
|
# add temp file to attachment. paperclip will copy the file to the right location
|
||||||
Rails.logger.info "Saved received email to #{tmp.path}"
|
Rails.logger.info "Saved received email to #{tmp.path}"
|
||||||
|
|
@ -50,11 +43,6 @@ class MessageGateway < ActionMailer::Base
|
||||||
tmp.close
|
tmp.close
|
||||||
saved = attachment.save!
|
saved = attachment.save!
|
||||||
|
|
||||||
# enable write permissions on group, since MessageGateway could be run under different
|
|
||||||
# user than Tracks (i.e. apache versus mail)
|
|
||||||
dir = File.open(File.dirname(attachment.file.path))
|
|
||||||
dir.chmod(0770)
|
|
||||||
|
|
||||||
# delete temp file
|
# delete temp file
|
||||||
tmp.unlink
|
tmp.unlink
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue