ソースを参照

Added unsubscribe/subscribe to folders

Luke Ehresman 25 年 前
コミット
1e4e3d6ba0
3 ファイル変更128 行追加3 行削除
  1. 3 3
      TODO
  2. 53 0
      functions/imap_mailbox.php
  3. 72 0
      src/folders.php

+ 3 - 3
TODO

@@ -15,12 +15,12 @@ initials = taken by that person
   -     Better inline HTML support including graphics (content-disposition)
   -     Maybe a rewrite of mime.php (see Gustav before any work is done)
   -     Better handling emptying Trash folder.  Some servers don't allow deleting it (Courier)
-(lme)   Fix "Seen" bug with UW IMAP server
-  -     Add "subscribe" to folders section.
+(lme)   Add "subscribe" to folders section.
   -     Make Location redirects absolute rather than relative (index.php)
   -     POP suport (maybe)
 
 
 Finished:
 ------------------------------------------------------
- (lme)  Saving sent messages
+(lme)   Saving sent messages
+(lme)   Fix "Seen" bug with UW IMAP server

+ 53 - 0
functions/imap_mailbox.php

@@ -198,5 +198,58 @@
 
       return $boxesnew;
    }
+
+   
+   /******************************************************************************
+    **  Returns a list of all folders, subscribed or not
+    ******************************************************************************/
+   function sqimap_mailbox_list_all ($imap_stream) {
+      global $special_folders, $list_special_folders_first;
+      
+      if (!function_exists ("ary_sort"))
+         include ("../functions/array.php");
+      
+      $dm = sqimap_get_delimiter ($imap_stream);
+
+      fputs ($imap_stream, "a001 LIST \"\" *\r\n");
+      $read_ary = sqimap_read_data ($imap_stream, "a001", true, $response, $message);
+      $g = 0;
+      $phase = "inbox"; 
+      for ($i = 0; $i < count($read_ary); $i++) {
+         if (substr ($read_ary[$i], 0, 4) != "a001") {
+            $boxes[$g]["raw"] = $read_ary[$i];
+
+            $mailbox = find_mailbox_name($read_ary[$i]);
+            $dm_count = countCharInString($mailbox, $dm);
+            if (substr($mailbox, -1) == $dm)
+               $dm_count--;
+               
+            for ($j = 0; $j < $dm_count; $j++)
+               $boxes[$g]["formatted"] = $boxes[$g]["formatted"] . "  ";
+            $boxes[$g]["formatted"] .= readShortMailboxName($mailbox, $dm);
+               
+            $boxes[$g]["unformatted-dm"] = $mailbox;
+            if (substr($mailbox, -1) == $dm)
+               $mailbox = substr($mailbox, 0, strlen($mailbox) - 1);
+            $boxes[$g]["unformatted"] = $mailbox;
+            $boxes[$g]["id"] = $g;
+
+            /** Now lets get the flags for this mailbox **/
+            fputs ($imap_stream, "a002 LIST \"\" \"$mailbox\"\r\n"); 
+            $read_mlbx = sqimap_read_data ($imap_stream, "a002", true, $response, $message);
+
+            $flags = substr($read_mlbx[0], strpos($read_mlbx[0], "(")+1);
+            $flags = substr($flags, 0, strpos($flags, ")"));
+            $flags = str_replace("\\", "", $flags);
+            $flags = trim(strtolower($flags));
+            if ($flags) {
+               $boxes[$g]["flags"] = explode(" ", $flags);
+            }
+         }
+         $g++;
+      }
+      $boxes = ary_sort ($boxes, "unformatted", 1);
+      return $boxes;
+   }
    
 ?>

+ 72 - 0
src/folders.php

@@ -146,6 +146,78 @@
       echo "<INPUT TYPE=SUBMIT VALUE=\"";
       echo _("Rename");
       echo "\">\n";
+      echo "</FORM></TD></TR>\n";
+   } else {
+      echo _("No mailboxes found") . "<br><br></td></tr>";
+   }
+   $boxes_sub = $boxes;
+   
+   /** UNSUBSCRIBE FOLDERS **/
+   echo "<TR><TD BGCOLOR=\"$color[0]\" ALIGN=CENTER><B>";
+   echo _("Unsubscribe/Subscribe");
+   echo "</B></TD></TR>";
+   echo "<TR><TD BGCOLOR=\"$color[4]\" ALIGN=CENTER>";
+   if ($count_special_folders < count($boxes)) {
+      echo "<FORM ACTION=\"folders_subscribe.php?method=unsub\" METHOD=POST>\n";
+      echo "<TT><SELECT NAME=mailbox>\n";
+      for ($i = 0; $i < count($boxes); $i++) {
+         $use_folder = true;
+         for ($p = 0; $p < count($special_folders); $p++) {
+            if ($boxes[$i]["unformatted"] == $special_folders[$p]) {
+               $use_folder = false;
+            } else if (substr($boxes[$i]["unformatted"], 0, strlen($trash_folder)) == $trash_folder) {
+               $use_folder = false;
+            }
+         }
+         if ($use_folder == true) {
+            $box = $boxes[$i]["unformatted-dm"];
+            $box2 = replace_spaces($boxes[$i]["formatted"]);
+            echo "         <OPTION VALUE=\"$box\">$box2\n";
+         }
+      }
+      echo "</SELECT></TT>\n";
+      echo "<INPUT TYPE=SUBMIT VALUE=\"";
+      echo _("Unsubscribe");
+      echo "\">\n";
+      echo "</FORM></TD></TR>\n";
+   } else {
+      echo _("No mailboxes found") . "<br><br></td></tr>";
+   }
+   $boxes_sub = $boxes;
+   
+   /** SUBSCRIBE TO FOLDERS **/
+
+   echo "<TR><TD BGCOLOR=\"$color[4]\" ALIGN=CENTER>";
+   if ($count_special_folders < count($boxes)) {
+      $imap_stream = sqimap_login ($username, $key, $imapServerAddress, $imapPort, 1);
+      $boxes = sqimap_mailbox_list_all ($imap_stream);
+      
+      echo "<FORM ACTION=\"folders_subscribe.php?method=sub\" METHOD=POST>\n";
+      echo "<TT><SELECT NAME=mailbox>\n";
+      for ($i = 0; $i < count($boxes); $i++) {
+         $use_folder = true;
+         for ($p = 0; $p < count($special_folders); $p++) {
+            if ($boxes[$i]["unformatted"] == $special_folders[$p]) {
+               $use_folder = false;
+            } else if (substr($boxes[$i]["unformatted"], 0, strlen($trash_folder)) == $trash_folder) {
+               $use_folder = false;
+            }
+
+            for ($q = 0; $q < count($boxes_sub); $q++) {
+               if ($boxes[$i]["unformatted"] == $boxes_sub[$q]["unformatted"]) 
+                  $use_folder = false;
+            }
+         }
+         if ($use_folder == true) {
+            $box = $boxes[$i]["unformatted-dm"];
+            $box2 = replace_spaces($boxes[$i]["formatted"]);
+            echo "         <OPTION VALUE=\"$box\">$box2\n";
+         }
+      }
+      echo "</SELECT></TT>\n";
+      echo "<INPUT TYPE=SUBMIT VALUE=\"";
+      echo _("Subscribe");
+      echo "\">\n";
       echo "</FORM></TD></TR></TABLE><BR>\n";
    } else {
       echo _("No mailboxes found") . "<br><br></td></tr></table>";