mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 16:11:08 +08:00
Adds a rake task for refreshing posts received via email
This is useful when the email_reply_trimmer gem was updated and you want to apply those changes to existing posts.
This commit is contained in:
@ -620,6 +620,12 @@ module Email
|
||||
|
||||
def create_post_with_attachments(options = {})
|
||||
# deal with attachments
|
||||
options[:raw] = add_attachments(options[:raw], options[:user].id, options)
|
||||
|
||||
create_post(options)
|
||||
end
|
||||
|
||||
def add_attachments(raw, user_id, options = {})
|
||||
attachments.each do |attachment|
|
||||
tmp = Tempfile.new(["discourse-email-attachment", File.extname(attachment.filename)])
|
||||
begin
|
||||
@ -627,19 +633,19 @@ 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(options[:user].id)
|
||||
upload = UploadCreator.new(tmp, attachment.filename, opts).create_for(user_id)
|
||||
if upload && upload.errors.empty?
|
||||
# try to inline images
|
||||
if attachment.content_type.start_with?("image/")
|
||||
if options[:raw][attachment.url]
|
||||
options[:raw].sub!(attachment.url, upload.url)
|
||||
elsif options[:raw][/\[image:.*?\d+[^\]]*\]/i]
|
||||
options[:raw].sub!(/\[image:.*?\d+[^\]]*\]/i, attachment_markdown(upload))
|
||||
if attachment.content_type&.start_with?("image/")
|
||||
if raw[attachment.url]
|
||||
raw.sub!(attachment.url, upload.url)
|
||||
elsif raw[/\[image:.*?\d+[^\]]*\]/i]
|
||||
raw.sub!(/\[image:.*?\d+[^\]]*\]/i, attachment_markdown(upload))
|
||||
else
|
||||
options[:raw] << "\n\n#{attachment_markdown(upload)}\n\n"
|
||||
raw << "\n\n#{attachment_markdown(upload)}\n\n"
|
||||
end
|
||||
else
|
||||
options[:raw] << "\n\n#{attachment_markdown(upload)}\n\n"
|
||||
raw << "\n\n#{attachment_markdown(upload)}\n\n"
|
||||
end
|
||||
end
|
||||
ensure
|
||||
@ -647,7 +653,7 @@ module Email
|
||||
end
|
||||
end
|
||||
|
||||
create_post(options)
|
||||
raw
|
||||
end
|
||||
|
||||
def attachment_markdown(upload)
|
||||
|
Reference in New Issue
Block a user