fixed formatting, sjeesh that's realy dull work. Makes me simple :(
[squirrelmail.git] / functions / imap_messages.php
index 227bd1ecc68c626119b88d0c7a4734935383ded4..8eec107fc122892204fa5ba135dcba627c2b9746 100755 (executable)
@@ -11,6 +11,8 @@
  * $Id$
  */
 
+/* NOTE: quite some functions in this file are not used anymore. */
+
 /* Copies specified messages to specified folder */
 /* obsolete */
 function sqimap_messages_copy ($imap_stream, $start, $end, $mailbox) {
@@ -66,6 +68,7 @@ function sqimap_toggle_flag($imap_stream, $id, $flag, $set, $handle_errors) {
     $read = sqimap_run_command ($imap_stream, "STORE $msgs_id ".$set_string."FLAGS ($flag)", $handle_errors, $response, $message, $uid_support);
 }
 
+// obsolete?
 function sqimap_get_small_header ($imap_stream, $id, $sent) {
     $res = sqimap_get_small_header_list($imap_stream, $id, $sent);
     return $res[0];
@@ -407,6 +410,7 @@ function elapsedTime($start) {
  return $timepassed;
 }
 
+// only used in sqimap_get_small_header_list
 function parseString($read,&$i) {
     $char = $read{$i};
     $s = '';
@@ -449,19 +453,7 @@ function parseString($read,&$i) {
     return $s;
 }
 
-function parseInteger($read,&$i) {
-    $s = false;
-    $i_pos = strpos($read,' ',$i);
-    if (!$i_pos) {
-        $i_pos = strpos($read,')',$i);
-    }
-    if ($i_pos) {
-        $s = substr($read,$i,$i_pos-$i);
-        $i = $i_pos+1;
-    }
-    return $s;
-}
-
+// only used in sqimap_get_small_header_list
 function parseArray($read,&$i) {
     $i = strpos($read,'(',$i);
     $i_pos = strpos($read,')',$i);
@@ -587,12 +579,12 @@ function sqimap_get_small_header_list ($imap_stream, $msg_list, $show_num=false)
                 
                 break;
             case 'INTERNALDATE':
-                $tmpdate = parseString($read,$i);
-                if ($tmpdate === false) break 3;
-                $tmpdate = str_replace('  ',' ',$tmpdate);
-                $tmpdate = explode(' ',$tmpdate);
-                $date = str_replace('-',' ',$tmpdate[0]) . " " . 
-                                            $tmpdate[1] . ' ' . $tmpdate[2];
+                $date = parseString($read,$i);
+                //if ($tmpdate === false) break 3;
+                //$tmpdate = str_replace('  ',' ',$tmpdate);
+                //$tmpdate = explode(' ',$tmpdate);
+                //$date = str_replace('-',' ',$tmpdate[0]) . " " . 
+                //                            $tmpdate[1] . ' ' . $tmpdate[2];
                 break;
             case 'BODY.PEEK[HEADER.FIELDS':
             case 'BODY[HEADER.FIELDS':
@@ -615,7 +607,7 @@ function sqimap_get_small_header_list ($imap_stream, $msg_list, $show_num=false)
                             case 'to': $to = $value; break;
                             case 'cc': $cc = $value; break;
                             case 'from': $from = $value; break;
-                            case 'date':
+                            case 'date': $date = $value; break;
                             case 'x-priority': $priority = $value; break;
                             case 'subject':
                                 $subject = $value;
@@ -702,6 +694,7 @@ function sqimap_get_small_header_list ($imap_stream, $msg_list, $show_num=false)
     return $new_messages;
 }
 
+// obsolete?
 function sqimap_get_headerfield($imap_stream, $field) {
     global $uid_support;
     $sid = sqimap_session_id(false);
@@ -766,14 +759,20 @@ function sqimap_get_message ($imap_stream, $id, $mailbox) {
     $flags = array();
     $read = sqimap_run_command ($imap_stream, "FETCH $id (FLAGS BODYSTRUCTURE)", true, $response, $message, $uid_support);
     if ($read) {
-    if (preg_match('/.+FLAGS\s\((.*)\)\s/AUi',$read[0],$regs)) {
-       if (trim($regs[1])) {
-          $flags = preg_split('/ /', $regs[1],-1,'PREG_SPLIT_NI_EMPTY');
-       }
-    }
+        if (preg_match('/.+FLAGS\s\((.*)\)\s/AUi',$read[0],$regs)) {
+            if (trim($regs[1])) {
+                $flags = preg_split('/ /', $regs[1],-1,'PREG_SPLIT_NI_EMPTY');
+            }
+        }
     } else {
-      echo "ERROR Yeah I know, not a very usefull errormessage (id = $id, mailbox = $mailbox sqimap_get_message)";
-      exit;
+        /* the message was not found, maybe the mailbox was modified? */
+        global $sort, $startMessage, $color;
+
+        $errmessage = _("The server couldn't find the message you requested.") .
+              '<p>'._("Most probably your message list was out of date and the message has been moved away or deleted (perhaps by another program accessing the same mailbox).");
+        /* this will include a link back to the message list */
+        error_message($errmessage, $mailbox, $sort, $startMessage, $color);
+        exit;
     } 
     $bodystructure = implode('',$read);
     $msg =  mime_structure($bodystructure,$flags);
@@ -785,6 +784,7 @@ function sqimap_get_message ($imap_stream, $id, $mailbox) {
 }
 
 /* Wrapper function that reformats the header information. */
+// obsolete?
 function sqimap_get_message_header ($imap_stream, $id, $mailbox) {
     global $uid_support;
     $read = sqimap_run_command ($imap_stream, "FETCH $id BODY[HEADER]", true, $response, $message, $uid_support);
@@ -795,6 +795,7 @@ function sqimap_get_message_header ($imap_stream, $id, $mailbox) {
 }
 
 /* Wrapper function that reformats the entity header information. */
+// obsolete?
 function sqimap_get_ent_header ($imap_stream, $id, $mailbox, $ent) {
     global $uid_support;
     $read = sqimap_run_command ($imap_stream, "FETCH $id BODY[$ent.HEADER]", true, $response, $message, $uid_support);
@@ -805,6 +806,7 @@ function sqimap_get_ent_header ($imap_stream, $id, $mailbox, $ent) {
 }
 
 /* function to get the mime headers */
+// obsolete?
 function sqimap_get_mime_ent_header ($imap_stream, $id, $mailbox, $ent) {
     global $uid_support;
     $read = sqimap_run_command ($imap_stream, "FETCH $id:$id BODY[$ent.MIME]", true, $response, $message, $uid_support);