summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/services/projects/upload_service.rb6
-rw-r--r--lib/gitlab/email_receiver.rb33
2 files changed, 36 insertions, 3 deletions
diff --git a/app/services/projects/upload_service.rb b/app/services/projects/upload_service.rb
index 992a7a7a1dc..279550d6f4a 100644
--- a/app/services/projects/upload_service.rb
+++ b/app/services/projects/upload_service.rb
@@ -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
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