From b15059418b82152ede609f80acb763541c00e15a Mon Sep 17 00:00:00 2001 From: Gerhard Schlager Date: Wed, 13 Dec 2017 22:01:31 +0100 Subject: [PATCH] FIX: rake task for updating posts received by email should not crash --- lib/tasks/posts.rake | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/tasks/posts.rake b/lib/tasks/posts.rake index 144a92e8656..b57d4cf9af1 100644 --- a/lib/tasks/posts.rake +++ b/lib/tasks/posts.rake @@ -250,13 +250,19 @@ task 'posts:refresh_emails', [:topic_id] => [:environment] do |_, args| total = posts.count posts.find_each do |post| - receiver = Email::Receiver.new(post.raw_email) + begin + receiver = Email::Receiver.new(post.raw_email) - body, elided = receiver.select_body - body = receiver.add_attachments(body || '', post.user_id) - body << Email::Receiver.elided_html(elided) if elided.present? + body, elided = receiver.select_body + body = receiver.add_attachments(body || '', post.user_id) + body << Email::Receiver.elided_html(elided) if elided.present? + + post.revise(Discourse.system_user, { raw: body, cook_method: Post.cook_methods[:regular] }, + skip_revision: true, skip_validations: true, bypass_bump: true) + rescue + puts "Failed to refresh post (topic_id: #{post.topic_id}, post_id: #{post.id})" + end - post.revise(Discourse.system_user, { raw: body }, skip_revision: true, skip_validations: true) updated += 1 print_status(updated, total)