2015-08-20 14:05:06 -04:00
|
|
|
module Gitlab
|
|
|
|
module Email
|
2015-08-20 14:17:14 -04:00
|
|
|
class AttachmentUploader
|
2015-08-20 14:05:06 -04: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
|
|
|
|
}
|
|
|
|
|
2017-05-01 09:14:35 -04:00
|
|
|
link = UploadService.new(project, file).execute
|
2015-08-20 14:05:06 -04:00
|
|
|
attachments << link if link
|
|
|
|
ensure
|
|
|
|
tmp.close!
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
attachments
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|