2018-11-06 04:45:35 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-08-20 18:05:06 +00:00
|
|
|
module Gitlab
|
|
|
|
module Email
|
2015-08-20 18:17:14 +00:00
|
|
|
class AttachmentUploader
|
2015-08-20 18:05:06 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2019-01-03 05:17:07 +00:00
|
|
|
uploader = UploadService.new(project, file).execute
|
|
|
|
attachments << uploader.to_h if uploader
|
2015-08-20 18:05:06 +00:00
|
|
|
ensure
|
|
|
|
tmp.close!
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
attachments
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|