Import attachments to topics/replies on mailing list import
This commit is contained in:
parent
e2bb08e8ea
commit
94cd87bb7c
|
@ -179,6 +179,22 @@ class ImportScripts::Mbox < ImportScripts::Base
|
||||||
|
|
||||||
title = mail.subject
|
title = mail.subject
|
||||||
|
|
||||||
|
# import the attachments
|
||||||
|
mail.attachments.each do |attachment|
|
||||||
|
tmp = Tempfile.new("discourse-email-attachment")
|
||||||
|
begin
|
||||||
|
# read attachment
|
||||||
|
File.open(tmp.path, "w+b") { |f| f.write attachment.body.decoded }
|
||||||
|
# create the upload for the user
|
||||||
|
upload = Upload.create_for(user_id_from_imported_user_id(mail.from.first) || Discourse::SYSTEM_USER_ID, tmp, attachment.filename, tmp.size )
|
||||||
|
if upload && upload.errors.empty?
|
||||||
|
raw << "\n\n#{receiver.attachment_markdown(upload)}\n\n"
|
||||||
|
end
|
||||||
|
ensure
|
||||||
|
tmp.try(:close!) rescue nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
{ id: t['id'],
|
{ id: t['id'],
|
||||||
title: clean_title(title),
|
title: clean_title(title),
|
||||||
user_id: user_id_from_imported_user_id(mail.from.first) || Discourse::SYSTEM_USER_ID,
|
user_id: user_id_from_imported_user_id(mail.from.first) || Discourse::SYSTEM_USER_ID,
|
||||||
|
@ -218,6 +234,22 @@ class ImportScripts::Mbox < ImportScripts::Base
|
||||||
selected = receiver.select_body
|
selected = receiver.select_body
|
||||||
raw = selected.force_encoding(selected.encoding).encode("UTF-8")
|
raw = selected.force_encoding(selected.encoding).encode("UTF-8")
|
||||||
|
|
||||||
|
# import the attachments
|
||||||
|
mail.attachments.each do |attachment|
|
||||||
|
tmp = Tempfile.new("discourse-email-attachment")
|
||||||
|
begin
|
||||||
|
# read attachment
|
||||||
|
File.open(tmp.path, "w+b") { |f| f.write attachment.body.decoded }
|
||||||
|
# create the upload for the user
|
||||||
|
upload = Upload.create_for(user_id_from_imported_user_id(mail.from.first) || Discourse::SYSTEM_USER_ID, tmp, attachment.filename, tmp.size )
|
||||||
|
if upload && upload.errors.empty?
|
||||||
|
raw << "\n\n#{receiver.attachment_markdown(upload)}\n\n"
|
||||||
|
end
|
||||||
|
ensure
|
||||||
|
tmp.try(:close!) rescue nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
{ id: id,
|
{ id: id,
|
||||||
topic_id: topic_id,
|
topic_id: topic_id,
|
||||||
user_id: user_id_from_imported_user_id(mail.from.first) || Discourse::SYSTEM_USER_ID,
|
user_id: user_id_from_imported_user_id(mail.from.first) || Discourse::SYSTEM_USER_ID,
|
||||||
|
|
Loading…
Reference in New Issue