From 5ac27ba832ad9d68df498e65dd51a1cf8f6db1b5 Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Fri, 24 Oct 2025 04:04:08 +0900 Subject: [PATCH 1/3] Decode encoded attachments --- app/models/message.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From 3ce00fdeb5e2f2522933fa9c80c43204af49f42f Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Fri, 24 Oct 2025 04:16:50 +0900 Subject: [PATCH 2/3] x-gzip64 decoder for Mail gem --- lib/mail/encodings/x_gzip64.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 lib/mail/encodings/x_gzip64.rb 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 From fc506009515f03300cf82d4a11e122594b62d845 Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Fri, 24 Oct 2025 04:17:26 +0900 Subject: [PATCH 3/3] Load x-gzip64 decoder before processing emails --- bin/import_mails | 1 + 1 file changed, 1 insertion(+) 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')