I've done Russian language recoding from one enctype to another while displaying message, its' body, subject and sender. Is this the right place to send it to? String to ChangeLog, if you have any: --- Mon Oct 13 21:31:00 2003 Vladimir Dyakov <dyakov@xxxxx> Added Russian recoding --- -- ÷ÌÁÄÉÍÉÒ äØÑËÏ× | Vladimir Dyakov úáï "éîôåòóéóô" | JSC "INTERSYST" +7 (3422) 909116 vladimir.dyakov@xxxxxxxxxxxx -- Attached file included as plaintext by Ecartis -- -- File: v-webmail-1.5.0-enable_russin_recoding.patch diff -Nru v-webmail-orig/config/.htaccess v-webmail/config/.htaccess --- v-webmail-orig/config/.htaccess Thu Jan 1 05:00:00 1970 +++ v-webmail/config/.htaccess Mon Oct 13 20:37:59 2003 @@ -0,0 +1 @@ +deny from all diff -Nru v-webmail-orig/htdocs/email.reply.redirect.php v-webmail/htdocs/email.reply.redirect.php --- v-webmail-orig/htdocs/email.reply.redirect.php Mon Oct 13 20:28:01 2003 +++ v-webmail/htdocs/email.reply.redirect.php Mon Oct 13 20:37:59 2003 @@ -410,6 +410,9 @@ $SESSION['common']['error_msg'] = lang('Invalid or no action supplied'); break; } + // Recode from message's Russian charset to the page's one if necessary + $SESSION['email_compose']['subject'] = convertMessageEncoding($SESSION['email_compose']['subject'],@$parsedheaders["content-type"]); + $SESSION['email_compose']['text'] = convertMessageEncoding($SESSION['email_compose']['text'],@$parsedheaders["content-type"]); /* * Connection mail server failed diff -Nru v-webmail-orig/htdocs/email.view.message.php v-webmail/htdocs/email.view.message.php --- v-webmail-orig/htdocs/email.view.message.php Mon Oct 13 20:28:01 2003 +++ v-webmail/htdocs/email.view.message.php Mon Oct 13 20:42:01 2003 @@ -397,6 +397,7 @@ } else { $data = htmlspecialchars($header_value); } + $data = convertMessageEncoding($data,$parsedheaders["content-type"]); $headers[] = array('name' => lang('Subject'), 'data' => $data); continue; @@ -412,8 +413,9 @@ // lang('Reply-To') // lang('Date') // lang('Importance') - $headers[] = array('name' => lang($header_name) ? lang($header_name) : $header_name, 'data' => $header_value); + // recode messages if got inconsistent Russian encodings + $headers[] = array('name' => lang($header_name) ? lang($header_name) : $header_name, 'data' => convertMessageEncoding($header_value,$parsedheaders["content-type"])); } elseif ($header_name_lc == 'subject') { $headers[] = array('name' => lang('Subject') ? lang('Subject') : $header_name, 'data' => lang('[no subject]')); } @@ -530,14 +532,18 @@ $body = wordwrap($body, 80, "\r\n", 1); $pre_start = '<pre>'; $pre_end = '</pre>'; - $body = convertUrls($body); // htmlspecialchars() done here + $body = convertMessageEncoding(convertUrls($body),$parsedheaders["content-type"]); + // htmlspecialchars() done here + // recoding from one russian charset to another is done here if necessary break; case $text: $body = wordwrap($message->body_plain, 80, "\r\n", 1); $pre_start = '<pre>'; $pre_end = '</pre>'; - $body = convertUrls($body); // htmlspecialchars() done here + $body = convertMessageEncoding(convertUrls($body),$parsedheaders["content-type"]); + // htmlspecialchars() done here + // recoding from one russian charset to another is done here if necessary break; default: diff -Nru v-webmail-orig/includes/functions.php v-webmail/includes/functions.php --- v-webmail-orig/includes/functions.php Mon Oct 13 20:28:05 2003 +++ v-webmail/includes/functions.php Mon Oct 13 20:37:59 2003 @@ -307,4 +307,33 @@ return false; } + + /** + * recoding from message's Russian charset to the page's one if necessary + */ + function convertMessageEncoding($body,$contenttype,$enc=false) + { + if ($_SESSION["session_global_var"]["common"]["lang"]!="ru") return $body; + if ($enc==="") $enc = "KOI8-R"; // default + if ($enc===false) + if (preg_match("/(charset=)/i",$contenttype)) + { + list(,$enc) = preg_split("/(charset=)/i",$contenttype); + list($enc) = preg_split("/;/",$enc); + } + else + $enc = $contenttype; + $enc = strtoupper($enc); + $pagenc = strtoupper( $GLOBALS['LANG']['ISO-8859-1'] ); + if ( $enc == $pagenc ) return $body; + exec("echo \"".addslashes($body)."\" | recode -f $enc..$pagenc",$ret); + $body = ""; + for ( $i=1; $i<=count($ret); $i++ ) + { + $str = $ret[$i-1]; + $body .= $str . ($i<count($ret)?"\r\n":""); + } + return $body; + } + ?> diff -Nru v-webmail-orig/includes/mailaccess/imapext.php v-webmail/includes/mailaccess/imapext.php --- v-webmail-orig/includes/mailaccess/imapext.php Mon Oct 13 20:28:05 2003 +++ v-webmail/includes/mailaccess/imapext.php Mon Oct 13 20:37:59 2003 @@ -548,6 +548,9 @@ $options = $GLOBALS['SESSION']['email']['use_uids'] ? FT_UID : 0; $raw_header = imap_fetchheader($this->conn, $msg_id, $options); $attachments = preg_match('/Content-Type: multipart\/mixed/im', $raw_header); + // Fetch encoding from headers string + $encoding = str_replace(array("\n","\r"),array("",""),preg_replace(array('/((Content-Type: text\/(plain|html)\; charset=)|(.+))(.*)/i'), "\\5", $raw_header)); + $encoding = preg_replace(array('/(.*);(.*)/i'), "\\1", $encoding); // Importance header? $importance = preg_match('/^Importance: High/im', $raw_header); @@ -555,6 +558,7 @@ } else { $attachments = false; $importance = false; + $encoding = false; } // Determine Size @@ -575,7 +579,7 @@ // From address if (isset($headers->from)) { $email = $headers->from[0]->mailbox.'@'.$headers->from[0]->host; - $name = isset($headers->from[0]->personal) ? decode_header($headers->from[0]->personal) : $email; + $name = isset($headers->from[0]->personal) ? convertMessageEncoding(decode_header($headers->from[0]->personal),$encoding) : $email; if (strlen($name) > 30) { $name = substr($name, 0, 30) . '...'; } @@ -598,7 +602,10 @@ } // Subject - $subject = (isset($headers->subject) AND trim($headers->subject) != '') ? decode_header($headers->subject) : lang('[no subject]'); + $subject = convertMessageEncoding ( + (isset($headers->subject) AND trim($headers->subject) != '') ? decode_header($headers->subject) : lang('[no subject]') + ,"", $encoding ); + // FIXME Make this max subject length configurable if (strlen($subject) > 80) { $subject = substr($subject, 0, 80).'...'; @@ -632,7 +639,7 @@ 'name' => htmlspecialchars($name), 'email_urlsafe' => urlencode(sprintf('"%s" <%s>', $name, $email)), // Err on caution as imap functions don't always return quoted strings 'to_email' => htmlspecialchars($to_email), - 'to_name' => htmlspecialchars($to_name), + 'to_name' => htmlspecialchars(convertMessageEncoding($to_name,$encoding)), 'to_urlsafe' => urlencode(sprintf('"%s" <%s>', $to_name, $to_email)), // Err on caution as imap functions don't always return quoted strings 'subject' => htmlspecialchars($subject), 'size' => $size, diff -Nru v-webmail-orig/includes/mailaccess/pop3.php v-webmail/includes/mailaccess/pop3.php --- v-webmail-orig/includes/mailaccess/pop3.php Mon Oct 13 20:28:05 2003 +++ v-webmail/includes/mailaccess/pop3.php Mon Oct 13 20:37:59 2003 @@ -331,24 +331,25 @@ } // Subject - $subject = (!empty($headerinfo->Subject) AND trim($headerinfo->Subject) != '') ? decode_header($headerinfo->Subject) : lang('[no subject]'); + $subject = convertMessageEncoding ( + empty($headerinfo->Subject) AND trim($headerinfo->Subject) != '' ? decode_header($headerinfo->Subject) : lang('[no subject]') + ,"", $encoding ); // FIXME Make this max subject length configurable if(strlen($subject) > 80){ $subject = substr($subject, 0, 80).'...'; } - // Return all the info $ret = array( 'msg_id' => $msg_id, 'date' => date('H:i jS M Y', $headerinfo->udate), 'email' => htmlspecialchars($email), - 'name' => htmlspecialchars($name), + 'name' => htmlspecialchars(convertMessageEncoding($name,$encoding)), 'email_urlsafe' => urlencode(sprintf('%s <%s>', $name, $email)), 'to_email' => htmlspecialchars($to_email), - 'to_name' => htmlspecialchars($to_name), + 'to_name' => htmlspecialchars(convertMessageEncoding($to_name,$encoding)), 'to_urlsafe' => urlencode(sprintf('%s <%s>', $to_name, $to_email)), - 'subject' => htmlspecialchars($subject), + 'subject' => htmlspecialchars(convertMessageEncoding($subject,$encoding)), 'size' => $size, 'attachments' => $attachments, 'importance' => $importance, -- V-webmail Support Mailing List (http://www.v-webmail.org) Archives: //www.freelists.org/archives/v-webmail/ To unsubscribe, send mail to: v-webmail-request@xxxxxxxxxxxxx with "unsubscribe" in the subject