From 341836eb42a3377f730c2bdf5f1ca086245a5955 Mon Sep 17 00:00:00 2001 From: Gerhard Schlager Date: Wed, 17 Oct 2018 16:48:09 +0200 Subject: [PATCH] Fix the rake task and importer instead --- lib/email/receiver.rb | 6 +++--- lib/tasks/posts.rake | 2 +- script/import_scripts/mbox/importer.rb | 3 ++- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/email/receiver.rb b/lib/email/receiver.rb index 8a95dbf6d33..a601b27eb7e 100644 --- a/lib/email/receiver.rb +++ b/lib/email/receiver.rb @@ -890,12 +890,12 @@ module Email def create_post_with_attachments(options = {}) # deal with attachments - options[:raw] = add_attachments(options[:raw], options[:user].id, options) + options[:raw] = add_attachments(options[:raw], options[:user], options) create_post(options) end - def add_attachments(raw, user_id, options = {}) + def add_attachments(raw, user, options = {}) rejected_attachments = [] attachments.each do |attachment| tmp = Tempfile.new(["discourse-email-attachment", File.extname(attachment.filename)]) @@ -904,7 +904,7 @@ module Email File.open(tmp.path, "w+b") { |f| f.write attachment.body.decoded } # create the upload for the user opts = { for_group_message: options[:is_group_message] } - upload = UploadCreator.new(tmp, attachment.filename, opts).create_for(user_id) + upload = UploadCreator.new(tmp, attachment.filename, opts).create_for(user.id) if upload&.valid? # try to inline images if attachment.content_type&.start_with?("image/") diff --git a/lib/tasks/posts.rake b/lib/tasks/posts.rake index d28dc665625..0c78987a0f6 100644 --- a/lib/tasks/posts.rake +++ b/lib/tasks/posts.rake @@ -277,7 +277,7 @@ task 'posts:refresh_emails', [:topic_id] => [:environment] do |_, args| receiver = Email::Receiver.new(post.raw_email) body, elided = receiver.select_body - body = receiver.add_attachments(body || '', post.user_id) + body = receiver.add_attachments(body || '', post.user) body << Email::Receiver.elided_html(elided) if elided.present? post.revise(Discourse.system_user, { raw: body, cook_method: Post.cook_methods[:regular] }, diff --git a/script/import_scripts/mbox/importer.rb b/script/import_scripts/mbox/importer.rb index dbccf64c328..30807b84867 100644 --- a/script/import_scripts/mbox/importer.rb +++ b/script/import_scripts/mbox/importer.rb @@ -131,7 +131,8 @@ module ImportScripts::Mbox if row['attachment_count'].positive? receiver = Email::Receiver.new(row['raw_message']) - body = receiver.add_attachments(body, user_id) + user = User.find(user_id) + body = receiver.add_attachments(body, user) end body << Email::Receiver.elided_html(elided) if elided.present?