added checking to see if php was compiled --with-gettext or not
[squirrelmail.git] / functions / imap.php
index 0362e32c97e5a61366bb964ae670d7d92985da80..190df98f4999fca0473ed3f5944ec7d63dd7d59c 100644 (file)
       fputs($imapConnection, ". list \"\" \"\"\n");
       $read = fgets($imapConnection, 1024);
 
-      $pos = strrpos($read, "\"");
-      $read = substr($read, 0, $pos);
-
-      $pos = strrpos($read, "\"");
-      $read = substr($read, 0, $pos);
+      if (strrpos($read, "\"") == strlen($read)) {
+         $pos = strrpos($read, "\"");
+         $read = substr($read, 0, $pos);
 
+         $pos = strrpos($read, "\"");
+         $read = substr($read, 0, $pos);
+      } else {
+         $pos = strrpos($read, " ");
+         $read = substr($read, 0, $pos);
+      }
+   
       $pos = strrpos($read, "\"");
       $read = substr($read, 0, $pos);
 
       $serverInfo = fgets($imapConnection, 256);
  
       // login
-      fputs($imapConnection, "a001 LOGIN $username $key\n");
+      fputs($imapConnection, "a001 LOGIN \"$username\" \"$key\"\n");
       $read = fgets($imapConnection, 1024);
       if ($debug_login == true) {
          echo "SERVER SAYS: $read<BR>";
       }
 
+      /** If the login attempt was UNsuccessful, lets see why **/
       if (substr($read, 0, 7) != "a001 OK") {
          if (!$hide) {
             if (substr($read, 0, 8) == "a001 BAD") {
                exit;
             }
             else if (substr($read, 0, 7) == "a001 NO") {
-               echo "<BR>";
-               echo "<TABLE COLS=1 WIDTH=70% NOBORDER BGCOLOR=\"$color[4]\" ALIGN=CENTER>";
+               echo "<HTML><BODY BGCOLOR=FFFFFF><BR>";
+               echo "<TABLE COLS=1 WIDTH=70% NOBORDER BGCOLOR=FFFFFF ALIGN=CENTER>";
                echo "   <TR>";
-               echo "      <TD BGCOLOR=\"$color[0]\">";
-               echo "         <FONT FACE=\"Arial,Helvetica\" COLOR=\"$color[2]\"><B><CENTER>ERROR</CENTER></B></FONT>";
+               echo "      <TD BGCOLOR=\"DCDCDC\">";
+               echo "         <FONT FACE=\"Arial,Helvetica\" COLOR=CC0000><B><CENTER>ERROR</CENTER></B></FONT>";
                echo "   </TD></TR><TR><TD>";
                echo "      <CENTER><FONT FACE=\"Arial,Helvetica\"><BR>Unknown user or password incorrect.<BR><A HREF=\"login.php\" TARGET=_top>Click here to try again</A>.</FONT></CENTER>";
                echo "   </TD></TR>";
          echo "<B><FONT FACE=\"Arial,Helvetica\" COLOR=FF0000>ERROR</FONT FACE=\"Arial,Helvetica\"><FONT FACE=\"Arial,Helvetica\" COLOR=CC0000>:  Bad or malformed request.</B></FONT FACE=\"Arial,Helvetica\"><BR><FONT FACE=\"Arial,Helvetica\" COLOR=CC0000>&nbsp;&nbsp;<B>Server responded:</B> $message</FONT FACE=\"Arial,Helvetica\"><BR><BR>";
          exit;
       }
+      fputs($imapConnection, "1 SUBSCRIBE \"$folder\"\n");
+      $data = imapReadData($imapConnection, "1", true, $response, $message);
    }
 
    function removeFolder($imapConnection, $folder) {
    function getFolderList($imapConnection, &$boxes) {
       require ("../config/config.php");
 
-      fputs($imapConnection, "1 list \"\" *\n");
+      /** First we get the inbox **/
+      fputs($imapConnection, "1 LIST \"\" INBOX\n");
       $str = imapReadData($imapConnection, "1", true, $response, $message);
-
       $dm = findMailboxDelimeter($imapConnection);
       $g = 0;
       for ($i = 0;$i < count($str); $i++) {
          }
       }
 
+      /** Next, we get all subscribed folders **/
+      fputs($imapConnection, "1 LSUB \"\" *\n");
+      $str = imapReadData($imapConnection, "1", true, $response, $message);
+      $dm = findMailboxDelimeter($imapConnection);
+      for ($i = 0;$i < count($str); $i++) {
+         $mailbox = chop($str[$i]);
+         if (substr(findMailboxName($mailbox), 0, 1) != ".") {
+            $boxes[$g]["RAW"] = $mailbox;
+
+            $mailbox = findMailboxName($mailbox);
+            $periodCount = countCharInString($mailbox, $dm);
+
+            // indent the correct number of spaces.
+            for ($j = 0;$j < $periodCount;$j++)
+               $boxes[$g]["FORMATTED"] = $boxes[$g]["FORMATTED"] . "&nbsp;&nbsp;";
+
+            $boxes[$g]["FORMATTED"] = $boxes[$g]["FORMATTED"] . readShortMailboxName($mailbox, $dm);
+            $boxes[$g]["UNFORMATTED"] = $mailbox;
+            $boxes[$g]["ID"] = $g;
+            $g++;
+         }
+      }
+
       $original = $boxes;
 
       for ($i = 0; $i < count($original); $i++) {
       } else {
          setMessageFlag($imapConnection, $a, $b, "Deleted");
       }
+      if ($auto_expunge == true)
+         expungeBox($imapConnection, $mailbox);
    }
+
    function stripComments($line) {
       if (strpos($line, ";")) {
          $line = substr($line, 0, strpos($line, ";"));