Commit ee1eb294 authored by Douwe Maan's avatar Douwe Maan

Turn reply-by-email attachments into uploads.

parent 01c5eced
......@@ -13,9 +13,9 @@ module Projects
filename = uploader.image? ? uploader.file.basename : uploader.file.filename
{
'alt' => filename,
'url' => uploader.secure_url,
'is_image' => uploader.image?
alt: filename,
url: uploader.secure_url,
is_image: uploader.image?
}
end
......
......@@ -40,6 +40,10 @@ module Gitlab
body = parse_body(message)
upload_attachments.each do |link|
body << "\n\n#{link}"
end
note = Notes::CreateService.new(
project,
author,
......@@ -152,5 +156,34 @@ module Gitlab
lines[0..range_end].join.strip
end
def upload_attachments
attachments = []
message.attachments.each do |attachment|
tmp = Tempfile.new("gitlab-email-attachment")
begin
File.open(tmp.path, "w+b") { |f| f.write attachment.body.decoded }
file = {
tempfile: tmp,
filename: attachment.filename,
content_type: attachment.content_type
}
link = ::Projects::UploadService.new(sent_notification.project, file).execute
if link
text = "[#{link[:alt]}](#{link[:url]})"
text.prepend("!") if link[:is_image]
attachments << text
end
ensure
tmp.close!
end
end
attachments
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment