Prechádzať zdrojové kódy

Folder Selection changes integrated from sizzle-ui stream..
Options for how folder selection list is displayed is on Folder Options page
Folder lists on Search, Folders, and Folder Options Pages, as well
as Folder selection lists used by the Message Index and the
Delete_move_next plugin all modified to use new Option list
creation method in imap_mailbox.

sizzlingmercury 23 rokov pred
rodič
commit
a55cce3a7a

+ 46 - 0
functions/imap_mailbox.php

@@ -446,6 +446,52 @@ function user_strcasecmp($a, $b) {
     return $result;
 }
 
+/*
+ * Returns list of options (to be echoed into select statement
+ * based on available mailboxes and separators
+ * Caller should surround options with <SELECT..> </SELECT> and
+ * any formatting.
+ *   $imap_stream - $imapConnection to query for mailboxes
+ *   $show_selected - array containing list of mailboxes to pre-select (0 if none)
+ *   $folder_skip - array of folders to keep out of option list (compared in lower)
+ *   $boxes - list of already fetched boxes (for places like folder panel, where
+ *            you know these options will be shown 3 times in a row.. (most often unset).
+ */
+function sqimap_mailbox_option_list($imap_stream, $show_selected = 0, $folder_skip = 0, $boxes = 0 ) {
+    global $username, $data_dir;
+    $mbox_options = '';
+
+    $shorten_box_names = getPref($data_dir, $username, 'mailbox_select_style', SMPREF_OFF);
+    
+    if ( $boxes == 0 ) {
+        $boxes = sqimap_mailbox_list($imap_stream);
+    }   
+    foreach ($boxes as $boxes_part) {
+        if (!in_array('noselect', $boxes_part['flags'])) {
+            $box = $boxes_part['unformatted'];
+            $lowerbox = strtolower($box);
+
+            if ( $folder_skip != 0 && in_array($lowerbox, $folder_skip) ) {
+                continue;
+            }
+            if ($lowerbox == 'inbox'){
+                $box2 = _("INBOX");
+            } else if ( $shorten_box_names == 2 ) {  /* delimited, style = 2 */
+                $box2 = str_replace('&nbsp;&nbsp;', '.&nbsp;', $boxes_part['formatted']);
+            } else if ( $shorten_box_names == 1 ) {     /* indent, style = 1 */
+                $box2 = $boxes_part['formatted'];
+            } else  {                      /* default, long names, style = 0 */
+                $box2 = str_replace(' ', '&nbsp;', imap_utf7_decode_local($boxes_part['unformatted-disp']));
+            }
+            if ($show_selected != 0 && in_array($lowerbox, $show_selected) ) {
+                $mbox_options .= '<OPTION VALUE="'.$box.'" SELECTED>'.$box2.'</OPTION>' . "\n";
+            } else {
+                $mbox_options .= '<OPTION VALUE="'.$box.'">'.$box2.'</OPTION>' . "\n";
+            }
+        }
+    }
+    return $mbox_options;
+}
 
 /*
  * Returns sorted mailbox lists in several different ways. 

+ 1 - 15
functions/mailbox_display.php

@@ -1193,21 +1193,7 @@ function processSubject($subject) {
 function getMbxList($imapConnection) {
     global $lastTargetMailbox;
     echo  '         <small>&nbsp;<tt><select name="targetMailbox">';
-    $boxes = sqimap_mailbox_list($imapConnection);
-    foreach ($boxes as $boxes_part) {
-        if (!in_array('noselect', $boxes_part['flags'])) {
-            $box = $boxes_part['unformatted'];
-            $box2 = str_replace(' ', '&nbsp;', imap_utf7_decode_local($boxes_part['unformatted-disp']));
-            if($box2 == 'INBOX') {
-                $box2 = _("INBOX");
-            }
-            if ($lastTargetMailbox == $box) {
-                echo "       <OPTION VALUE=\"$box\" SELECTED>$box2</OPTION>\n";
-            } else {
-                echo "         <OPTION VALUE=\"$box\">$box2</OPTION>\n";
-            }
-        }
-    }
+    echo sqimap_mailbox_option_list($imapConnection, array(strtolower($lastTargetMailbox)) ); 
     echo '         </SELECT></TT>&nbsp;';
 }
 

+ 36 - 0
functions/options.php

@@ -24,6 +24,7 @@ define('SMOPT_TYPE_FLOAT', 4);
 define('SMOPT_TYPE_BOOLEAN', 5);
 define('SMOPT_TYPE_HIDDEN', 6);
 define('SMOPT_TYPE_COMMENT', 7);
+define('SMOPT_TYPE_FLDRLIST', 8);
 
 /* Define constants for the options refresh levels. */
 define('SMOPT_REFRESH_NONE', 0);
