#2789 Missing email message parts in PHP 5.4


Recently, I received a message with 6 lines of text out of 10 missing. When I click the "Download this as a file", the message displayed entirely. I'm using PHP 5.4.2 with a recent snapshot v.1.5.2. While investigation, I realized that the htmlspecialchars function is responsible for deleting the information when displaying the message. This is due to the fact that, as per the PHP doc, the charset parameter "Defines encoding used in conversion. If omitted, the default value for this argument is ISO-8859-1 in versions of PHP prior to 5.4.0, and UTF-8 from PHP 5.4.0 onwards."

I fixed it by modifying the charset_decode function in include/languages.php lines 219 - 220 to the following in order to reflect the default parameters in earlier versions:

if ( ! $force_decode && $charset == strtolower($default_charset) )
return ($save_html ? $string : htmlspecialchars($string,ENT_COMPAT | ENT_HTML401,'ISO-8859-1'));

I think this should be better documented or fixed, a cleaner way.

Thank you.


  • Paul Lesniewski

    Paul Lesniewski - 2012-05-14

    Thanks, we're aware of this problem, but the fix is not to hard-code that parameter, since it's different depending on the user's language selection. We are evaluating how we should best approach this fix.

    If you can attach the FULL message source of the message you were having problems with, that would help our testing efforts.

  • Mathieu Viau

    Mathieu Viau - 2012-05-14

    Test e-mail body with latin characters.

  • Mathieu Viau

    Mathieu Viau - 2012-05-14

    Here you go, any file with latin (accented) characters will permit to reproduce the issue.

  • Harald Eilertsen

    I have the same problem, similar solution but ended up with this patch instead:

    --- functions/i18n.php (revisjon 14340)
    +++ functions/i18n.php (arbeidskopi)
    @@ -184,7 +184,7 @@

    /* All HTML special characters are 7 bit and can be replaced first */
    - if (! $save_html) $string = htmlspecialchars ($string);
    + if (! $save_html) $string = htmlspecialchars ($string, ENT_COMPAT, $charset);
    $charset = strtolower($charset);


    Would be really nice to get this fixed, so we don't need extra patches for the production setup.

  • alex

    alex - 2012-10-04

    No-one in latin coutries (and php 5.4) can use squirrelmail.
    I can´t use it for 6 monthes or so.

    For example, if the sender name has accented chars, when I reply, nothing is copied to the reply form. Nor the "To:" field, neither the subject filed, neither the body field.

  • Harald Eilertsen

    banha, I see the same as you on my production setup (FreeBSD 8.3 php5.4) but on my home system (ArchLinux) the problem does not occur. Both systems are running with my patch applied. I'm working on getting a test setup to try to reproduce the exact setup on the server to see if I can debug the problem further.

  • Paul Lesniewski

    Paul Lesniewski - 2012-12-01
    • status: open --> closed

Log in to post a comment.