Fixes #3096 - Japanese emails incorrectly converted
This commit is contained in:
parent
8c6ac52ef6
commit
88d4e534b2
3 changed files with 46 additions and 4 deletions
|
@ -528,14 +528,15 @@ process unprocessable_mails (tmp/unprocessable_mail/*.eml) again
|
||||||
|
|
||||||
# https://github.com/zammad/zammad/issues/2922
|
# https://github.com/zammad/zammad/issues/2922
|
||||||
def force_parts_encoding_if_needed(mail)
|
def force_parts_encoding_if_needed(mail)
|
||||||
mail.parts.each { |elem| force_single_part_encoding_if_needed(elem) }
|
# enforce encoding on both multipart parts and main body
|
||||||
|
([mail] + mail.parts).each { |elem| force_single_part_encoding_if_needed(elem) }
|
||||||
end
|
end
|
||||||
|
|
||||||
# https://github.com/zammad/zammad/issues/2922
|
# https://github.com/zammad/zammad/issues/2922
|
||||||
def force_single_part_encoding_if_needed(part)
|
def force_single_part_encoding_if_needed(part)
|
||||||
return if part.charset != 'iso-2022-jp'
|
return if part.charset&.downcase != 'iso-2022-jp'
|
||||||
|
|
||||||
part.body = part.body.encoded.unpack1('M').force_encoding('ISO-2022-JP').encode('UTF-8')
|
part.body = force_japanese_encoding part.body.encoded.unpack1('M')
|
||||||
end
|
end
|
||||||
|
|
||||||
ISO2022JP_REGEXP = /=\?ISO-2022-JP\?B\?(.+?)\?=/.freeze
|
ISO2022JP_REGEXP = /=\?ISO-2022-JP\?B\?(.+?)\?=/.freeze
|
||||||
|
@ -543,7 +544,7 @@ process unprocessable_mails (tmp/unprocessable_mail/*.eml) again
|
||||||
# https://github.com/zammad/zammad/issues/3115
|
# https://github.com/zammad/zammad/issues/3115
|
||||||
def header_field_unpack_japanese(field)
|
def header_field_unpack_japanese(field)
|
||||||
field.value.gsub ISO2022JP_REGEXP do
|
field.value.gsub ISO2022JP_REGEXP do
|
||||||
Base64.decode64($1).force_encoding('SJIS').encode('UTF-8')
|
force_japanese_encoding Base64.decode64($1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -934,6 +935,16 @@ process unprocessable_mails (tmp/unprocessable_mail/*.eml) again
|
||||||
|
|
||||||
"<gen-#{Digest::MD5.hexdigest(raw_message)}@#{fqdn}>"
|
"<gen-#{Digest::MD5.hexdigest(raw_message)}@#{fqdn}>"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# https://github.com/zammad/zammad/issues/3096
|
||||||
|
# specific email needs to be forced to ISO-2022-JP
|
||||||
|
# but that breaks other emails that can be forced to SJIS only
|
||||||
|
# thus force to ISO-2022-JP but fallback to SJIS
|
||||||
|
def force_japanese_encoding(input)
|
||||||
|
input.force_encoding('ISO-2022-JP').encode('UTF-8')
|
||||||
|
rescue
|
||||||
|
input.force_encoding('SJIS').encode('UTF-8')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
module Mail
|
module Mail
|
||||||
|
|
18
test/data/mail/mail098.box
Normal file
18
test/data/mail/mail098.box
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
Return-Path: <return@example.org>
|
||||||
|
Delivered-To: delivered@example.org
|
||||||
|
Received: from localhost (unknown [127.0.0.1])
|
||||||
|
by mail.example.org (Postfix) with ESMTP id 31337;
|
||||||
|
Mon, 21 Dec 2020 11:03:03 +0900 (JST)
|
||||||
|
MIME-Version: 1.0
|
||||||
|
Content-Type: text/plain; charset=ISO-2022-JP
|
||||||
|
Content-Transfer-Encoding: 7bit
|
||||||
|
From: "=?ISO-2022-JP?B?GyRCO3ZMMzZJGyhC==?="
|
||||||
|
<noreply@example.org>
|
||||||
|
Reply-To: info@example.org
|
||||||
|
To: noreply@example.org
|
||||||
|
Cc:
|
||||||
|
Subject: =?ISO-2022-JP?B?GyRCMGxNdyFXJHIlIiVDJVckNyReJDkbKEI=?=
|
||||||
|
Message-Id: <20201221110303>
|
||||||
|
Date: Mon, 21 Dec 2020 11:33:03 +0900 (JST)
|
||||||
|
|
||||||
|
$B%+%F%4%j!'A4%a%s%P!<(B
|
13
test/data/mail/mail098.yml
Normal file
13
test/data/mail/mail098.yml
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
--- !ruby/hash:ActiveSupport::HashWithIndifferentAccess
|
||||||
|
from: '"事務局" <noreply@example.org>'
|
||||||
|
from_email: noreply@example.org
|
||||||
|
from_display_name: 事務局
|
||||||
|
to: noreply@example.org
|
||||||
|
cc: ''
|
||||||
|
subject: 一覧」をアップします
|
||||||
|
body: 'カテゴリ:全メンバー
|
||||||
|
|
||||||
|
'
|
||||||
|
content_type: text/plain
|
||||||
|
reply-to: info@example.org
|
||||||
|
attachments: []
|
Loading…
Reference in a new issue