Commit f5020a81 authored by YANO Takashi's avatar YANO Takashi

ZP-1202 Part of subject or from may be in junk string. Released under the...

ZP-1202 Part of subject or from may be in junk string. Released under the Affero GNU General Public License (AGPL) version 3.
parent fb98a51e
...@@ -380,35 +380,21 @@ class Utils { ...@@ -380,35 +380,21 @@ class Utils {
* *
* If it's not possible to truncate properly, an empty string is returned * If it's not possible to truncate properly, an empty string is returned
* *
* @param string $string the string * @param string $string - the string
* @param string $length position where string should be cut * @param string $length - position where string should be cut
* @param boolean $htmlsafe doesn't cut html tags in half, doesn't ensure correct html - default: false
*
* @return string truncated string * @return string truncated string
*/ */
static public function Utf8_truncate($string, $length, $htmlsafe = false) { static public function Utf8_truncate($string, $length) {
// make sure length is always an interger // make sure length is always an interger
$length = (int)$length; $length = (int)$length;
// if the input string is shorter then the trunction, make sure it's valid UTF-8! if (strlen($string) <= $length)
if (strlen($string) <= $length) { return $string;
$length = strlen($string) - 1;
}
// The intent is not to cut HTML tags in half which causes displaying issues (see ZP-1240).
// The used method just tries to cut outside of tags, without checking tag validity and closing tags.
if ($htmlsafe) {
$offset = 0 - strlen($string) + $length;
$validPos = strrpos($string, "<", $offset);
if ($validPos > strrpos($string, ">", $offset)) {
$length = $validPos;
}
}
while($length >= 0) { while($length >= 0) {
if ((ord($string[$length]) < 0x80) || (ord($string[$length]) >= 0xC0)) { if ((ord($string[$length]) < 0x80) || (ord($string[$length]) >= 0xC0))
return substr($string, 0, $length); return substr($string, 0, $length);
}
$length--; $length--;
} }
return ""; return "";
...@@ -876,7 +862,6 @@ class Utils { ...@@ -876,7 +862,6 @@ class Utils {
/** /**
* Checks if a file has the same owner and group as the parent directory. * Checks if a file has the same owner and group as the parent directory.
* If not, owner and group are fixed (being updated to the owner/group of the directory). * If not, owner and group are fixed (being updated to the owner/group of the directory).
* If the given file is a special file (i.g., /dev/null, fifo), nothing is changed.
* Function code contributed by Robert Scheck aka rsc. * Function code contributed by Robert Scheck aka rsc.
* *
* @param string $file * @param string $file
...@@ -885,7 +870,7 @@ class Utils { ...@@ -885,7 +870,7 @@ class Utils {
* @return boolean * @return boolean
*/ */
public static function FixFileOwner($file) { public static function FixFileOwner($file) {
if(posix_getuid() == 0 && is_file($file)) { if(posix_getuid() == 0 && file_exists($file)) {
$dir = dirname($file); $dir = dirname($file);
$perm_dir = stat($dir); $perm_dir = stat($dir);
$perm_file = stat($file); $perm_file = stat($file);
...@@ -1280,9 +1265,6 @@ class Utils { ...@@ -1280,9 +1265,6 @@ class Utils {
/** /**
* Check if the UTF-8 string has ISO-2022-JP esc seq * Check if the UTF-8 string has ISO-2022-JP esc seq
=======
* Check if the UTF-8 string has ISO-2022-JP esc seq
>>>>>>> 18c88cd9bfeae83ea5ddb16905b32182cc332207
* if so, it is ISO-2022-JP, not UTF-8 and convert it into UTF-8 * if so, it is ISO-2022-JP, not UTF-8 and convert it into UTF-8
* string * string
* *
...@@ -1318,41 +1300,6 @@ class Utils { ...@@ -1318,41 +1300,6 @@ class Utils {
$message->headers["subject"] = Utils::ConvertRawHeader2Utf8($rawheaders["subject"], $message->headers["subject"]); $message->headers["subject"] = Utils::ConvertRawHeader2Utf8($rawheaders["subject"], $message->headers["subject"]);
$message->headers["from"] = Utils::ConvertRawHeader2Utf8($rawheaders["from"], $message->headers["from"]); $message->headers["from"] = Utils::ConvertRawHeader2Utf8($rawheaders["from"], $message->headers["from"]);
} }
/**
* Get to or cc header in mime-header-encoded UTF-8 text.
*
* @access public
* @param $addrstruncs
* $addrstruncts is a return value of
* Mail_RFC822->parseAddressList(). Convert this into
* plain text. If the phrase part is in plain UTF-8,
* convert this into mime-header encoded UTF-8
*/
public static function CheckAndFixEncodingInHeadersOfSentMail($addrstructs) {
mb_internal_encoding("UTF-8");
$addrarray = array();
// process each address
foreach ( $addrstructs as $struc ) {
$addrphrase = $struc->personal;
if (isset($addrphrase) && strlen($addrphrase) > 0 && mb_detect_encoding($addrphrase, "UTF-8") != false && preg_match('/[^\x00-\x7F]/', $addrphrase) == 1) {
// phrase part is plain utf-8 text including non ascii characters
// convert this into mime-header-encoded text
$addrphrase = mb_encode_mimeheader($addrphrase);
}
if ( strlen($addrphrase) > 0 ) {
// there is a phrase part in the address
$addrarray[] = $addrphrase . " " . " <" . $struc->mailbox . "@" . $struc->host . ">";
} else {
// there is no phrase part in the address
$addrarray[] = $struc->mailbox . "@" . $struc->host;
}
}
// combine each address into a string
$addresses = implode(",", $addrarray);
ZLog::Write(LOGLEVEL_DEBUG, sprintf("Utils::CheckAndFixEncodingInHeadersOfSentMail(): addresses %s", $addresses));
return $addresses;
}
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment