Translated strings in plugin to gettext.
[squirrelmail.git] / functions / imap_messages.php
index 3b52743e32a7c07ad1e7214e831452c1e9a27654..d609c8ea873b212380fc7639a99de4055e01d280 100755 (executable)
@@ -3,7 +3,7 @@
 /**
  * imap_messages.php
  *
- * 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 implements functions that manipulate messages
  */
 
 /* Copies specified messages to specified folder */
+/* obsolete */
 function sqimap_messages_copy ($imap_stream, $start, $end, $mailbox) {
     global $uid_support;
     $read = sqimap_run_command ($imap_stream, "COPY $start:$end \"$mailbox\"", true, $response, $message, $uid_support);
 }
 
+function sqimap_msgs_list_copy ($imap_stream, $id, $mailbox) {
+    global $uid_support;
+    $msgs_id = sqimap_message_list_squisher($id);    
+    $read = sqimap_run_command ($imap_stream, "COPY $msgs_id \"$mailbox\"", true, $response, $message, $uid_support);
+    $read = sqimap_run_command ($imap_stream, "STORE $msgs_id +FLAGS (\\Deleted)", true, $response, $message, $uid_support);
+}
+
+
 /* Deletes specified messages and moves them to trash if possible */
+/* obsolete */
 function sqimap_messages_delete ($imap_stream, $start, $end, $mailbox) {
     global $move_to_trash, $trash_folder, $auto_expunge, $uid_support;
 
@@ -27,6 +37,16 @@ function sqimap_messages_delete ($imap_stream, $start, $end, $mailbox) {
     sqimap_messages_flag ($imap_stream, $start, $end, "Deleted", true);
 }
 
+function sqimap_msgs_list_delete ($imap_stream, $mailbox, $id) {
+    global $move_to_trash, $trash_folder, $uid_support;
+    $msgs_id = sqimap_message_list_squisher($id);
+    if (($move_to_trash == true) && (sqimap_mailbox_exists($imap_stream, $trash_folder) && ($mailbox != $trash_folder))) {
+        $read = sqimap_run_command ($imap_stream, "COPY $msgs_id \"$trash_folder\"", true, $response, $message, $uid_support);
+    }
+    $read = sqimap_run_command ($imap_stream, "STORE $msgs_id +FLAGS (\\Deleted)", true, $response, $message, $uid_support);
+}
+
+
 /* Sets the specified messages with specified flag */
 function sqimap_messages_flag ($imap_stream, $start, $end, $flag, $handle_errors) {
     global $uid_support;
@@ -39,6 +59,14 @@ function sqimap_messages_remove_flag ($imap_stream, $start, $end, $flag, $handle
     $read = sqimap_run_command ($imap_stream, "STORE $start:$end -FLAGS (\\$flag)", $handle_errors, $response, $message, $uid_support);
 }
 
+function sqimap_toggle_flag($imap_stream, $id, $flag, $set, $handle_errors) {
+    global $uid_support;
+    $msgs_id = sqimap_message_list_squisher($id);
+    $set_string = ($set ? '+' : '-');
+    $read = sqimap_run_command ($imap_stream, "STORE $msgs_id ".$set_string."FLAGS ($flag)", $handle_errors, $response, $message, $uid_support);
+}
+
+
 /* Returns some general header information -- FROM, DATE, and SUBJECT */
 class small_header {
     var $from = '', $subject = '', $date = '', $to = '', 
@@ -56,7 +84,7 @@ function sqimap_get_small_header ($imap_stream, $id, $sent) {
  */
 function sqimap_message_list_squisher($messages_array) {
     if( !is_array( $messages_array ) ) {
-        return;
+        return $messages_array;
     }
 
     sort($messages_array, SORT_NUMERIC);
@@ -105,7 +133,7 @@ function sqimap_get_sort_order ($imap_stream, $sort, $mbxresponse) {
             $internal_date_sort, $server_sort_array,
             $sent_folder, $mailbox, $uid_support;
 
-    if (session_is_registered('server_sort_array')) {
+    if (sqsession_is_registered('server_sort_array')) {
         sqsession_unregister('server_sort_array');
     }
 
@@ -180,7 +208,7 @@ function sqimap_get_sort_order ($imap_stream, $sort, $mbxresponse) {
 function sqimap_get_php_sort_order ($imap_stream, $mbxresponse) {
     global $uid_support;
 
-    if (session_is_registered('php_sort_array')) {
+    if (sqsession_is_registered('php_sort_array')) {
         sqsession_unregister('php_sort_array');
     }
 
@@ -319,10 +347,10 @@ function get_parent_level ($imap_stream) {
 
 function get_thread_sort ($imap_stream) {
     global $thread_new, $sort_by_ref, $default_charset, $server_sort_array, $uid_support;
-    if (session_is_registered('thread_new')) {
+    if (sqsession_is_registered('thread_new')) {
         sqsession_unregister('thread_new');
     }
-    if (session_is_registered('server_sort_array')) {
+    if (sqsession_is_registered('server_sort_array')) {
         sqsession_unregister('server_sort_array');
     }
     $sid = sqimap_session_id($uid_support);
@@ -388,6 +416,7 @@ function get_thread_sort ($imap_stream) {
     return $thread_list;
 }
 
+
 function elapsedTime($start) {
  $stop = gettimeofday();
  $timepassed =  1000000 * ($stop['sec'] - $start['sec']) + $stop['usec'] - $start['usec'];
@@ -431,14 +460,14 @@ function sqimap_get_small_header_list ($imap_stream, $msg_list) {
                       _("ERROR : Could not complete request.") .
                       '</b><br>' .
                       _("Unknown response from IMAP server: ") . ' 1.' .
-                      $r[0] . "</font><br>\n";
+                      htmlspecialchars($r[0]) . "</font><br>\n";
             } else if (! isset($id2index[$regs[1]]) || !count($id2index[$regs[1]])) {
                 set_up_language($squirrelmail_language);
                 echo '<br><b><font color=$color[2]>' .
                       _("ERROR : Could not complete request.") .
                       '</b><br>' .
                       _("Unknown message number in reply from server: ") .
-                      $regs[1] . "</font><br>\n";
+                      htmlspecialchars($regs[1]) . "</font><br>\n";
             } else {
                 $read_list[$id2index[$regs[1]]] = $r;
             }
@@ -449,14 +478,14 @@ function sqimap_get_small_header_list ($imap_stream, $msg_list) {
                      _("ERROR : Could not complete request.") .
                      '</b><br>' .
                      _("Unknown response from IMAP server: ") . ' 1.' .
-                     $r[0] . "</font><br>\n";
+                     htmlspecialchars($r[0]) . "</font><br>\n";
             } else if (! isset($id2index[$regs[2]]) || !count($id2index[$regs[2]])) {
                 set_up_language($squirrelmail_language);
                 echo '<br><b><font color=$color[2]>' .
                       _("ERROR : Could not complete request.") .
                       '</b><br>' .
                       _("Unknown message number in reply from server: ") .
-                      $regs[2] . "</font><br>\n";
+                      htmlspecialchars($regs[2]) . "</font><br>\n";
             } else {
                 $read_list[$id2index[$regs[2]]] = $r;
                 $unique_id = $regs[2];
@@ -480,13 +509,13 @@ function sqimap_get_small_header_list ($imap_stream, $msg_list) {
         $subject = _("(no subject)");
         $from = _("Unknown Sender");
         $priority = 0;
-        $messageid = "<>";
-        $cc = "";
-        $to = "";
-        $date = "";
-        $type[0] = "";
-        $type[1] = "";
-        $inrepto = "";
+        $messageid = '<>';
+        $cc = '';
+        $to = '';
+        $date = '';
+        $type[0] = '';
+        $type[1] = '';
+        $inrepto = '';
         $flag_seen = false;
         $flag_answered = false;
         $flag_deleted = false;
@@ -496,9 +525,9 @@ function sqimap_get_small_header_list ($imap_stream, $msg_list) {
 
         foreach ($read as $read_part) {
             //unfold multi-line headers
-           if ($prevline && strpos($read_part, "\t ") === true) {
-               $read_part = substr($prevline, 0, -2) . preg_replace('/(\t\s+)/',' ',$read_part);
-           }
+            if ($prevline && strpos($read_part, "\t ") === true) {
+                $read_part = substr($prevline, 0, -2) . preg_replace('/(\t\s+)/',' ',$read_part);
+            }
             $prevline = $read_part;
             if ($read_part{0} == '*') {
                 if ($internaldate) {
@@ -507,7 +536,7 @@ function sqimap_get_small_header_list ($imap_stream, $msg_list) {
                         $tmpdate = str_replace('  ',' ',$tmpdate);
                         $tmpdate = explode(' ',$tmpdate);
                         $date = str_replace('-',' ',$tmpdate[0]) . " " .
-                                $tmpdate[1] . " " .
+                                $tmpdate[1] . ' ' .
                                 $tmpdate[2];
                     }
                 }
@@ -533,7 +562,7 @@ function sqimap_get_small_header_list ($imap_stream, $msg_list) {
                     $unique_id = $reg[1];
                 }
             } else {
-                $firstchar = $read_part{0};
+                $firstchar = strtoupper($read_part{0});
                 if ($firstchar == 'T') {
                     $regpattern = $patterns[0];
                     $id = 1;