Commit 971785ae authored by Sebastian Kummer's avatar Sebastian Kummer

Merge pull request #442 in ZP/z-push from...

Merge pull request #442 in ZP/z-push from bugfix/ZP-869-imap-utf-7-charset-conversion-some to develop

* commit '2a4e9dd0':
  ZP-869 utf-7 charset conversion: some folders are not shown.Released under the Affero GNU General Public License (AGPL) version 3.
  ZP-869 utf-7 charset conversion: some folders are not shown.Released under the Affero GNU General Public License (AGPL) version 3.
  ZP-869 utf-7 charset conversion: some folders are not shown.Released under the Affero GNU General Public License (AGPL) version 3.
  ZP-869 utf-7 charset conversion: some folders are not shown. Released under the Affero GNU General Public License (AGPL) version 3.
parents e588ebf6 2a4e9dd0
......@@ -201,6 +201,12 @@ class BackendIMAP extends BackendDiff implements ISearchProvider {
}
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) {
mb_internal_encoding("UTF-8");
ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->SendMail(): Subject in raw UTF-8: %s", $message->headers["subject"]));
$message->headers["subject"] = mb_encode_mimeheader($message->headers["subject"]);
}
$this->setReturnPathValue($message->headers, $fromaddr);
$finalBody = "";
......@@ -703,7 +709,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 +791,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 +862,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 +2209,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) {
......
......@@ -510,6 +510,21 @@ 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");
}
return $string;
}
/**
* Converts an UTF-8 encoded string into an UTF-7 string.
*
......@@ -528,6 +543,21 @@ 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");
}
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