diff --git a/app/models/message.rb b/app/models/message.rb index f873c96..e08aa58 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -67,7 +67,7 @@ def from_mail(mail, list, list_seq) handle_body p end elsif part.attachment? - file = StringIO.new(part.body.raw_source) + file = StringIO.new(part.decoded) attachments.attach(io: file, filename: part.filename, content_type: part.content_type) else case part.content_type&.downcase diff --git a/bin/import_mails b/bin/import_mails index 1678060..60fb8cd 100755 --- a/bin/import_mails +++ b/bin/import_mails @@ -2,6 +2,7 @@ require 'optparse' require 'mail' +require 'mail/encodings/x_gzip64' BASE_DIR = Rails.root.join('tmp') diff --git a/lib/mail/encodings/x_gzip64.rb b/lib/mail/encodings/x_gzip64.rb new file mode 100644 index 0000000..661a787 --- /dev/null +++ b/lib/mail/encodings/x_gzip64.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +require 'mail/encodings/base64' +require 'zlib' + +module Mail + module Encodings + class XGzip64 < Base64 + NAME = 'x-gzip64' + PRIORITY = 3 + Encodings.register(NAME, self) + + def self.decode(str) + base64str = Utilities.decode_base64(str) + ActiveSupport::Gzip.decompress(base64str) + end + end + end +end