Commit 7fe8135b authored by YANO Takashi's avatar YANO Takashi

ZP-1226 Sent mails' To or Cc field may be junk string at other mail clients....

ZP-1226 Sent mails' To or Cc field may be junk string at other mail clients. Released under the Affero GNU General Public License (AGPL) version 3.
parent 0e4a1a39
...@@ -204,6 +204,10 @@ class BackendIMAP extends BackendDiff implements ISearchProvider { ...@@ -204,6 +204,10 @@ class BackendIMAP extends BackendDiff implements ISearchProvider {
$toaddr = $this->parseAddr($Mail_RFC822->parseAddressList($message->headers["to"])); $toaddr = $this->parseAddr($Mail_RFC822->parseAddressList($message->headers["to"]));
ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->SendMail(): To defined: %s", $toaddr)); ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->SendMail(): To defined: %s", $toaddr));
} }
$message->headers["to"] = Utils::CheckAndFixEncodingInHeadersOfSentMail($Mail_RFC822->parseAddressList($message->headers["to"]));
$message->headers["cc"] = Utils::CheckAndFixEncodingInHeadersOfSentMail($Mail_RFC822->parseAddressList($message->headers["cc"]));
unset($Mail_RFC822); unset($Mail_RFC822);
if (isset($message->headers["subject"]) && mb_detect_encoding($message->headers["subject"], "UTF-8") != false && preg_match('/[^\x00-\x7F]/', $message->headers["subject"]) == 1) { if (isset($message->headers["subject"]) && mb_detect_encoding($message->headers["subject"], "UTF-8") != false && preg_match('/[^\x00-\x7F]/', $message->headers["subject"]) == 1) {
......
...@@ -1192,6 +1192,41 @@ class Utils { ...@@ -1192,6 +1192,41 @@ class Utils {
$string = mb_convert_encoding($string, "utf-8", "ISO-2022-JP-MS"); $string = mb_convert_encoding($string, "utf-8", "ISO-2022-JP-MS");
} }
} }
/**
* 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 ths 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