#3368 - Japanese character is garbled
This commit is contained in:
parent
045e3751a6
commit
90a67e9d94
3 changed files with 36 additions and 2 deletions
|
@ -940,10 +940,21 @@ process unprocessable_mails (tmp/unprocessable_mail/*.eml) again
|
||||||
# specific email needs to be forced to ISO-2022-JP
|
# specific email needs to be forced to ISO-2022-JP
|
||||||
# but that breaks other emails that can be forced to SJIS only
|
# but that breaks other emails that can be forced to SJIS only
|
||||||
# thus force to ISO-2022-JP but fallback to SJIS
|
# thus force to ISO-2022-JP but fallback to SJIS
|
||||||
|
#
|
||||||
|
# https://github.com/zammad/zammad/issues/3368
|
||||||
|
# some characters are not included in the official ISO-2022-JP
|
||||||
|
# ISO-2022-JP-KDDI superset provides support for more characters
|
||||||
def force_japanese_encoding(input)
|
def force_japanese_encoding(input)
|
||||||
input.force_encoding('ISO-2022-JP').encode('UTF-8')
|
%w[ISO-2022-JP ISO-2022-JP-KDDI SJIS]
|
||||||
|
.lazy
|
||||||
|
.map { |encoding| try_encoding(input, encoding) }
|
||||||
|
.detect(&:present?)
|
||||||
|
end
|
||||||
|
|
||||||
|
def try_encoding(input, encoding)
|
||||||
|
input.force_encoding(encoding).encode('UTF-8')
|
||||||
rescue
|
rescue
|
||||||
input.force_encoding('SJIS').encode('UTF-8')
|
nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
13
test/data/mail/mail099.box
Normal file
13
test/data/mail/mail099.box
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
Content-Type: text/plain; charset=ISO-2022-JP
|
||||||
|
Content-Transfer-Encoding: 7bit
|
||||||
|
From: "example"
|
||||||
|
<noreply@example.org>
|
||||||
|
Reply-To: info@example.org
|
||||||
|
Errors-To: return@example.org
|
||||||
|
To: noreply@example.org
|
||||||
|
Subject: example
|
||||||
|
Message-Id: <msgid@example.org>
|
||||||
|
Date: Fri, 1 Jan 2021 10:00:00 +0900 (JST)
|
||||||
|
|
||||||
|
$B!!!!!!!!!!-!#1ET#38)$N03$H!"(B
|
||||||
|
|
10
test/data/mail/mail099.yml
Normal file
10
test/data/mail/mail099.yml
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
--- !ruby/hash:ActiveSupport::HashWithIndifferentAccess
|
||||||
|
from: example <noreply@example.org>
|
||||||
|
from_email: noreply@example.org
|
||||||
|
from_display_name: example
|
||||||
|
to: noreply@example.org
|
||||||
|
subject: example
|
||||||
|
body: " ①1都3県の鯵と、\n\n"
|
||||||
|
content_type: text/plain
|
||||||
|
reply-to: info@example.org
|
||||||
|
attachments: []
|
Loading…
Reference in a new issue