Fixed wrong sqimap_run_command call. The $sid is added inside
[squirrelmail.git] / plugins / filters / filters.php
index 4cbf7b414802d21003887f03347742dfb3244ac7..1300394e305c6cd54874544bad82ceb15eaf2251 100644 (file)
@@ -3,7 +3,7 @@
 /**
  * Message and Spam Filter Plugin
  *
- * Copyright (c) 1999-2002 The SquirrelMail Project Team
+ * Copyright (c) 1999-2003 The SquirrelMail Project Team
  * Licensed under the GNU GPL. For full terms see the file COPYING.
  *
  * This plugin filters your inbox into different folders based upon given
@@ -164,10 +164,10 @@ function filters_bulkquery($filters_spam_scan, $filters, $read) {
 function start_filters() {
     global $mailbox, $imapServerAddress, $imapPort, $imap,
            $imap_general, $filters, $imap_stream, $imapConnection,
-           $UseSeparateImapConnection, $AllowSpamFilters, $_SESSION, $_COOKIE;
+           $UseSeparateImapConnection, $AllowSpamFilters;
 
-    $username = $_SESSION['username'];
-    $key = $_COOKIE['key'];
+    sqgetGlobalVar('username', $username, SQ_SESSION);
+    sqgetGlobalVar('key',      $key,      SQ_COOKIE);
 
 #    if ($mailbox == 'INBOX') {
         // Detect if we have already connected to IMAP or not.
@@ -325,24 +325,23 @@ function spam_filters($imap_stream) {
     // flags for each message.  Kinda big.
     if ($filters_spam_scan != 'new') {
         $read = sqimap_run_command($imap_stream, 'FETCH 1:* (FLAGS BODY.PEEK[HEADER.FIELDS ' .
-            '(RECEIVED)])', true, $reponse, $message, $uid_support);
+            '(RECEIVED)])', true, $response, $message, $uid_support);
     } else {
-        $read = sqimap_run_command($imap_stream, 'SEARCH UNSEEN', true, $reponse, $message, $uid_support);
+        $read = sqimap_run_command($imap_stream, 'SEARCH UNSEEN', true, $response, $message, $uid_support);
         if ($response != 'OK' || trim($read[0]) == '* SEARCH') {
            $read = sqimap_run_command($imap_stream, 'FETCH 1:* (FLAGS BODY.PEEK[HEADER.FIELDS ' .
-            '(RECEIVED)])', true, $reponse, $message, $uid_support);
+            '(RECEIVED)])', true, $response, $message, $uid_support);
         } else {
-           $read[0] = trim($read[0]);
-            $i = 0;
-            $imap_query = $sid.' FETCH ';
-            $Chunks = explode(' ', $read[0]);
-            for ($i=2; $i < (count($Chunks)-1) ; $i++) {
-                $imap_query .= $Chunks[$i].',';
+            if (isset($read[0])) {
+                if (preg_match("/^\* SEARCH (.+)$/", $read[0], $regs)) {
+                    $search_array = preg_split("/ /", trim($regs[1]));
+                }
             }
-            $imap_query .= $Chunks[count($Chunks)-1];
+           $msgs_str = sqimap_message_list_squisher($search_array);
+            $imap_query = 'FETCH '.$msgs_str;
             $imap_query .= ' (FLAGS BODY.PEEK[HEADER.FIELDS ';
-            $imap_query .= '(RECEIVED)])';//\r\n";
-           $read = sqimap_run_command($imap_stream,$imap_query, true, $reponse, $message, $uid_support);
+            $imap_query .= '(RECEIVED)])';
+           $read = sqimap_run_command($imap_stream,$imap_query, true, $response, $message, $uid_support);
         }
     }