Commit 2acbb00b authored by YANO Takashi's avatar YANO Takashi

ZP-869 utf-7 charset conversion: some folders are not shown. Released under...

ZP-869 utf-7 charset conversion: some folders are not shown. Released under the Affero GNU General Public License (AGPL) version 3.
parent 2097efe0
......@@ -144,7 +144,8 @@ class Mail_mail extends Mail {
// pass it as a seperate argument to mail().
$subject = '';
if (isset($headers['Subject'])) {
$subject = $headers['Subject'];
mb_internal_encoding("UTF-8");
$subject = mb_encode_mimeheader($headers['Subject']);
unset($headers['Subject']);
}
......
......@@ -703,7 +703,7 @@ class BackendIMAP extends BackendDiff implements ISearchProvider {
$notExcluded = true;
for ($i = 0, $cnt = count($this->excludedFolders); $notExcluded && $i < $cnt; $i++) { // expr1, expr2 modified by mku ZP-329
// fix exclude folders with special chars by mku ZP-329
if (strpos(strtolower($val), strtolower(Utils::Utf7_iconv_encode(Utils::Utf8_to_utf7($this->excludedFolders[$i])))) !== false) {
if (strpos(strtolower($val), strtolower(Utils::Utf8_to_utf7imap($this->excludedFolders[$i]))) !== false) {
$notExcluded = false;
ZLog::Write(LOGLEVEL_DEBUG, sprintf("Pattern: <%s> found, excluding folder: '%s'", $this->excludedFolders[$i], $val)); // sprintf added by mku ZP-329
}
......@@ -785,12 +785,12 @@ class BackendIMAP extends BackendDiff implements ISearchProvider {
}
if (count($fhir) == 1) {
$folder->displayname = Utils::Utf7_to_utf8(Utils::Utf7_iconv_decode($fhir[0]));
$folder->displayname = Utils::Utf7imap_to_utf8($fhir[0]);
$folder->parentid = "0";
}
else {
$this->getModAndParentNames($fhir, $folder->displayname, $imapparent);
$folder->displayname = Utils::Utf7_to_utf8(Utils::Utf7_iconv_decode($folder->displayname));
$folder->displayname = Utils::Utf7imap_to_utf8($folder->displayname);
if ($imapparent === null) {
ZLog::Write(LOGLEVEL_WARN, sprintf("BackendIMAP->GetFolder('%s'): '%s'; we didn't found a valid parent name for the folder, but we should... contact the developers for further info", $id, $imapid));
$folder->parentid = "0"; // We put the folder as root folder, so we see it
......@@ -856,7 +856,7 @@ class BackendIMAP extends BackendDiff implements ISearchProvider {
else {
// build name for new mailboxBackendMaildir
$displayname = Utils::Utf7_iconv_encode(Utils::Utf8_to_utf7($displayname));
$displayname = Utils::Utf8_to_utf7imap($displayname);
if ($folderid == "0") {
$newimapid = $displayname;
......@@ -2203,7 +2203,7 @@ class BackendIMAP extends BackendDiff implements ISearchProvider {
* @return boolean success
*/
private function imap_create_folder($foldername) {
$name = Utils::Utf7_iconv_encode(Utils::Utf8_to_utf7($foldername));
$name = Utils::Utf8_to_utf7imap($foldername);
$res = @imap_createmailbox($this->mbox, $name);
if ($res) {
......@@ -2477,6 +2477,10 @@ class BackendIMAP extends BackendDiff implements ISearchProvider {
*/
private function saveSentMessage($finalHeaders, $finalBody) {
ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->saveSentMessage(): saving message in Sent Items folder"));
if ( isset($finalHeaders['Subject']) ) {
mb_internal_encoding("UTF-8");
$finalHeaders['Subject'] = mb_encode_mimeheader($finalHeaders['Subject']);
}
$headers = "";
foreach ($finalHeaders as $k => $v) {
......
......@@ -510,6 +510,23 @@ class Utils {
return $string;
}
/**
* Converts an UTF7-IMAP encoded string into an UTF-8 string.
*
* @param string $string to convert
*
* @access public
* @return string
*/
static public function Utf7imap_to_utf8($string) {
if (function_exists("mb_convert_encoding")){
return @mb_convert_encoding($string, "UTF-8", "UTF7-IMAP");
} else {
ZLog::Write(LOGLEVEL_WARN, "Utils::Utf7imap_to_utf8() 'mb_convert_encoding' is not available. Charset conversion skipped.");
}
return $string;
}
/**
* Converts an UTF-8 encoded string into an UTF-7 string.
*
......@@ -528,6 +545,23 @@ class Utils {
return $string;
}
/**
* Converts an UTF-8 encoded string into an UTF7-IMAP string.
*
* @param string $string to convert
*
* @access public
* @return string
*/
static public function Utf8_to_utf7imap($string) {
if (function_exists("mb_convert_encoding")){
return @mb_convert_encoding($string, "UTF7-IMAP", "UTF-8");
} else {
ZLog::Write(LOGLEVEL_WARN, "Utils::Utf7imap_to_utf8() 'mb_convert_encoding' is not available. Charset conversion skipped.");
}
return $string;
}
/**
* Checks for valid email addresses
* The used regex actually only checks if a valid email address is part of the submitted string
......
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