Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2015-08-19 20:18:05 +0300
committerDouwe Maan <douwe@gitlab.com>2015-08-19 20:18:05 +0300
commitee1eb2948d30365be241bed6a68b29da57495af8 (patch)
tree4b04886c84c942973fb6b9b3b24f82b38430c2f0 /lib
parent01c5ecedd405fed29dbae11039ecb1a90f170c28 (diff)
Turn reply-by-email attachments into uploads.
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/email_receiver.rb33
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