Request #7545 - Translate special folder names.
authorMichael M Slusarz <slusarz@curecanti.org>
Mon, 29 Dec 2008 21:03:39 +0000 (14:03 -0700)
committerMichael M Slusarz <slusarz@curecanti.org>
Mon, 29 Dec 2008 21:03:39 +0000 (14:03 -0700)
imp/config/prefs.php.dist
imp/docs/CHANGES
imp/lib/IMAP/Tree.php
imp/lib/IMP.php

index 08df891..e357aa3 100644 (file)
@@ -273,7 +273,7 @@ $_prefs['sent_mail_folder'] = array(
     // 3501 [5.1.3]). For Exchange, uncomment the entry below and remove the
     // default value entry.
     // 'value' => 'Sent Items',
-    'value' => _("Sent"),
+    'value' => 'Sent',
     'locked' => false,
     'shared' => false,
     'type' => 'implicit');
@@ -311,7 +311,7 @@ $_prefs['folderselect'] = array('type' => 'special');
 $_prefs['drafts_folder'] = array(
     // The mailbox value must be encoded in the UTF7-IMAP charset (see RFC
     // 3501 [5.1.3]).
-    'value' => _("Drafts"),
+    'value' => 'Drafts',
     'locked' => false,
     'shared' => false,
     'type' => 'implicit');
@@ -326,7 +326,7 @@ $_prefs['trash_folder'] = array(
     // 3501 [5.1.3]). For Exchange, uncomment the entry below and remove the
     // default value entry.
     // 'value' => 'Deleted Items',
-    'value' => _("Trash"),
+    'value' => 'Trash',
     'locked' => false,
     'shared' => false,
     'type' => 'implicit');
@@ -339,7 +339,7 @@ $_prefs['spamselect'] = array('type' => 'special');
 $_prefs['spam_folder'] = array(
     // The mailbox value must be encoded in the UTF7-IMAP charset (see RFC
     // 3501 [5.1.3]).
-    'value' => _("Spam"),
+    'value' => 'Spam',
     'locked' => false,
     'shared' => false,
     'type' => 'implicit');
index d2c9dd3..c77a224 100644 (file)
@@ -2,6 +2,7 @@
 v5.0-cvs
 --------
 
+[mms] Translate special folder names (Request #7545).
 [mms] Make autocompletion threshold parameters configurable (Request #7322).
 [mms] Add compose attachment preview to DIMP.
 [mms] Add 'unit' parameter for quota display (Carlos Pires <acmpires@sapo.pt>,
index fd7e803..990c523 100644 (file)
@@ -383,9 +383,8 @@ class IMP_IMAP_Tree
         $tmp = explode(is_null($ns_info) ? $this->_delimiter : $ns_info['delimiter'], $elt['v']);
         $elt['c'] = count($tmp) - 1;
 
-        /* Convert label to localized charset & convert 'INBOX' to localized
-         * name. */
-        $elt['l'] = ($elt['v'] == 'INBOX') ? _("Inbox") : String::convertCharset($tmp[$elt['c']], 'UTF7-IMAP');
+        /* Get the mailbox label. */
+        $elt['l'] = IMP::getLabel($tmp[$elt['c']]);
 
         if ($_SESSION['imp']['protocol'] != 'pop') {
             if ($elt['c'] != 0) {
index e1c1ab4..1a66eec 100644 (file)
@@ -469,39 +469,53 @@ class IMP
     /**
      * If there is information available to tell us about a prefix in front of
      * mailbox names that shouldn't be displayed to the user, then use it to
-     * strip that prefix out.
+     * strip that prefix out. Additionally, translate prefix text if this
+     * is one of the folders with special meaning.
      *
      * @param string $folder  The folder name to display (UTF7-IMAP).
      *
-     * @return string  The folder, with any prefix gone.
+     * @return string  The folder, with any prefix gone/translated.
      */
     static public function displayFolder($folder)
     {
+        global $prefs;
+
         $cache = &self::$_displaycache;
 
         if (isset($cache[$folder])) {
             return $cache[$folder];
         }
 
-        if ($folder == 'INBOX') {
-            $cache[$folder] = _("Inbox");
-        } else {
-            $ns_info = $GLOBALS['imp_imap']->getNamespace($folder);
-            if (!is_null($ns_info) &&
-                !empty($ns_info['name']) &&
-                ($ns_info['type'] == 'personal') &&
-                substr($folder, 0, strlen($ns_info['name'])) == $ns_info['name']) {
-                $cache[$folder] = substr($folder, strlen($ns_info['name']));
-            } elseif (!is_null($ns_info) &&
-                      (stripos($folder, 'INBOX' . $ns_info['delimiter']) === 0)) {
-                $cache[$folder] = _("Inbox") . substr($folder, 5);
-            } else {
-                $cache[$folder] = $folder;
+        $ns_info = $GLOBALS['imp_imap']->getNamespace($folder);
+        $delimiter = is_null($ns_info) ? $ns_info['delimiter'] : '';
+
+        /* Substitute any translated prefix text. */
+        $sub_array = array(
+            'INBOX' => _("Inbox"),
+            $prefs->getValue('sent_mail_folder') => _("Sent"),
+            $prefs->getValue('drafts_folder') => _("Drafts"),
+            $prefs->getValue('trash_folder') => _("Trash"),
+            $prefs->getValue('spam_folder') => _("Spam")
+        );
+
+        foreach ($sub_array as $key => $val) {
+            if (stripos($folder, $key . $delimiter) === 0) {
+                return $val . String::convertCharset(substr($folder, strlen($key)), 'UTF7-IMAP');
             }
+        }
 
-            $cache[$folder] = String::convertCharset($cache[$folder], 'UTF7-IMAP');
+        /* Strip namespace information. */
+        if (!is_null($ns_info) &&
+            !empty($ns_info['name']) &&
+            ($ns_info['type'] == 'personal') &&
+            substr($folder, 0, strlen($ns_info['name'])) == $ns_info['name']) {
+            $out = substr($folder, strlen($ns_info['name']));
+        } else {
+            $out = $folder;
         }
 
+        $cache[$folder] = String::convertCharset($out, 'UTF7-IMAP');
+
         return $cache[$folder];
     }