Turn reply-by-email attachments into uploads.

This commit is contained in:
Douwe Maan 2015-08-19 10:18:05 -07:00
parent 01c5ecedd4
commit ee1eb2948d
2 changed files with 36 additions and 3 deletions

View file

@ -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

View file

@ -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