Skip to content

Commit a3fc7f6

Browse files
authored
Merge pull request #71 from amatsuda/x-gzip64
Decode x-gzip64 attachments
2 parents 965ed47 + fc50600 commit a3fc7f6

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

app/models/message.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def from_mail(mail, list, list_seq)
6767
handle_body p
6868
end
6969
elsif part.attachment?
70-
file = StringIO.new(part.body.raw_source)
70+
file = StringIO.new(part.decoded)
7171
attachments.attach(io: file, filename: part.filename, content_type: part.content_type)
7272
else
7373
case part.content_type&.downcase

bin/import_mails

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
require 'optparse'
44
require 'mail'
5+
require 'mail/encodings/x_gzip64'
56

67
BASE_DIR = Rails.root.join('tmp')
78

lib/mail/encodings/x_gzip64.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# frozen_string_literal: true
2+
3+
require 'mail/encodings/base64'
4+
require 'zlib'
5+
6+
module Mail
7+
module Encodings
8+
class XGzip64 < Base64
9+
NAME = 'x-gzip64'
10+
PRIORITY = 3
11+
Encodings.register(NAME, self)
12+
13+
def self.decode(str)
14+
base64str = Utilities.decode_base64(str)
15+
ActiveSupport::Gzip.decompress(base64str)
16+
end
17+
end
18+
end
19+
end

0 commit comments

Comments
 (0)