[BlueOnyx:22201] Mojibake in /usr/local/sbin/vacation.pl

Tomohiro Hosaka bokutin at gmail.com
Thu Jul 5 03:22:14 -05 2018


Hello.

Mojibake (text garbling) occured if the user's fullName contains Japanese.

The problem is as follows.

# yum whatprovides /usr/local/sbin/vacation.pl | head
...
base-email-glue-1.6.0-0BX33.el6.noarch : glue for base-email.
Repo        : BlueOnyx-520XR


# diff -ubU4 /usr/local/sbin/vacation.pl-20170912_110001
/usr/local/sbin/vacation.pl-01problem
--- /usr/local/sbin/vacation.pl-20170912_110001 2017-02-25
13:53:47.000000000 +0900
+++ /usr/local/sbin/vacation.pl-01problem       2018-07-05
17:08:29.966473953 +0900
@@ -335,16 +335,20 @@

     $subject = $i18n->get("[[base-email.vacationSubject]]");
     $format = $i18n->getProperty("vacationSubject", "base-email");
     %data = (NAME => "$fullname", EMAIL => "<$user_from>", MSG => $subject);
+    # At this point, if $locale eq "ja_JP"...
+    #        NAME(ascii or utf8)  EMAIL(ascii)             MSG(euc-jp)
     $format=~s/(NAME|EMAIL|MSG)/$data{$1}/g;

     # If the users locale preference is Japanese, then the Subject is now
     # in EUC-JP, which we cannot mail with MIME::Lite. We need to convert
     # it into UTF-8 first:
     &debug_msg("Locale preference of user $username: $locale\n");
     if ($locale eq "ja_JP") {
         &debug_msg("Converting Japanese vacation message to UTF-8 for
user $username.\n");
+        # If NAME is utf8,  $format = "NAME(utf8)   EMAIL(ascii)
MSG(euc-jp)". It can not be decoded as euc-jp. It mojibake.
+        # If NAME is ascii. $format = "NAME(ascii)  EMAIL(ascii)
MSG(euc-jp)". Decode succeeds as euc-jp.
         $format = decode("euc-jp", $format)
     }

     open (INMESSAGE, "$message_file") || die "Can't open message file $!\n";


I changed it in the production servers as follows and it works well.

# diff -ubU4 /usr/local/sbin/vacation.pl-20170912_110001
/usr/local/sbin/vacation.pl-02min_fix
--- /usr/local/sbin/vacation.pl-20170912_110001 2017-02-25
13:53:47.000000000 +0900
+++ /usr/local/sbin/vacation.pl-02min_fix       2018-07-05
16:53:36.113162093 +0900
@@ -335,8 +335,13 @@

     $subject = $i18n->get("[[base-email.vacationSubject]]");
     $format = $i18n->getProperty("vacationSubject", "base-email");
     %data = (NAME => "$fullname", EMAIL => "<$user_from>", MSG => $subject);
+    # At this point, if $locale eq "ja_JP"...
+    #        NAME(ascii or utf8)  EMAIL(ascii)             MSG(euc-jp)
+    eval { Encode::from_to($data{NAME}, "utf8", "euc-jp") } if
$locale eq "ja_JP";
+    # At this point, if $locale eq "ja_JP"...
+    #        NAME(euc-jp)         EMAIL(ascii)             MSG(euc-jp)
     $format=~s/(NAME|EMAIL|MSG)/$data{$1}/g;

     # If the users locale preference is Japanese, then the Subject is now
     # in EUC-JP, which we cannot mail with MIME::Lite. We need to convert

There are also files /usr/sausalito/perl/I18nMail.pm and
/usr/sausalito/bin/i18nmail.pl.
I did not know what kind of patch is better.

I hope someday this bug will be fixed.

Thank you.

--
Tomohiro Hosaka



More information about the Blueonyx mailing list