Class: Gitlab::Email::AttachmentUploader

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/email/attachment_uploader.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message) ⇒ AttachmentUploader

Returns a new instance of AttachmentUploader


6
7
8
# File 'lib/gitlab/email/attachment_uploader.rb', line 6

def initialize(message)
  @message = message
end

Instance Attribute Details

#messageObject

Returns the value of attribute message


4
5
6
# File 'lib/gitlab/email/attachment_uploader.rb', line 4

def message
  @message
end

Instance Method Details

#execute(project) ⇒ Object


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/gitlab/email/attachment_uploader.rb', line 10

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