debian-mirror-gitlab/lib/gitlab/email/attachment_uploader.rb

38 lines
826 B
Ruby
Raw Normal View History

2018-12-23 12:14:25 +05:30
# frozen_string_literal: true
2015-09-25 12:07:36 +05:30
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
}
2017-08-17 22:00:37 +05:30
link = UploadService.new(project, file).execute
2015-09-25 12:07:36 +05:30
attachments << link if link
ensure
tmp.close!
end
end
attachments
end
end
end
end