浏览代码

add $no_list_for_subscribe configure option to turn off generation of
the list of available folders in the subscription dialog

robsiemb 23 年之前
父节点
当前提交
0a331297ee
共有 4 个文件被更改,包括 52 次插入14 次删除
  1. 2 1
      config/conf.pl
  2. 8 0
      config/config_default.php
  3. 24 10
      src/folders.php
  4. 18 3
      src/folders_subscribe.php

+ 2 - 1
config/conf.pl

@@ -2407,7 +2407,6 @@ sub save_data {
         print CF "\$allow_charset_search     = $allow_charset_search;\n";
         print CF "\$allow_charset_search     = $allow_charset_search;\n";
         # boolean
         # boolean
         print CF "\$uid_support              = $uid_support;\n";
         print CF "\$uid_support              = $uid_support;\n";
-	# boolean
         print CF "\n";
         print CF "\n";
 	
 	
 	# all plugins are strings
 	# all plugins are strings
@@ -2475,6 +2474,8 @@ sub save_data {
         print CF "\$prefs_key_field = '$prefs_key_field';\n";
         print CF "\$prefs_key_field = '$prefs_key_field';\n";
 	# string
 	# string
         print CF "\$prefs_val_field = '$prefs_val_field';\n";
         print CF "\$prefs_val_field = '$prefs_val_field';\n";
+	# boolean
+	print CF "\$no_list_for_subscribe = $no_list_for_subscribe;\n";
         print CF "\n";
         print CF "\n";
 
 
         print CF "/**\n";
         print CF "/**\n";

+ 8 - 0
config/config_default.php

@@ -500,6 +500,14 @@ $allow_server_sort = false;
 global $noselect_fix_enable;
 global $noselect_fix_enable;
 $noselect_fix_enable = false;
 $noselect_fix_enable = false;
 
 
+/**
+ * this disables listing all of the folders on the IMAP Server to
+ * generate the folder subscribe listbox (this can take a long time
+ * when you have a lot of folders).  Instead, a textbox will be
+ * displayed allowing users to enter a specific folder name to subscribe to */
+global $no_list_for_subscribe;
+$no_list_for_subscribe = false;
+
 /**
 /**
  * Make sure there are no characters after the PHP closing
  * Make sure there are no characters after the PHP closing
  * tag below (including newline characters and whitespace).
  * tag below (including newline characters and whitespace).

+ 24 - 10
src/folders.php

@@ -43,6 +43,10 @@ if ((isset($success) && $success) ||
         $td_str = "<b>" . _("Created folder successfully!") . "</b><br>";
         $td_str = "<b>" . _("Created folder successfully!") . "</b><br>";
     } else if ($success == "rename") {
     } else if ($success == "rename") {
         $td_str = "<b>" . _("Renamed successfully!") . "</b><br>";
         $td_str = "<b>" . _("Renamed successfully!") . "</b><br>";
+    } else if ($success == "subscribe-doesnotexist") {
+        $td_str = "<b>" .
+                  _("Subscription Unsuccessful - Folder does not exist.") .
+                  "</b><br>";
     }
     }
 
 
     echo html_tag( 'table',
     echo html_tag( 'table',
@@ -252,12 +256,14 @@ $boxes_sub = $boxes;
 
 
 /** SUBSCRIBE TO FOLDERS **/
 /** SUBSCRIBE TO FOLDERS **/
 echo html_tag( 'td', '', 'center', $color[0], 'width="50%"' );
 echo html_tag( 'td', '', 'center', $color[0], 'width="50%"' );
-$imap_stream = sqimap_login ($username, $key, $imapServerAddress, $imapPort, 1);
-$boxes_all = sqimap_mailbox_list_all ($imap_stream);
-
-$box = "";
-$box2 = "";
-for ($i = 0, $q = 0; $i < count($boxes_all); $i++) {
+if(!$no_list_for_subscribe) {
+  $imap_stream = sqimap_login ($username, $key, $imapServerAddress,
+                               $imapPort, 1);
+  $boxes_all = sqimap_mailbox_list_all ($imap_stream);
+
+  $box = "";
+  $box2 = "";
+  for ($i = 0, $q = 0; $i < count($boxes_all); $i++) {
     $use_folder = true;
     $use_folder = true;
     for ($p = 0; $p < count ($boxes); $p++) {
     for ($p = 0; $p < count ($boxes); $p++) {
         if ($boxes_all[$i]["unformatted"] == $boxes[$p]["unformatted"]) {
         if ($boxes_all[$i]["unformatted"] == $boxes[$p]["unformatted"]) {
@@ -272,10 +278,10 @@ for ($i = 0, $q = 0; $i < count($boxes_all); $i++) {
         $box2[$q] = imap_utf7_decode_local($boxes_all[$i]["unformatted-disp"]);
         $box2[$q] = imap_utf7_decode_local($boxes_all[$i]["unformatted-disp"]);
         $q++;
         $q++;
     }
     }
-}
-sqimap_logout($imap_stream);
+  }
+  sqimap_logout($imap_stream);
 
 
-if ($box && $box2) {
+  if ($box && $box2) {
     echo "<FORM ACTION=\"folders_subscribe.php?method=sub\" METHOD=\"POST\">\n";
     echo "<FORM ACTION=\"folders_subscribe.php?method=sub\" METHOD=\"POST\">\n";
     echo "<tt><select name=\"mailbox[]\" multiple size=8>";
     echo "<tt><select name=\"mailbox[]\" multiple size=8>";
 
 
@@ -285,8 +291,16 @@ if ($box && $box2) {
     echo "</select></tt><br><br>";
     echo "</select></tt><br><br>";
     echo "<input type=SUBMIT VALUE=\"". _("Subscribe") . "\">\n";
     echo "<input type=SUBMIT VALUE=\"". _("Subscribe") . "\">\n";
     echo "</FORM></td></tr></table><BR>\n";
     echo "</FORM></td></tr></table><BR>\n";
-} else {
+  } else {
     echo _("No folders were found to subscribe to!") . "</td></tr></table>";
     echo _("No folders were found to subscribe to!") . "</td></tr></table>";
+  }
+} else {
+  /* don't perform the list action -- this is much faster */
+  echo "<FORM ACTION=\"folders_subscribe.php?method=sub\" METHOD=\"POST\">\n";
+  echo _("Subscribe to:") . "<br>";
+  echo "<tt><input type=\"text\" name=\"mailbox[]\" size=35>";
+  echo "<INPUT TYPE=SUBMIT VALUE=\"". _("Subscribe") . "\">\n";
+  echo "</FORM></TD></TR></TABLE><BR>\n";
 }
 }
 
 
 do_hook("folders_bottom");
 do_hook("folders_bottom");

+ 18 - 3
src/folders_subscribe.php

@@ -19,7 +19,25 @@ require_once('../functions/display_messages.php');
 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
 
 
 $location = get_location();
 $location = get_location();
+
+if (!isset($mailbox) || !isset($mailbox[0]) || $mailbox[0] == "") {
+    header("Location: $location/folders.php");
+    sqimap_logout($imapConnection);
+    exit(0);
+}
+
 if ($method == 'sub') {
 if ($method == 'sub') {
+    if($no_list_for_subscribe && $imap_server_type == 'cyrus') {
+       /* Cyrus, atleast, does not typically allow subscription to
+	* nonexistent folders (this is an optional part of IMAP),
+        * lets catch it here and report back cleanly. */
+       if(!sqimap_mailbox_exists($imapConnection, $mailbox[0])) {
+          header("Location: $location/folders.php?success=subscribe-doesnotexist");
+          sqimap_logout($imapConnection);
+          exit(0);
+       }
+    }
+
     for ($i=0; $i < count($mailbox); $i++) {
     for ($i=0; $i < count($mailbox); $i++) {
         $mailbox[$i] = trim($mailbox[$i]);
         $mailbox[$i] = trim($mailbox[$i]);
         sqimap_subscribe ($imapConnection, $mailbox[$i]);
         sqimap_subscribe ($imapConnection, $mailbox[$i]);
@@ -32,9 +50,6 @@ if ($method == 'sub') {
         header("Location: $location/folders.php?success=unsubscribe");
         header("Location: $location/folders.php?success=unsubscribe");
     }
     }
 }
 }
-if (!isset($mailbox)) {
-    header("Location: $location/folders.php");
-}
 sqimap_logout($imapConnection);
 sqimap_logout($imapConnection);
 
 
 /*
 /*