Skip to content

Commit

Permalink
Improve iso-2022-jp subjects and attachment names decoding - closes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
freescout-help-desk committed Jul 14, 2023
1 parent f8787c6 commit 9053670
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion app/Misc/Mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -891,6 +891,8 @@ public static function decodeSubject($subject)
// =?utf-8?Q?Gesch=C3=A4ftskonto?= erstellen =?utf-8?Q?f=C3=BCr?=
// 249143
$subject = preg_replace("/[\r\n]/", '', $subject);
// https://github.com/freescout-helpdesk/freescout/issues/3185
$subject = str_replace('=?iso-2022-jp?', '=?iso-2022-jp-ms?', $subject);

// Sometimes imap_utf8() can't decode the subject, for example:
// =?iso-2022-jp?B?GyRCIXlCaBsoQjEzMhskQjlmISEhViUsITwlRyVzGyhCJhskQiUoJS8lOSVGJWolIiFXQGxMZ0U5JE4kPyRhJE4jURsoQiYbJEIjQSU1JW0lcyEhIVo3bjQpJSglLyU5JUYlaiUiISYlbyE8JS8hWxsoQg==?=
Expand Down Expand Up @@ -957,7 +959,9 @@ public static function decodeSubject($subject)
// mb_decode_mimeheader() properly decodes umlauts into one unice symbol.
// But we use mb_decode_mimeheader() as a last resort as it may garble some symbols.
// Example: =?ISO-8859-1?Q?Vorgang 538336029: M=F6chten Sie Ihre E-Mail-Adresse =E4ndern??=
if (preg_match_all("/=\?[^\?]+\?[BQ]\?/i", $subject_decoded) && $subject == $subject_decoded) {
if ((preg_match_all("/=\?[^\?]+\?[BQ]\?/i", $subject_decoded) && $subject == $subject_decoded)
|| !mb_check_encoding($subject_decoded, 'UTF-8')
) {
$subject_decoded = mb_decode_mimeheader($subject);
}

Expand Down

0 comments on commit 9053670

Please sign in to comment.