patches for horde-3.1.3 hiromi at tac.tsukuba.ac.jp --- lib/Horde.php.orig Thu Aug 17 22:27:43 2006 +++ lib/Horde.php Fri Aug 18 09:07:22 2006 @@ -826,7 +826,8 @@ } if (!empty($title)) { - $title = '<pre>' . preg_replace(array('/\n/', '/((?))/em', '/

/', '/
/'), array('', 'str_repeat(" ", strlen("$1"))', '<br /> <br />', '<br />'), nl2br(@htmlspecialchars(@htmlspecialchars($title, ENT_QUOTES, $charset), ENT_QUOTES, $charset))) . '</pre>'; + //$title = '<pre>' . preg_replace(array('/\n/', '/((?))/em', '/

/', '/
/'), array('', 'str_repeat(" ", strlen("$1"))', '<br /> <br />', '<br />'), nl2br(@htmlspecialchars(@htmlspecialchars($title, ENT_QUOTES, $charset), ENT_QUOTES, $charset))) . '</pre>'; + $title = '<pre>' . preg_replace(array('/\n/', '/

/', '/
/'), array('', '<br /> <br />', '<br />'), nl2br(@htmlspecialchars(@htmlspecialchars($title, ENT_QUOTES, $charset), ENT_QUOTES, $charset))) . '</pre>'; } return Horde::link($url, $title, $class, $target, $onclick, null, $accesskey, $attributes, false); } --- lib/Horde/NLS.php.orig Thu Aug 17 22:27:43 2006 +++ lib/Horde/NLS.php Mon Nov 6 10:25:26 2006 @@ -119,6 +119,10 @@ setlocale(LC_ALL, $lang_charset); } } + /* let *BSDs behave as Linuxes */ + if(NLS::getCharset() == "UTF-8"){ + setlocale(LC_CTYPE,"C"); + } @putenv('LANG=' . $lang_charset); @putenv('LANGUAGE=' . $lang_charset); } --- lib/Horde/MIME.php.orig Thu Aug 17 22:27:43 2006 +++ lib/Horde/MIME.php Thu Nov 2 11:49:22 2006 @@ -110,6 +110,55 @@ return (is_string($string) && preg_match('/[\x80-\xff]/', $string)); } + /* by gullevek at gullevek dot org */ + function _mb_mime_encode($string, $encoding) + { + //if($encoding == "utf-8"){ + // return "=?".$encoding."?B?".base64_encode($string)."?="; + //} + $pos = 0; + $split = 26; + $_string = null; + while ($pos < mb_strlen($string, $encoding)) + { + $output = mb_strimwidth($string, $pos, $split, "", $encoding); + if($output == "") break; + $pos += mb_strlen($output, $encoding); + $_string_encoded = "=?".$encoding."?B?".base64_encode($output)."?="; + if (isset($_string)) + $_string .= "\r\n"; + $_string .= $_string_encoded; + } + $string = $_string; + return $string; + } + + /* encode jis string */ + function jisencode($text) + { + //print "text=" . $text . "\n"; + $pos1 = strpos($text,"\033\$B"); + //print "pos1=" . $pos1 . " "; + if($pos1 === false) + return $text; + if($pos1 > 0){ + $sub1 = substr($text,0,$pos1); + $sub2 = substr($text,$pos1); + return $sub1 . MIME::jisencode($sub2); + } + $pos2 = strpos($text,"\033(B"); + //print "pos2=" . $pos2 . " "; + if($pos2 === false) + return $text; + if(strlen($text) > $pos2+3){ + $sub1 = substr($text,0,$pos2+3); + $sub2 = substr($text,$pos2+3); + return MIME::jisencode($sub1) . MIME::jisencode($sub2); + } + //return mb_encode_mimeheader($text,'iso-2022-jp'); + return MIME::_mb_mime_encode($text,'iso-2022-jp'); + } + /** * Encodes a string containing non-ASCII characters according to RFC 2047. * @@ -121,16 +170,25 @@ */ function encode($text, $charset = null) { - /* Return if nothing needs to be encoded. */ - if (!MIME::is8bit($text)) { - return $text; - } - if (is_null($charset)) { $charset = NLS::getCharset(); } $charset = String::lower($charset); + + if ($charset == 'iso-2022-jp') { + if (mb_detect_encoding($text) == 'ASCII') { + return $text; + } else { + return MIME::jisencode($text); + } + } + + /* Return if nothing needs to be encoded. */ + if (!MIME::is8bit($text)) { + return $text; + } + $line = ''; /* Get the list of elements in the string. */ @@ -140,9 +198,12 @@ if (MIME::is8bit($val[1])) { if ((($key + 1) < $size) && MIME::is8bit($matches[$key + 1][1])) { - $line .= MIME::_encode($val[1] . $val[2], $charset) . ' '; + $line .= MIME::_mb_mime_encode($val[1] . $val[2], $charset) . ' '; } else { - $line .= MIME::_encode($val[1], $charset) . $val[2]; + if(MIME::is8bit($val[2])) + $line .= MIME::_mb_mime_encode($val[1] . $val[2], $charset); + else + $line .= MIME::_mb_mime_encode($val[1], $charset) . $val[2]; } } else { $line .= $val[1] . $val[2]; @@ -297,6 +358,11 @@ function decode($string, $to_charset = null) { if (($pos = strpos($string, '=?')) === false) { + // raw jis string ? + if(($pos = strpos($string,"\033\$B")) === false){ + return $string; + } + $string = mb_convert_encoding($string,$to_charset,'JIS'); return $string; } --- lib/Horde/Kolab.php.orig Thu Aug 17 22:27:43 2006 +++ lib/Horde/Kolab.php Fri Aug 18 09:07:22 2006 @@ -488,19 +488,23 @@ return false; } + $encoding = NLS::getEmailCharset(); + $charset = NLS::getCharset(); + $this->_msg_no = -1; $this->_message = new MIME_Message(); $kolab_text = sprintf(_("This is a Kolab Groupware object. To view this object you will need an email client that understands the Kolab Groupware format. For a list of such email clients please visit %s"), 'http://www.kolab.org/kolab2-clients.html'); + $kolab_text = String::convertCharset($kolab_text, $charset,$encoding); - $part = new MIME_Part('text/plain', String::wrap($kolab_text, 76, KOLAB_NEWLINE, NLS::getCharset()), - NLS::getCharset()); + $part = new MIME_Part('text/plain', String::wrap($kolab_text, 76, KOLAB_NEWLINE), + $encoding); $part->setTransferEncoding('quoted-printable'); $this->_message->addPart($part); - $part = new MIME_Part($this->_mime_type, '', NLS::getCharset()); + $part = new MIME_Part($this->_mime_type, '', $encoding); $part->setTransferEncoding('quoted-printable'); $this->_message->addPart($part); --- lib/Horde/MIME/Headers.php.orig Thu Aug 17 22:27:43 2006 +++ lib/Horde/MIME/Headers.php Fri Aug 18 09:07:22 2006 @@ -170,7 +170,7 @@ /* Parse through the list of all headers. */ foreach ($this->getAllHeaders($decode) as $key => $val) { - $this->addHeader($key, $val); + $this->addHeader($key, $val, false); } } @@ -374,8 +374,9 @@ * * @param string $header The header name. * @param string $value The header value. + * @param boolean $encode MIME encoding for sending ? */ - function addHeader($header, $value) + function addHeader($header, $value, $encode = true) { $header = trim($header); $lcHeader = String::lower($header); @@ -383,6 +384,17 @@ if (!isset($this->_headers[$lcHeader])) { $this->_headers[$lcHeader] = array(); } + + if($encode){ + $encoding = NLS::getEmailCharset(); + $charset = NLS::getCharset(); + $value = String::convertCharset($value,$charset,$encoding); + if($encoding == 'ISO-2022-JP' && + in_array($lcHeader,array('from','to','reply-to','cc','bcc','subject'))){ + $value = MIME::jisencode($value); + } + } + $this->_headers[$lcHeader]['header'] = $header; $this->_headers[$lcHeader]['value'] = $value; $this->_headers[$lcHeader]['_alter'] = false; --- lib/Horde/MIME/MDN.php.orig Thu Aug 17 22:27:43 2006 +++ lib/Horde/MIME/MDN.php Fri Aug 18 09:07:22 2006 @@ -195,11 +195,14 @@ $msg->setType('multipart/report'); $msg->setContentTypeParameter('report-type', 'disposition-notification'); + $encoding = NLS::getEmailCharset(); + $charset = NLS::getCharset(); + /* The first part is a human readable message. */ $part_one = &new MIME_Part('text/plain'); - $part_one->setCharset(NLS::getCharset()); + $part_one->setCharset($encoding); if ($type == 'displayed') { - $part_one->setContents(sprintf(_("The message sent on %s to %s with subject \"%s\" has been displayed.\nThis is no guarantee that the message has been read or understood."), $this->_headers->getValue('Date'), $this->_headers->getValue('To'), $this->_headers->getValue('Subject'))); + $part_one->setContents(String::convertCharset(sprintf(_("The message sent on %s to %s with subject \"%s\" has been displayed.\nThis is no guarantee that the message has been read or understood."), $this->_headers->getValue('Date'), $this->_headers->getValue('To'), $this->_headers->getValue('Subject')),$charset,$encoding)); } // TODO: Messages for other notification types. $msg->addPart($part_one); --- services/problem.php.orig Mon Jan 16 23:24:03 2006 +++ services/problem.php Fri Aug 18 09:07:22 2006 @@ -90,10 +90,12 @@ $msg_headers->addHeader('From', $email); $msg_headers->addHeader('Sender', 'horde-problem@' . $conf['problems']['maildomain']); + $encoding = NLS::getEmailCharset(); + $charset = NLS::getCharset(); $mime = &new MIME_Message(); $mime->addPart(new MIME_Part('text/plain', - String::wrap($body, 80, "\n"), - NLS::getCharset())); + String::convertCharset(String::wrap($body, 80, "\n"), $charset,$encoding), + $encoding)); $msg_headers->addMIMEHeaders($mime); $mail_driver = $conf['mailer']['type'];