added step for copying config_default.php to config.php
[squirrelmail.git] / functions / imap.php
index 667d9c4be1cd86865bfc729907427ed3580803d2..267bce91a9659f010d9ab9905b000498c241c490 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>";
    /** Sends back two arrays, boxesFormatted and boxesUnformatted **/
    function getFolderList($imapConnection, &$boxes) {
       require ("../config/config.php");
+      if (!function_exists("ary_sort"))
+         include("../functions/array.php");
 
       /** First we get the inbox **/
       fputs($imapConnection, "1 LIST \"\" INBOX\n");
 
    function deleteMessages($imapConnection, $a, $b, $numMessages, $trash_folder, $move_to_trash, $auto_expunge, $mailbox) {
       /** check if they would like to move it to the trash folder or not */
-      if ($move_to_trash == true) {
+      if (($move_to_trash == true) && (folderExists($imapConnection, $trash_folder))) {
          $success = copyMessages($imapConnection, $a, $b, $trash_folder);
          if ($success == true)
             setMessageFlag($imapConnection, $a, $b, "Deleted");
       } 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, ";"));
       }
       return $full_line;
    }
+
+   function folderExists($imapConnection, $folderName) {
+      getFolderList($imapConnection, $folders);
+      $found = false;
+      for ($i = 0; ($i < count($folders)) && (!$found); $i++) {
+         if ($folders[$i]["UNFORMATTED"] == $folderName)
+            $found = true;
+      }
+      return $found;
+   }
 ?>