Replacing tabs with spaces, trimming white space at EOL and newline at EOF (PHP only)
[squirrelmail.git] / functions / imap_messages.php
index a9011edcf33ea76c6eda34c65d94647f06ca646a..cb2cf325c13f5caf35cf41ace1c2ca8ecc032a71 100755 (executable)
@@ -3,7 +3,7 @@
 /**
  * imap_messages.php
  *
- * Copyright (c) 1999-2004 The SquirrelMail Project Team
+ * Copyright (c) 1999-2005 The SquirrelMail Project Team
  * Licensed under the GNU GPL. For full terms see the file COPYING.
  *
  * This implements functions that manipulate messages
@@ -131,12 +131,7 @@ function sqimap_message_list_squisher($messages_array) {
  * @return array $id sorted uid list
  */
 function sqimap_get_sort_order($imap_stream, $sSortField, $reverse, $search='ALL') {
-    global  $default_charset,
-            $sent_folder;
-
-    $id = array();
-    $sort_test = array();
-    $sort_query = '';
+    global  $default_charset;
 
     if ($sSortField) {
         if ($reverse) {
@@ -247,7 +242,7 @@ function get_squirrel_sort($imap_stream, $sSortField, $reverse = false, $aUid =
       case 'RFC822.SIZE':
         if(!$walk) {
             // redefine $sSortField to maintain the same namespace between
-            // server-side sorting and squirrelmail sorting
+            // server-side sorting and SquirrelMail sorting
             $sSortField = 'SIZE';
         }
         foreach ($msgs as $item) {
@@ -430,7 +425,6 @@ function get_thread_sort($imap_stream, $search='ALL') {
         $thread_temp = preg_split("//", $thread_list, -1, PREG_SPLIT_NO_EMPTY);
     }
 
-    $char_count = count($thread_temp);
     $counter = 0;
     $thread_new = array();
     $k = 0;
@@ -485,6 +479,19 @@ function elapsedTime($start) {
 }
 
 
+function parsePriority($value) {
+    $value = strtolower(array_shift(split('/\w/',trim($value))));
+    if ( is_numeric($value) ) {
+        return $value;
+    }
+    if ( $value == 'urgent' || $value == 'high' ) {
+        return 1;
+    } elseif ( $value == 'non-urgent' || $value == 'low' ) {
+        return 5;
+    }
+    return 3;
+}
+
 /**
  * Parses a string in an imap response. String starts with " or { which means it
  * can handle double quoted strings and literal strings
@@ -566,11 +573,10 @@ function parseArray($read,&$i) {
  * @return array   $aMessages associative array with messages. Key is the UID, value is an associative array
  */
 function sqimap_get_small_header_list($imap_stream, $msg_list,
-    $aHeaderFields = array('Date', 'To', 'Cc', 'From', 'Subject', 'X-Priority', 'Content-Type'),
+    $aHeaderFields = array('Date', 'To', 'Cc', 'From', 'Subject', 'X-Priority', 'Importance', 'Priority', 'Content-Type'),
     $aFetchItems = array('FLAGS', 'RFC822.SIZE', 'INTERNALDATE')) {
 
     $aMessageList = array();
-    $read_list = array();
 
     $bUidFetch = ! in_array('UID', $aFetchItems, true);
 
@@ -589,7 +595,6 @@ function sqimap_get_small_header_list($imap_stream, $msg_list,
         }
     } else {
         $msgs_str = '1:*';
-        $aId = array();
     }
 
     /*
@@ -695,7 +700,7 @@ function parseFetch($aResponse,$aMessageList = array()) {
             case 'BODYSTRUCTURE':
                 break;
             case 'INTERNALDATE':
-                $msg['INTERNALDATE'] = str_replace('  ', ' ',parseString($read,$i));
+                $msg['INTERNALDATE'] = trim(str_replace('  ', ' ',parseString($read,$i)));
                 break;
             case 'BODY.PEEK[HEADER.FIELDS':
             case 'BODY[HEADER.FIELDS':
@@ -722,7 +727,10 @@ function parseFetch($aResponse,$aMessageList = array()) {
                             case 'date':
                                 $msg['DATE'] = str_replace('  ', ' ', $value);
                                 break;
-                            case 'x-priority': $msg['PRIORITY'] = $value; break;
+                            case 'x-priority':
+                            case 'importance':
+                            case 'priority':
+                                $msg['PRIORITY'] = parsePriority($value); break;
                             case 'subject': $msg['SUBJECT'] = $value; break;
                             case 'content-type':
                                 $type = $value;
@@ -831,7 +839,7 @@ function sqimap_parse_envelope($read, &$i, &$msg) {
     if (count($arg_a) > 9) {
         $d = strtr($arg_a[0], array('  ' => ' '));
         $d = explode(' ', $d);
-        if (!$arg_a[1]) $arg_1[1] = '';
+        if (!$arg_a[1]) $arg_a[1] = '';
         $msg['DATE'] = $d; /* argument 1: date */
         $msg['SUBJECT'] = $arg_a[1];     /* argument 2: subject */
         $msg['FROM'] = is_array($arg_a[2]) ? $arg_a[2][0] : '';     /* argument 3: from        */
@@ -936,7 +944,7 @@ function sqimap_messages_copy($imap_stream, $start, $end, $mailbox) {
  * Deprecated !!!!!!! DO NOT USE THIS, use sqimap_msgs_list_delete instead
  */
 function sqimap_messages_delete($imap_stream, $start, $end, $mailbox, $bypass_trash=false) {
-    global $move_to_trash, $trash_folder, $auto_expunge;
+    global $move_to_trash, $trash_folder;
 
     if (($move_to_trash == true) && ($bypass_trash != true) &&
         (sqimap_mailbox_exists($imap_stream, $trash_folder) && ($mailbox != $trash_folder))) {