Page MenuHomePhorge

Incoming mail parsing fails if specific headers have UTF-8 encoded text in them
Open, Needs TriagePublic

Description

Since pulling rPa76444a8e238: Update mimemailparser from May 2011 version to 8.0.4 (T15940: Update copy of external mimemailparser library) my Phorge install no longer receives email sent by me, instead throwing this error:

[2024-11-24 16:33:23] EXCEPTION: (RuntimeException) iconv_mime_decode(): Detected an illegal character in input string at [<arcanist>/src/error/PhutilErrorHandler.php:273]
arcanist(head=master, ref.master=29ca3df1122b), phorge(head=master, ref.master=a76444a8e238)
  #0 PhutilErrorHandler::handleError(integer, string, string, integer)
  #1 iconv_mime_decode(string, integer, string) called at [<arcanist>/src/utils/utils.php:1759]
  #2 phutil_decode_mime_header(string) called at [<phorge>/scripts/mail/mail_handler.php:63]

After some debugging it seems like this is caused by a behaviour change in the library where it now decodes MIME encoded UTF8 data in headers (in this case From). Phorge passes that header to the iconv_mime_decode() PHP function that does not accept already encoded content:

php > var_dump( iconv_mime_decode( 'From: =?UTF-8?B?VGFhdmkgVsOkw6Ruw6RuZW4=?= <taavi@majava.org>', 0, 'utf8' ) );
string(42) "From: Taavi Väänänen <taavi@majava.org>"
php > var_dump( iconv_mime_decode( 'From: Taavi Väänänen <taavi@majava.org>', 0, 'utf8' ) );
PHP Notice:  iconv_mime_decode(): Detected an illegal character in input string in php shell code on line 1
bool(false)