@@ -163,6 +164,9 @@ class SquirrelOption {
             case SMOPT_TYPE_COMMENT:
                 $result = $this->createWidget_Comment();
                 break;
+            case SMOPT_TYPE_FLDRLIST:
+                $result = $this->createWidget_FolderList();
+                break;
             default:
                $result = '<font color="' . $color[2] . '">'
                        . sprintf(_("Option Type '%s' Not Found"), $this->type)
@@ -225,6 +229,38 @@ class SquirrelOption {
         return ($result);
     }
 
+    function createWidget_FolderList() {
+        $selected = array(strtolower($this->value));
+
+        /* Begin the select tag. */
+        $result = "<select name=\"new_$this->name\">";
+
+        /* Add each possible value to the select list. */
+        foreach ($this->possible_values as $real_value => $disp_value) {
+            if ( is_array($disp_value) ) { 
+              /* For folder list, we passed in the array of boxes.. */
+              $new_option = sqimap_mailbox_option_list(0, $selected, 0, $disp_value);
+            } else {
+              /* Start the next new option string. */
+              $new_option = "<option value=\"$real_value\"";
+  
+              /* If this value is the current value, select it. */
+              if ($real_value == $this->value) {
+                 $new_option .= ' selected';
+              }
+  
+              /* Add the display value to our option string. */
+              $new_option .= ">$disp_value</option>";
+            }
+            /* And add the new option string to our select tag. */
+            $result .= $new_option;
+        }        
+        /* Close the select tag and return our happy result. */
+        $result .= '</select>';
+        return ($result);
+    }
+
+
     function createWidget_TextArea() {
         switch ($this->size) {
             case SMOPT_SIZE_TINY:  $rows = 3; $cols =  10; break;

+ 2 - 0
include/load_prefs.php

@@ -244,6 +244,8 @@ $search_memory = getPref($data_dir, $username, 'search_memory', 0);
 
 $forward_cc = getPref($data_dir, $username, 'forward_cc', 0);
 
+$mailbox_select_style = getPref($data_dir, $username, 'mailbox_select_style', 0);
+
 do_hook('loading_prefs');
 
 ?>

+ 27 - 18
include/options/folder.php

@@ -13,10 +13,12 @@
 
 /* SquirrelMail required files. */
 require_once(SM_PATH . 'functions/imap.php');
+require_once(SM_PATH . 'functions/imap_general.php');
 
 /* Define the group constants for the folder options page. */   
 define('SMOPT_GRP_SPCFOLDER', 0);
 define('SMOPT_GRP_FOLDERLIST', 1);
+define('SMOPT_GRP_FOLDERSELECT', 2);
 
 /* Define the optpage load function for the folder options page. */
 function load_optpage_data_folder() {
@@ -52,43 +54,34 @@ function load_optpage_data_folder() {
         );
     }
 
-    $special_folder_values = array();
-    foreach ($boxes as $folder) {
-        if (strtolower($folder['unformatted']) != 'inbox') {
-            $real_value = $folder['unformatted-dm'];
-            $disp_value = str_replace(' ', '&nbsp;', $folder['formatted']);
-            $special_folder_values[$real_value] = $disp_value;
-        }
-    }
-
-    $trash_none = array(SMPREF_NONE => _("Do not use Trash"));
-    $trash_folder_values = array_merge($trash_none, $special_folder_values);
+    $trash_folder_values = array(SMPREF_NONE => '[ '._("Do not use Trash").' ]',
+                                 'whatever'  => $boxes);
     $optvals[SMOPT_GRP_SPCFOLDER][] = array(
         'name'    => 'trash_folder',
         'caption' => _("Trash Folder"),
-        'type'    => SMOPT_TYPE_STRLIST,
+        'type'    => SMOPT_TYPE_FLDRLIST,
         'refresh' => SMOPT_REFRESH_FOLDERLIST,
         'posvals' => $trash_folder_values,
         'save'    => 'save_option_trash_folder'
     );
     
-    $sent_none = array(SMPREF_NONE => _("Do not use Sent"));
-    $sent_folder_values = array_merge($sent_none, $special_folder_values);
+    $sent_folder_values = array(SMPREF_NONE => '[ '._("Do not use Sent").' ]',
+                                'whatever'  => $boxes);
     $optvals[SMOPT_GRP_SPCFOLDER][] = array(
         'name'    => 'sent_folder',
         'caption' => _("Sent Folder"),
-        'type'    => SMOPT_TYPE_STRLIST,
+        'type'    => SMOPT_TYPE_FLDRLIST,
         'refresh' => SMOPT_REFRESH_FOLDERLIST,
         'posvals' => $sent_folder_values,
         'save'    => 'save_option_sent_folder'
     );
     
-    $draft_none = array(SMPREF_NONE => _("Do not use Drafts"));
-    $draft_folder_values = array_merge($draft_none, $special_folder_values);
+    $draft_folder_values = array(SMPREF_NONE => '[ '._("Do not use Drafts").' ]',
+                                 'whatever'  => $boxes);
     $optvals[SMOPT_GRP_SPCFOLDER][] = array(
         'name'    => 'draft_folder',
         'caption' => _("Draft Folder"),
-        'type'    => SMOPT_TYPE_STRLIST,
+        'type'    => SMOPT_TYPE_FLDRLIST,
         'refresh' => SMOPT_REFRESH_FOLDERLIST,
         'posvals' => $draft_folder_values,
         'save'    => 'save_option_draft_folder'
@@ -211,6 +204,22 @@ function load_optpage_data_folder() {
                             9 => '9')
     );
 
+
+    /*** Load the General Options into the array ***/
+    $optgrps[SMOPT_GRP_FOLDERSELECT] = _("Folder Selection Options");
+    $optvals[SMOPT_GRP_FOLDERSELECT] = array();
+
+    $delim = sqimap_get_delimiter();
+    $optvals[SMOPT_GRP_FOLDERSELECT][] = array(
+        'name'    => 'mailbox_select_style',
+        'caption' => _("Selection List Style"),
+        'type'    => SMOPT_TYPE_STRLIST,
+        'refresh' => SMOPT_REFRESH_NONE,
+        'posvals' => array( 0 => _("Long: ") . '"Folder' . $delim . 'Subfolder"',
+                            1 => _("Indented: ") .  '"&nbsp;&nbsp;&nbsp;&nbsp;' . 'Subfolder"',
+                            2 => _("Delimited: ") . '".&nbsp;' . 'Subfolder"')
+    );
+
     /* Assemble all this together and return it as our result. */
     $result = array(
         'grps' => $optgrps,

+ 1 - 12
plugins/delete_move_next/setup.php

@@ -219,18 +219,7 @@ function delete_move_next_read($currloc) {
 
 function get_move_target_list() {
     global $imapConnection;
-
-    $boxes = sqimap_mailbox_list($imapConnection);
-    for ($i = 0; $i < count($boxes); $i++) {
-        if (!in_array('noselect', $boxes[$i]['flags'])) {
-            $box = $boxes[$i]['unformatted'];
-            $box2 = str_replace(' ', '&nbsp;', $boxes[$i]['unformatted-disp']);
-            if ( $box2 == 'INBOX' ) {
-                $box2 = _("INBOX");
-            }
-            echo "<option value=\"$box\">$box2</option>\n";
-        }
-    }
+    echo sqimap_mailbox_option_list($imapConnection);
 }
 
 function delete_move_next_moveNextForm($next) {

+ 14 - 47
src/folders.php

@@ -109,25 +109,17 @@ if ($default_sub_of_inbox == false) {
     echo '<OPTION VALUE="">[ '._("None")." ]\n";
 }
 
-for ($i = 0, $cnt=count($boxes); $i < $cnt; $i++) {
-    if (!in_array('noinferiors', $boxes[$i]['flags'])) {
-        if ((strtolower($boxes[$i]['unformatted']) == 'inbox') &&
-            $default_sub_of_inbox) {
-
-            $box = $boxes[$i]['unformatted'];
-            $box2 = str_replace(' ', '&nbsp;',
-                                imap_utf7_decode_local($boxes[$i]['unformatted-disp']));
-            echo "<OPTION SELECTED VALUE=\"$box\">$box2</option>\n";
-        } else {
-            $box = $boxes[$i]['unformatted'];
-            $box2 = str_replace(' ', '&nbsp;',
-                                imap_utf7_decode_local($boxes[$i]['unformatted-disp'])); 
-            if (strtolower($imap_server_type) != 'courier' ||
-                  strtolower($box) != "inbox.trash")
-                echo "<OPTION VALUE=\"$box\">$box2</option>\n";
-        }
-    }
+$show_selected = 0;
+if ( $default_sub_of_inbox ) {
+    $show_selected = array('inbox');
 }
+$skip_folders = 0;
+if ( strtolower($imap_server_type) == 'courier' ) {
+    $skip_folders = array('inbox.trash');
+}
+
+echo sqimap_mailbox_option_list($imapConnection, $show_selected, $skip_folders, $boxes, 'noinferiors');
+
 echo "</SELECT></TT>\n";
 if ($show_contain_subfolders_option) {
     echo '<br><input type=CHECKBOX NAME="contain_subs"> &nbsp;'
@@ -179,22 +171,9 @@ if ($count_special_folders < count($boxes)) {
     echo "<FORM ACTION=\"folders_rename_getname.php\" METHOD=\"POST\">\n"
        . "<TT><SELECT NAME=old>\n"
        . '         <OPTION VALUE="">[ ' . _("Select a folder") . " ]</OPTION>\n";
-    for ($i = 0; $i < count($boxes); $i++) {
-        $use_folder = true;
 
-        if ((strtolower($boxes[$i]['unformatted']) != 'inbox') &&
-            ($boxes[$i]['unformatted'] != $trash_folder)  &&
-            ($boxes[$i]['unformatted'] != $sent_folder) &&
-            ($boxes[$i]['unformatted'] != $draft_folder)) {
-            $box = $boxes[$i]['unformatted-dm'];
+    echo sqimap_mailbox_option_list($imapConnection, 0, $skip_folders, $boxes);
 
-            $box2 = str_replace(' ', '&nbsp;',
-                                imap_utf7_decode_local($boxes[$i]['unformatted-disp']));
-            if (strtolower($imap_server_type) != 'courier' || strtolower($box) != 'inbox.trash') {
-                echo "<OPTION VALUE=\"$box\">$box2</option>\n";
-            }
-        }
-    }
     echo "</SELECT></TT>\n".
          "<input type=SUBMIT VALUE=\"".
          _("Rename").
@@ -220,21 +199,9 @@ if ($count_special_folders < count($boxes)) {
     echo "<FORM ACTION=\"folders_delete.php\" METHOD=\"POST\">\n"
        . "<TT><SELECT NAME=mailbox>\n"
        . '         <OPTION VALUE="">[ ' . _("Select a folder") . " ]</OPTION>\n";
-    for ($i = 0; $i < count($boxes); $i++) {
-        $use_folder = true;
-        if ((strtolower($boxes[$i]['unformatted']) != 'inbox') &&
-            ($boxes[$i]['unformatted'] != $trash_folder) &&
-            ($boxes[$i]['unformatted'] != $sent_folder) &&
-            ($boxes[$i]['unformatted'] != $draft_folder) &&
-            (!in_array('noselect', $boxes[$i]['flags'])) &&
-            ((strtolower($imap_server_type) != 'courier') ||
-             (strtolower($boxes[$i]['unformatted']) != 'inbox.trash'))) {
-            $box = $boxes[$i]['unformatted-dm'];
-            $box2 = str_replace(' ', '&nbsp;',
-                                imap_utf7_decode_local($boxes[$i]['unformatted-disp']));
-            echo "         <OPTION VALUE=\"$box\">$box2</option>\n";
-        }
-    }
+
+    echo sqimap_mailbox_option_list($imapConnection, 0, $skip_folders, $boxes);
+
     echo "</SELECT></TT>\n"
        . '<input type=SUBMIT VALUE="'
        . _("Delete")

+ 12 - 21
src/search.php

@@ -436,27 +436,18 @@ echo html_tag( 'div', '<b>' . _("Current Search") . '</b>', 'left' ) . "\n"
    . html_tag( 'table', '', '', '', 'width="95%" cellpadding="0" cellspacing="0" border="0"' )
    . html_tag( 'tr' )
    . html_tag( 'td', '', 'left' )
-   . '<select name="mailbox">';
-for ($i = 0; $i < count($boxes); $i++) {
-    if (!in_array('noselect', $boxes[$i]['flags'])) {
-        $box = $boxes[$i]['unformatted'];
-        $box2 = str_replace(' ', '&nbsp;', 
-                         imap_utf7_decode_local($boxes[$i]['unformatted-disp']));
-        if( $box2 == 'INBOX' ) {
-            $box2 = _("INBOX");
-        }
-        echo '         <option value="' . $box . '"';
-        if ($mailbox == $box) { echo ' selected'; }
-        echo '>' . $box2 . '</option>' . "\n";
-    }
-}
-        echo '<option value="All Folders"';
-        if ($mailbox == 'All Folders') {
-            echo ' selected';
-        }
-        echo ">All folders</option>\n";
-echo '         </select>'.
-     "       </td>\n";
+   . '<select name="mailbox">'
+   . '<option value="All Folders"';
+   if ($mailbox == 'All Folders') {
+       echo ' selected';
+   }
+   echo ">[ All Folders ]</option>\n";
+
+   $show_selected = array(strtolower($mailbox));
+   echo sqimap_mailbox_option_list($imapConnection, $show_selected, 0, $boxes);
+
+   echo '         </select>'.
+        "       </td>\n";
 if ( !isset( $what ) ) {
     $what = '';
 }