Menu

#345 Blank headers because AIX iconv uses different names

closed-fixed
5
2007-08-04
2007-08-03
Carey Evans
No

I'm running NOCC 1.4 on "Zend Core for i5/OS", which uses the AIX C runtime on an iSeries (AS/400) server. As the PHP manual warns, AIX uses different character set names for its version of iconv; notably, ISO-8859-1 is not recognised and ISO8859-1 must be used instead. Because ISO-8859-1 is not supported, the From, To and Subject appear blank with most emails received.

The list of supported names for character sets with AIX iconv is at the bottom of http://publib.boulder.ibm.com/infocenter/pseries/v5r3/topic/com.ibm.aix.nls/doc/nlsgdrf/iconv.htm

Part of this problem is that mime_header_decode() doesn't check whether the iconv() function succeeded. If the return value from iconv() was checked in mime_header_decode() like in aff_mail(), I would at least be able to see something, and guess straight away that character encodings were at fault. My main request is to do something about this, to save hours spent trying to work out whether the problem is in the mail server or the imap extension.

The harder problem is to get a valid character set name for iconv when the GNU version isn't being used. I've replaced the calls to iconv() with a wrapper function that guesses a likely character set when running on AIX. This isn't perfect, since it only works with handful of European character sets. However, it works for us.

This is the function I'm using:

function os_iconv($input_charset, $output_charset, &$text) {
if (strlen($text) == 0) {
return $text;
}

if (PHP_OS == 'AIX') {
// AIX has its own small selection of names.
$input_charset = strtolower($input_charset);
if ($input_charset == 'x-unknown' || $input_charset = 'us-ascii') {
$input_charset = 'ISO8859-1';
} else if (ereg('^iso[-_]?8859[-_]?([1-9][0-9]?)', $input_charset, $groups)) {
$input_charset = 'ISO8859-' . $groups[0];
} else if (ereg('^(windows|cp|ibm)[-_]?([0-9]+)$', $input_charset, $groups)) {
$input_charset = 'IBM-' . str_pad($groups[1], 3, '0', STR_PAD_LEFT);
}
} else {
// Assume default GNU iconv.
if ($input_charset == 'x-unknown') {
$input_charset = 'ISO-8859-1';
}
}

return @iconv($input_charset, $output_charset, $text);
}

Discussion

  • Carey Evans

    Carey Evans - 2007-08-03

    Logged In: YES
    user_id=116629
    Originator: YES

    How embarassing. That should be $input_charset == 'us-ascii', of course.

     
  • Anonymous

    Anonymous - 2007-08-04
    • assigned_to: nobody --> goddess_skuld
    • status: open --> closed-fixed
     
  • Anonymous

    Anonymous - 2007-08-04

    Logged In: YES
    user_id=529507
    Originator: NO

    Fixed in CVS.

    It'll be included in next release.

    But you can download daily snapshots at :
    http://nocc.sourceforge.net/download/

    Thanks for the bug report.

     

Log in to post a comment.