Menu

#3 ISO-8859-7 and UTF-8 do not work in subject

open
nobody
5
2007-12-16
2007-12-16
Anonymous
No

When setting ISO-8859-7 or UTF-8 as the encoding for the subject. All spaces are removed.

Also in the body Greek characters are encoded as α β which is rather clumsy compared to the usual =CE =A0 etc

Stuart Gall
stuart@otenet.gr

Discussion

  • Nobody/Anonymous

    Logged In: NO

    This can be fixed (May be not completely correctly) By getting it to encode the spaces as well. But only if there is an 8bit char first

    in htmlMimeMail.php
    change

    /**
    * Function to encode a header if necessary
    * according to RFC2047
    */
    function _encodeHeader($input, $charset = 'ISO-8859-7')
    {
    preg_match_all('/(\w*[\x80-\xFF]+[\x80-\xFF ]+\w*)/', $input, $matches);
    foreach ($matches[1] as $value) {
    $replacement = preg_replace('/([\x80-\xFF ])/e', '"=" . strtoupper(dechex(ord("\1")))', $value);
    $input = str_replace($value, '=?' . $charset . '?Q?' . $replacement . '?=', $input);
    }
    return $input;
    }

    Stuart Gall
    stuart@otenet.gr

     
  • Stuart Gall

    Stuart Gall - 2008-05-19

    Logged In: YES
    user_id=2065068
    Originator: NO

    You fix this by editing includes/common.php line 146 add the following

    if(strtolower($charset) != 'utf-8') {
    $text=iconv($charset,"UTF-8//TRANSLIT",$text);
    };

    Before the line
    $input = str_replace($encoded, $text, $input);

    THIS ASSUMES THAT YOUR $tpl_charset is UTF-8
    So I suppose it would be better in the above to actually use that var instead
    viz

    if(strtolower($charset) != strtolower($tpl_charset)) {
    $text=iconv($charset,$tpl_charset."//TRANSLIT",$text);
    };

    But I haven't tested this.

     
  • Michael Braun

    Michael Braun - 2009-02-04

    Yet another proposal with includes the message body as well and uses lang(ISO-8859-1) to detect target charset. It further fixes the use of ->charset on the result of imap_fetchstructure, which does not work for php5.

    diff -r -i -w old/v-webmail-1.6.4/includes/common.php vmail/includes/common.php
    145c145,146
    <
    ---
    > // FIXME charset translation
    > $text = iconv($charset, lang('ISO-8859-1') , $text);
    diff -r -i -w old/v-webmail-1.6.4/includes/mailaccess/imapext.php vmail/includes/mailaccess/imapext.php
    339,340c339,349
    < @$message->$body_var .= decode_body($this->getPart($msg_id, $parts->mime_id), $encoding) . "\r\n";
    < $message->$char_var = (!empty($cparameters[0]->charset)) ? $cparameters[0]->charset : 'iso-8859-1';
    ---
    > $text .= decode_body($this->getPart($msg_id, $parts->mime_id), $encoding) . "\r\n";
    > $charset = lang("iso-8859-1");
    > foreach ($cparameters as $cparameter) {
    > if ($cparameter->attribute == "charset") { $charset = $cparameter->value; break; }
    > }
    > // FIXME charset translation
    > if ($charset != lang("ISO-8859-1")) {
    > $text = iconv($charset,lang("ISO-8859-1"),$text);
    > }
    > @$message->$body_var .= $text;
    > $message->$char_var = $charset;
    diff -r -i -w old/v-webmail-1.6.4/includes/mailaccess/mysql.php vmail/includes/mailaccess/mysql.php
    324,325c324,334
    < @$message->$body_var .= decode_body($this->getPart($msg_id, $parts->mime_id), $encoding) . "\r\n";
    < $message->$char_var = (!empty($cparameters[0]->charset)) ? $cparameters[0]->charset : 'iso-8859-1';
    ---
    > $text .= decode_body($this->getPart($msg_id, $parts->mime_id), $encoding) . "\r\n";
    > $charset = lang("iso-8859-1");
    > foreach ($cparameters as $cparameter) {
    > if ($cparameter->attribute == "charset") { $charset = $cparameter->value; break; }
    > }
    > // FIXME charset translation
    > if ($charset != lang("ISO-8859-1")) {
    > $text = iconv($charset,lang("ISO-8859-1"),$text);
    > }
    > @$message->$body_var .= $text;
    > $message->$char_var = $charset;

     

Log in to post a comment.