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.



8
9
10
# File 'lib/gitlab/email/attachment_uploader.rb', line 8

def initialize(message)
  @message = message
end

Instance Attribute Details

#messageObject

Returns the value of attribute message.



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

def message
  @message
end

Instance Method Details

#execute(upload_parent:, uploader_class:) ⇒ Object



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

def execute(upload_parent:, uploader_class:)
  attachments = []

  filter_signature_attachments(message).each do |attachment|
    tmp = Tempfile.new("gitlab-email-attachment")
    begin
      content = attachment.body.decoded
      File.open(tmp.path, "w+b") { |f| f.write content }
      sanitize_exif_if_needed(content, tmp.path)

      file = {
        tempfile: tmp,
        filename: attachment.filename,
        content_type: attachment.content_type
      }

      uploader = UploadService.new(upload_parent, file, uploader_class).execute
      attachments << uploader.to_h if uploader
    ensure
      tmp.close!
    end
  end

  attachments
end