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
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gitlab/email/attachment_uploader.rb')
-rw-r--r--lib/gitlab/email/attachment_uploader.rb35
1 files changed, 35 insertions, 0 deletions
diff --git a/lib/gitlab/email/attachment_uploader.rb b/lib/gitlab/email/attachment_uploader.rb
new file mode 100644
index 00000000000..32cece8316b
--- /dev/null
+++ b/lib/gitlab/email/attachment_uploader.rb
@@ -0,0 +1,35 @@
+module Gitlab
+ module Email
+ class AttachmentUploader
+ attr_accessor :message
+
+ def initialize(message)
+ @message = message
+ end
+
+ def execute(project)
+ 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(project, file).execute
+ attachments << link if link
+ ensure
+ tmp.close!
+ end
+ end
+
+ attachments
+ end
+ end
+ end
+end