Better error reporting
authorstekkel <stekkel@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Wed, 8 Feb 2006 08:00:10 +0000 (08:00 +0000)
committerstekkel <stekkel@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Wed, 8 Feb 2006 08:00:10 +0000 (08:00 +0000)
git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@10659 7612ce4b-ef26-0410-bec9-ea0150e637f0

functions/imap_general.php
functions/imap_messages.php

index e45f5d41b1eb3dd4c072fc43690e7739c49ab242..7551cbaf18365df65138ea39f097ee55d3317c89 100755 (executable)
@@ -701,28 +701,28 @@ function sqimap_create_stream($server,$port,$tls=0) {
                 // starttls was successful
 
                 /**
-                 * RFC 2595 requires to discard CAPABILITY information after successful 
-                 * STARTTLS command. We don't follow RFC, because SquirrelMail stores CAPABILITY 
-                 * information only after successful login (src/redirect.php) and cached information 
-                 * is used only in other php script connections after successful STARTTLS. If script 
-                 * issues sqimap_capability() call before sqimap_login() and wants to get initial 
-                 * capability response, script should set third sqimap_capability() argument to false. 
+                 * RFC 2595 requires to discard CAPABILITY information after successful
+                 * STARTTLS command. We don't follow RFC, because SquirrelMail stores CAPABILITY
+                 * information only after successful login (src/redirect.php) and cached information
+                 * is used only in other php script connections after successful STARTTLS. If script
+                 * issues sqimap_capability() call before sqimap_login() and wants to get initial
+                 * capability response, script should set third sqimap_capability() argument to false.
                  */
-                //sqsession_unregister('sqimap_capabilities');            
+                //sqsession_unregister('sqimap_capabilities');
             } else {
                 /**
                  * stream_socket_enable_crypto() call failed. Possible issues:
                  * - broken ssl certificate (uw drops connection, error is in syslog mail facility)
-                 * - some ssl error (can reproduce with STREAM_CRYPTO_METHOD_SSLv3_CLIENT, PHP E_WARNING 
+                 * - some ssl error (can reproduce with STREAM_CRYPTO_METHOD_SSLv3_CLIENT, PHP E_WARNING
                  *   suppressed in stream_socket_enable_crypto() call)
                  */
                 sqimap_error_box(sprintf(_("Error connecting to IMAP server: %s."), $server),
                                  '','',
                                  _("Unable to start TLS."));
                 /**
-                 * Bug: stream_socket_enable_crypto() does not register SSL errors in 
-                 * openssl_error_string() or stream notification wrapper and displays 
-                 * them in E_WARNING level message. It is impossible to retrieve error 
+                 * Bug: stream_socket_enable_crypto() does not register SSL errors in
+                 * openssl_error_string() or stream notification wrapper and displays
+                 * them in E_WARNING level message. It is impossible to retrieve error
                  * message without own error handler.
                  */
                 exit;
@@ -932,7 +932,7 @@ function sqimap_logout ($imap_stream) {
  * else returns array of all capabilities.
  * @param stream $imap_stream
  * @param string $capability (since 1.3.0)
- * @param boolean $bUseCache (since 1.5.1) Controls use of capability data stored in session 
+ * @param boolean $bUseCache (since 1.5.1) Controls use of capability data stored in session
  * @return mixed (string if $capability is set and found,
  *  false, if $capability is set and not found,
  *  array if $capability not set)
@@ -1179,7 +1179,7 @@ function sqimap_append_done ($imap_stream, $folder='') {
  * @since 1.5.1 and 1.4.5
  */
 function sqimap_append_checkresponse($response, $folder) {
-
+    // TODO use error handler, see how sort and thread errors are handled and see errors.php
     if (preg_match("/(.*)(BAD|NO)(.*)$/", $response, $regs)) {
         global $squirrelmail_language, $color;
         set_up_language($squirrelmail_language);
index 2bdf5e79f3b9d1f88a22043867b7f8479059fbf3..05fc99d74f3e0278c1d24ba526569d6649cafd89 100755 (executable)
@@ -165,13 +165,20 @@ function sqimap_get_sort_order($imap_stream, $sSortField, $reverse, $search='ALL
         // use sqimap_run_command_list in case of unsollicited responses. If we don't we could loose the SORT response
         $aData = sqimap_run_command_list ($imap_stream, $query, false, $response, $message, TRUE);
         /* fallback to default charset */
-        if ($response == 'NO' && strpos($message,'[BADCHARSET]') !== false) {
-            $query = "SORT ($sSortField) US-ASCII $search";
-            $aData = sqimap_run_command_list ($imap_stream, $query, true, $response, $message, TRUE);
+        if ($response == 'NO') {
+            if (strpos($message,'[BADCHARSET]') !== false ||
+                strpos($message,'Unrecognized character set') !== false) {
+                sqm_trigger_imap_error('SQM_IMAP_BADCHARSET',$query, $response, $message);
+                $query = "SORT ($sSortField) US-ASCII $search";
+                $aData = sqimap_run_command_list ($imap_stream, $query, true, $response, $message, TRUE);
+            } else {
+                sqm_trigger_imap_error('SQM_IMAP_ERROR',$query, $response, $message);
+            }
+        } else if ($response == 'BAD') {
+            sqm_trigger_imap_error('SQM_IMAP_NO_SORT',$query, $response, $message);
         }
     }
 
-
     if ($response == 'OK') {
         return parseUidList($aData,'SORT');
     } else {
@@ -428,11 +435,21 @@ function get_thread_sort($imap_stream, $search='ALL') {
     }
     $query = "THREAD $sort_type ".strtoupper($default_charset)." $search";
 
+    // TODO use sqimap_run_command_list as we do in get_server_sort()
     $thread_test = sqimap_run_command ($imap_stream, $query, false, $response, $message, TRUE);
     /* fallback to default charset */
-    if ($response == 'NO' && strpos($message,'[BADCHARSET]') !== false) {
-        $query = "THREAD $sort_type US-ASCII $search";
-        $thread_test = sqimap_run_command ($imap_stream, $query, true, $response, $message, TRUE);
+
+    if ($response == 'NO') {
+        if (strpos($message,'[BADCHARSET]') !== false ||
+            strpos($message,'Unrecognized character set') !== false) {
+            sqm_trigger_imap_error('SQM_IMAP_BADCHARSET',$query, $response, $message);
+            $query = "THREAD $sort_type US-ASCII $search";
+            $thread_test = sqimap_run_command ($imap_stream, $query, true, $response, $message, TRUE);
+        } else {
+            sqm_trigger_imap_error('SQM_IMAP_ERROR',$query, $response, $message);
+        }
+    } elseif ($response == 'BAD') {
+        sqm_trigger_imap_error('SQM_IMAP_NO_THREAD',$query, $response, $message);
     }
     if (isset($thread_test[0])) {
         for ($i=0,$iCnt=count($thread_test);$i<$iCnt;++$i) {
@@ -445,7 +462,7 @@ function get_thread_sort($imap_stream, $search='ALL') {
         $thread_list = "";
     }
     if (!preg_match("/OK/", $response)) {
-        $server_sort_array = 'no';
+        $server_sort_array = false;
         return $server_sort_array;
     }
     if (isset($thread_list)) {