diff options
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 |