diff --git a/lib/mail_handler/backends/mail_backend.rb b/lib/mail_handler/backends/mail_backend.rb index 87b612b7e56..cfb6886bbbd 100644 --- a/lib/mail_handler/backends/mail_backend.rb +++ b/lib/mail_handler/backends/mail_backend.rb @@ -404,7 +404,7 @@ def attempt_to_find_original_attachment_attributes(mail, body:, nested: false) def calculate_hexdigest(body) # ensure bodies have the same line endings Digest::MD5.hexdigest(Mail::Utilities.binary_unsafe_to_lf( - body.rstrip + convert_string_to_utf8(body.rstrip).string )) end diff --git a/spec/lib/mail_handler/backends/mail_backend_spec.rb b/spec/lib/mail_handler/backends/mail_backend_spec.rb index c5dda569b62..37237ab3a9f 100644 --- a/spec/lib/mail_handler/backends/mail_backend_spec.rb +++ b/spec/lib/mail_handler/backends/mail_backend_spec.rb @@ -461,6 +461,7 @@ add_file filename: 'lf.txt', content: "bar\nbar" add_file filename: 'crlf-non-ascii.txt', content: "Aberdâr\r\n" add_file filename: 'lf-non-ascii.txt', content: "Aberdâr\n" + add_file filename: 'latin1.txt', content: "naïve" add_file filename: 'mail.eml', content: mail_attachment add_file filename: 'uuencoded.eml', content: mail_with_uuencoded end @@ -492,6 +493,11 @@ it { is_expected.to include(body: "Aberdâr\n") } end + context 'when binary body encoded as Latin 1 / ISO-8859-1' do + let(:body) { "na\xEFve".b } + it { is_expected.to include(body: "naïve") } + end + context 'when attached email headers are different' do let(:body) do <<~EML