• I’m using Entourage for reading my emails, and when I received comment notifications with letter encoding problems (“??” -> “????”, etc…).

    The solution is to add some lines in “wp-includes/comments-functions.php”

    Code to insert in the empty line 706 :

    // debut ajout
    $subject = stripslashes($subject);
    $subject = utf8_decode($subject);
    $notify_message = stripslashes($notify_message);
    $notify_message = utf8_decode($notify_message);
    // fin ajout

    After you must to have something like this :

    $from = "From: $admin_email";

    // debut ajout
    $subject = stripslashes($subject);
    $subject = utf8_decode($subject);
    $notify_message = stripslashes($notify_message);
    $notify_message = utf8_decode($notify_message);
    // fin ajout

    $message_headers = "MIME-Version: 1.0\n"

    Code to insert in the empty line 663 :

    // debut ajout
    $subject = stripslashes($subject);
    $subject = utf8_decode($subject);
    $notify_message = stripslashes($notify_message);
    $notify_message = utf8_decode($notify_message);
    // fin ajout

    After, you must have something like this :

    $from = 'From: "' . $comment->comment_author . "\" <$comment->comment_author_email>";
    }

    // debut ajout
    $subject = stripslashes($subject);
    $subject = utf8_decode($subject);
    $notify_message = stripslashes($notify_message);
    $notify_message = utf8_decode($notify_message);
    // fin ajout

    $message_headers = "MIME-Version: 1.0\n"

    That’s all…

Viewing 1 replies (of 1 total)
  • zeguigui

    (@zeguigui)

    This code solves the UTF8/ISO-Latin-1 problem but there is still a problem. email RFC request that subject and sender to be in 7 bit ascii!

    You will need to Q-Encode or B-Encode the subject and sender to be fully compliant with this RFC.

    Being “RFC compliant” is a plus with some antispam softwares.

    Here is a sample function to Q-Encode a string:

    function encodeMailHeader($txt)
    {
    $result = "";
    // Search for an 8 bit char in supplyed string
    $len = strlen ($txt);
    $bNeedEncoding = false;
    for ($i = 0; $i < $len; $i++)
    {
    if (ord(substr($txt, $i, 1)) > 127)
    { // On est sur 8 bits !
    $bNeedEncoding = true;
    break;
    }
    }
    if ($bNeedEncoding)
    {
    $result = '=?iso-8859-1?Q?'; // Q encoding is easier to read and debug!
    // Note we probably could use UTF-8???
    for ($i = 0; $i < $len; $i++)
    {
    $c = ord(substr($txt, $i, 1));
    if (($c > 127) || ($c < 0x20))
    { $result .= '='.strtoupper(dechex($c));
    }
    else
    {
    switch ($c)
    {
    case 0x20: $result .= '_'; break; // space
    case 0x22:
    case 0x28:
    case 0x29:
    case 0x2C:
    case 0x2E:
    case 0x2F:
    case 0x3A:
    case 0x3B:
    case 0x3C:
    case 0x3D:
    case 0x3E:
    case 0x3F:
    case 0x40:
    case 0x5B:
    case 0x5D: $result .= '='.strtoupper(dechex($c)); break; // Special chars
    default: $result .= chr($c); // default chars
    }
    }
    }
    $result .= '?='; // end of encoding
    }
    else
    { $result = $txt;
    }
    return $result;
    }

    (well it’s probably not “state-of-the-art” programming but it works!).

Viewing 1 replies (of 1 total)
  • The topic ‘WP 1.5 : comment notifications with “French” characters’ is closed to new replies.