added flag related functions for handling sets of messages instead of using
[squirrelmail.git] / functions / imap_general.php
index f658073f161d06c8e6c6f885328f8332e9286f5e..8575e7eb032b8be65c87ae277caf46b6b319e2cf 100755 (executable)
@@ -31,17 +31,41 @@ function sqimap_session_id($unique_id = false) {
  * This is to allow proper session number handling.
  */
 function sqimap_run_command_list ($imap_stream, $query, $handle_errors, &$response, &$message, $unique_id = false) {
-    $sid = sqimap_session_id($unique_id);
-    fputs ($imap_stream, $sid . ' ' . $query . "\r\n");
-    $read = sqimap_read_data_list ($imap_stream, $sid, $handle_errors, $response, $message, $query );
-    return $read;
+    if ($imap_stream) {
+       $sid = sqimap_session_id($unique_id);
+       fputs ($imap_stream, $sid . ' ' . $query . "\r\n");
+       $read = sqimap_read_data_list ($imap_stream, $sid, $handle_errors, $response, $message, $query );
+       return $read;
+    } else {
+        global $squirrelmail_language, $color;
+        set_up_language($squirrelmail_language);
+        require_once(SM_PATH . 'functions/display_messages.php');
+        $string = "<b><font color=$color[2]>\n" .
+                _("ERROR : No available imapstream.") .
+                "</b></font>\n";
+        error_box($string,$color);
+       return false;
+    }
+    
 }
 
 function sqimap_run_command ($imap_stream, $query, $handle_errors, &$response, &$message, $unique_id = false) {
-    $sid = sqimap_session_id($unique_id);
-    fputs ($imap_stream, $sid . ' ' . $query . "\r\n");
-    $read = sqimap_read_data ($imap_stream, $sid, $handle_errors, $response, $message, $query);
-    return $read;
+    if ($imap_stream) {
+        $sid = sqimap_session_id($unique_id);
+       fputs ($imap_stream, $sid . ' ' . $query . "\r\n");
+       $read = sqimap_read_data ($imap_stream, $sid, $handle_errors, $response, $message, $query);
+       return $read;
+    } else {
+        global $squirrelmail_language, $color;
+        set_up_language($squirrelmail_language);
+        require_once(SM_PATH . 'functions/display_messages.php');
+        $string = "<b><font color=$color[2]>\n" .
+                _("ERROR : No available imapstream.") .
+                "</b></font>\n";
+        error_box($string,$color);
+       return false;
+    }
+    
 }
 
 
@@ -186,13 +210,6 @@ function sqimap_login ($username, $password, $imap_server_address, $imap_port, $
     $imap_server_address = sqimap_get_user_server($imap_server_address, $username);
 
     $imap_stream = fsockopen ( $imap_server_address, $imap_port, $error_number, $error_string, 15);
-    if ( !$imap_stream ) {
-        return false;
-    }
-    $server_info = fgets ($imap_stream, 1024);
-
-    /* Decrypt the password */
-    $password = OneTimePadDecrypt($password, $onetimepad);
 
     /* Do some error correction */
     if (!$imap_stream) {
@@ -202,11 +219,16 @@ function sqimap_login ($username, $password, $imap_server_address, $imap_port, $
            $string = sprintf (_("Error connecting to IMAP server: %s.") .
                              "<br>\r\n", $imap_server_address) .
                       "$error_number : $error_string<br>\r\n";
-           error_box($string,$color);
+           logout_error($string,$color);
         }
         exit;
     }
 
+    $server_info = fgets ($imap_stream, 1024);
+
+    /* Decrypt the password */
+    $password = OneTimePadDecrypt($password, $onetimepad);
+
     $query = 'LOGIN "' . quoteIMAP($username) .  '" "' . quoteIMAP($password) . '"';
     $read = sqimap_run_command ($imap_stream, $query, false, $response, $message);
 
@@ -449,20 +471,36 @@ function sqimap_append ($imap_stream, $sent_folder, $length) {
     $tmp = fgets ($imap_stream, 1024);
 }
 
-function sqimap_append_done ($imap_stream) {
+function sqimap_append_done ($imap_stream, $folder='') {
     global $squirrelmail_language, $color;
     fputs ($imap_stream, "\r\n");
     $tmp = fgets ($imap_stream, 1024);
     if (preg_match("/(.*)(BAD|NO)(.*)$/", $tmp, $regs)) {
         set_up_language($squirrelmail_language);
         require_once(SM_PATH . 'functions/display_messages.php');
-        $string = "<b><font color=$color[2]>\n" .
+       $reason = $regs[3];
+       if ($regs[2] == 'NO') {
+          $string = "<b><font color=$color[2]>\n" .
+                 _("ERROR : Could not append message to") ." $folder." .
+                 "</b><br>\n" .
+                 _("Server responded: ") .
+                 $reason . "<br>\n";
+          if (preg_match("/(.*)(quota)(.*)$/i", $reason, $regs)) {
+             $string .= _("Solution: ") . 
+           _("Remove unneccessary messages from your folder and start with your Trash folder.") 
+             ."<br>\n";
+          }
+          $string .= "</font>\n";
+          error_box($string,$color);
+       } else {
+           $string = "<b><font color=$color[2]>\n" .
                  _("ERROR : Bad or malformed request.") .
                  "</b><br>\n" .
                  _("Server responded: ") .
                  $tmp . "</font><br>\n";
-       error_box($string,$color);
-        exit;
+          error_box($string,$color);
+           exit;
+       }
     }
 }