diff options
author | Douwe Maan <douwe@gitlab.com> | 2015-08-19 10:18:05 -0700 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2015-08-19 10:18:05 -0700 |
commit | ee1eb2948d30365be241bed6a68b29da57495af8 (patch) | |
tree | 4b04886c84c942973fb6b9b3b24f82b38430c2f0 /lib | |
parent | 01c5ecedd405fed29dbae11039ecb1a90f170c28 (diff) | |
download | gitlab-ce-ee1eb2948d30365be241bed6a68b29da57495af8.tar.gz |
Turn reply-by-email attachments into uploads.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/email_receiver.rb | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/lib/gitlab/email_receiver.rb b/lib/gitlab/email_receiver.rb index 18a06d2ee8c..3dd8942a262 100644 --- a/lib/gitlab/email_receiver.rb +++ b/lib/gitlab/email_receiver.rb @@ -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 |