Fix two typos "squirrelmai" -> "squirrelmail". Sheesh.
[squirrelmail.git] / functions / imap_messages.php
index 8eec107fc122892204fa5ba135dcba627c2b9746..f3e1023c14eba918194944f2ddcef561cfb50365 100755 (executable)
@@ -7,29 +7,62 @@
  * Licensed under the GNU GPL. For full terms see the file COPYING.
  *
  * This implements functions that manipulate messages
+ * NOTE: Quite a few functions in this file are obsolete
  *
  * $Id$
+ * @package squirrelmail
  */
 
-/* NOTE: quite some functions in this file are not used anymore. */
-
-/* Copies specified messages to specified folder */
-/* obsolete */
+/**
+ * Copies specified messages to specified folder
+ * @param int $imap_stream The resource ID for the IMAP connection
+ * @param string $start Beginning of range to copy
+ * @param string $end End of the range to copy
+ * @param string $mailbox Which box to copy to
+ * @deprecated This function is obsolete and should not be used
+ */
 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);
+    $read = sqimap_run_command ($imap_stream, "COPY $start:$end " . sqimap_encode_mailbox_name($mailbox), true, $response, $message, $uid_support);
 }
 
+/**
+* copy a range of messages ($id) to another mailbox ($mailbox)
+* @param int $imap_stream The resource ID for the IMAP socket
+* @param string $id The list of messages to copy
+* @param string $mailbox The destination to copy to
+* @return void
+*/
 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);
+    $read = sqimap_run_command ($imap_stream, "COPY $msgs_id " . sqimap_encode_mailbox_name($mailbox), true, $response, $message, $uid_support);
+}
+
+/**
+* move a range of messages ($id) to another mailbox. Deletes the originals.
+* @param int $imap_stream The resource ID for the IMAP socket
+* @param string $id The list of messages to move
+* @param string $mailbox The destination to move to
+* @return void
+*/
+function sqimap_msgs_list_move ($imap_stream, $id, $mailbox) {
+    global $uid_support;
+    $msgs_id = sqimap_message_list_squisher($id);
+    $read = sqimap_run_command ($imap_stream, "COPY $msgs_id " . sqimap_encode_mailbox_name($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 */
+/**
+ * Deletes specified messages and moves them to trash if possible
+ * @deprecated This function is obsolete and should no longer be used
+ * @param int $imap_steam The resource ID for the IMAP connection
+ * @param string $start Start of range
+ * @param string $end End of range
+ * @param string $mailbox Mailbox messages are being deleted from
+ * @return void
+ */
 function sqimap_messages_delete ($imap_stream, $start, $end, $mailbox) {
     global $move_to_trash, $trash_folder, $auto_expunge, $uid_support;
 
@@ -39,17 +72,19 @@ 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) {
+function sqimap_msgs_list_delete ($imap_stream, $mailbox, $id, $bypass_trash=false) {
     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);
+    if (($move_to_trash == true) && (sqimap_mailbox_exists($imap_stream, $trash_folder) && ($mailbox != $trash_folder)) && ($bypass_trash != true)) {
+        $read = sqimap_run_command ($imap_stream, "COPY $msgs_id " . sqimap_encode_mailbox_name($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 */
+/**
+ * Sets the specified messages with specified flag
+ */
 function sqimap_messages_flag ($imap_stream, $start, $end, $flag, $handle_errors) {
     global $uid_support;
     $read = sqimap_run_command ($imap_stream, "STORE $start:$end +FLAGS (\\$flag)", $handle_errors, $response, $message, $uid_support);
@@ -181,9 +216,12 @@ function sqimap_get_sort_order ($imap_stream, $sort, $mbxresponse) {
         $sort_test = sqimap_run_command ($imap_stream, $query, true, $response, $message, $uid_support);
     }
     if (isset($sort_test[0])) {
-        if (preg_match("/^\* SORT (.+)$/", $sort_test[0], $regs)) {
+      for ($i=0,$iCnt=count($sort_test);$i<$iCnt;++$i) {
+        if (preg_match("/^\* SORT (.+)$/", $sort_test[$i], $regs)) {
             $server_sort_array = preg_split("/ /", trim($regs[1]));
+           break;
         }
+      }
     }
     if ($sort == 0 || $sort == 2 || $sort == 4) {
        $server_sort_array = array_reverse($server_sort_array);
@@ -352,9 +390,12 @@ function get_thread_sort ($imap_stream) {
     $query = "THREAD $sort_type ".strtoupper($default_charset)." ALL";
     $thread_test = sqimap_run_command ($imap_stream, $query, true, $response, $message, $uid_support);
     if (isset($thread_test[0])) {
-        if (preg_match("/^\* THREAD (.+)$/", $thread_test[0], $regs)) {
-            $thread_list = trim($regs[1]);
-        }
+        for ($i=0,$iCnt=count($thread_test);$i<$iCnt;++$i) {
+           if (preg_match("/^\* THREAD (.+)$/", $thread_test[$i], $regs)) {
+              $thread_list = trim($regs[1]);
+             break;
+           }
+        } 
     }
     else {
        $thread_list = "";
@@ -500,7 +541,7 @@ function sqimap_get_small_header_list ($imap_stream, $msg_list, $show_num=false)
     
     foreach ($read_list as $r) {
         $subject = _("(no subject)");
-        $from = _("Unknown Sender");
+        $from = _("Unknown sender");
         $priority = 0;
         $messageid = '<>';
         $cc = $to = $date = $type[0] = $type[1] = $inrepto = '';