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 { ...@@ -144,7 +144,8 @@ class Mail_mail extends Mail {
// pass it as a seperate argument to mail(). // pass it as a seperate argument to mail().
$subject = ''; $subject = '';
if (isset($headers['Subject'])) { if (isset($headers['Subject'])) {
$subject = $headers['Subject']; mb_internal_encoding("UTF-8");
$subject = mb_encode_mimeheader($headers['Subject']);
unset($headers['Subject']); unset($headers['Subject']);
} }
......
...@@ -703,7 +703,7 @@ class BackendIMAP extends BackendDiff implements ISearchProvider { ...@@ -703,7 +703,7 @@ class BackendIMAP extends BackendDiff implements ISearchProvider {
$notExcluded = true; $notExcluded = true;
for ($i = 0, $cnt = count($this->excludedFolders); $notExcluded && $i < $cnt; $i++) { // expr1, expr2 modified by mku ZP-329 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 // 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; $notExcluded = false;
ZLog::Write(LOGLEVEL_DEBUG, sprintf("Pattern: <%s> found, excluding folder: '%s'", $this->excludedFolders[$i], $val)); // sprintf added by mku ZP-329 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 { ...@@ -785,12 +785,12 @@ class BackendIMAP extends BackendDiff implements ISearchProvider {
} }
if (count($fhir) == 1) { 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"; $folder->parentid = "0";
} }
else { else {
$this->getModAndParentNames($fhir, $folder->displayname, $imapparent); $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) { 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)); 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 $folder->parentid = "0"; // We put the folder as root folder, so we see it
...@@ -856,7 +856,7 @@ class BackendIMAP extends BackendDiff implements ISearchProvider { ...@@ -856,7 +856,7 @@ class BackendIMAP extends BackendDiff implements ISearchProvider {
else { else {
// build name for new mailboxBackendMaildir // build name for new mailboxBackendMaildir
$displayname = Utils::Utf7_iconv_encode(Utils::Utf8_to_utf7($displayname)); $displayname = Utils::Utf8_to_utf7imap($displayname);
if ($folderid == "0") { if ($folderid == "0") {
$newimapid = $displayname; $newimapid = $displayname;
...@@ -2203,7 +2203,7 @@ class BackendIMAP extends BackendDiff implements ISearchProvider { ...@@ -2203,7 +2203,7 @@ class BackendIMAP extends BackendDiff implements ISearchProvider {
* @return boolean success * @return boolean success
*/ */
private function imap_create_folder($foldername) { 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); $res = @imap_createmailbox($this->mbox, $name);
if ($res) { if ($res) {
...@@ -2477,6 +2477,10 @@ class BackendIMAP extends BackendDiff implements ISearchProvider { ...@@ -2477,6 +2477,10 @@ class BackendIMAP extends BackendDiff implements ISearchProvider {
*/ */
private function saveSentMessage($finalHeaders, $finalBody) { private function saveSentMessage($finalHeaders, $finalBody) {
ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->saveSentMessage(): saving message in Sent Items folder")); 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 = ""; $headers = "";
foreach ($finalHeaders as $k => $v) { foreach ($finalHeaders as $k => $v) {
......
...@@ -510,6 +510,23 @@ class Utils { ...@@ -510,6 +510,23 @@ class Utils {
return $string; 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. * Converts an UTF-8 encoded string into an UTF-7 string.
* *
...@@ -528,6 +545,23 @@ class Utils { ...@@ -528,6 +545,23 @@ class Utils {
return $string; 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 * Checks for valid email addresses
* The used regex actually only checks if a valid email address is part of the submitted string * 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