bugfix
[squirrelmail.git] / src / read_body.php
index 18b8d4300a5564e8caa0501bc0289ef1743d875d..c2a4c84cb8a27719dc7c5bb71e4a59a34e805c80 100644 (file)
@@ -32,10 +32,10 @@ function findNextMessage() {
            $server_sort_array;
     if (!is_array($server_sort_array)) {
         $thread_sort_messages = 0;
-        $allow_server_sort = 'false';
+        $allow_server_sort = FALSE;
     }
     $result = -1;
-    if ($thread_sort_messages == 1 || $allow_server_sort == 'true') {
+    if ($thread_sort_messages == 1 || $allow_server_sort == TRUE) {
         reset($server_sort_array);
         while(list($key, $value) = each ($server_sort_array)) {
             if ($currentArrayIndex == $value) {
@@ -48,13 +48,13 @@ function findNextMessage() {
             }
         }
     } 
-    elseif ($sort == 6 && $allow_server_sort != 'true' &&
+    elseif ($sort == 6 && $allow_server_sort != TRUE &&
             $thread_sort_messages != 1) {
         if ($currentArrayIndex != 1) {
             $result = $currentArrayIndex - 1;
         }
     }
-    elseif ($allow_server_sort != 'true' && $thread_sort_messages != 1 ) {
+    elseif ($allow_server_sort != TRUE && $thread_sort_messages != 1 ) {
         if (!is_array($msort)) {
             return -1;
         }
@@ -95,9 +95,9 @@ function findPreviousMessage() {
     $result = -1;
     if (!is_array($server_sort_array)) {
         $thread_sort_messages = 0;
-        $allow_server_sort = 'false';
+        $allow_server_sort = FALSE;
     }
-    if ($thread_sort_messages == 1 || $allow_server_sort == 'true') {
+    if ($thread_sort_messages == 1 || $allow_server_sort == TRUE) {
         reset($server_sort_array);
         while(list($key, $value) = each ($server_sort_array)) {
             if ($currentArrayIndex == $value) {
@@ -110,14 +110,14 @@ function findPreviousMessage() {
             }
         }
     }
-    elseif ($sort == 6 && $allow_server_sort != 'true' && 
+    elseif ($sort == 6 && $allow_server_sort != TRUE && 
             $thread_sort_messages != 1) {
         $numMessages = sqimap_get_num_messages($imapConnection, $mailbox);
         if ($currentArrayIndex != $numMessages) {
             $result = $currentArrayIndex + 1;
         }
     } 
-    elseif ($thread_sort_messages != 1 && $allow_server_sort != 'true') {
+    elseif ($thread_sort_messages != 1 && $allow_server_sort != TRUE) {
         if (!is_array($msort)) {
             return -1;
         }
@@ -261,7 +261,6 @@ function SendMDN ( $recipient , $sender) {
 function ToggleMDNflag ( $set ) {
     global $imapConnection, $passed_id, $mailbox;
     sqimap_mailbox_select($imapConnection, $mailbox);
-    
     $sg =  $set?'+':'-';
     $cmd = 'STORE ' . $passed_id . ' ' . $sg . 'FLAGS ($MDNSent)';
     $read = sqimap_run_command ($imapConnection, $cmd, true, $response, 
@@ -275,7 +274,7 @@ function ClearAttachments() {
 
        $rem_attachments = array();
         foreach ($attachments as $info) {
-           if ($info->session == -1) {
+           if ($info['session'] == -1) {
                $attached_file = "$hashed_attachment_dir/$info[localfilename]";
                if (file_exists($attached_file)) {
                    unlink($attached_file);
@@ -471,7 +470,9 @@ if (isset($view_hdr)) {
             $s .= '    ' . nl2br($second[$j]);
             $j++;
         }
-        parseEmail($s);
+        if(strtolower($f) != 'message-id:') {
+            parseEmail($s);     /* Find and linkify emailaddresses except msgid */
+        }
         if (isset($f)) {
             echo "<nobr><tt><b>$f</b>$s</tt></nobr>";
         }
@@ -581,11 +582,6 @@ $url_replytoallcc = urlencode($url_replytoallcc);
 
 $dateString = getLongDateString($message->header->date);
 
-/**
- * What do we reply to -- text only, if possible
- */
-$ent_num = findDisplayEntity($message);
-
 /** TEXT STRINGS DEFINITIONS **/
 $echo_more = _("more");
 $echo_less = _("less");
@@ -663,6 +659,47 @@ if (!empty($idents) && $idents > 1) {
 }
 
 do_hook('read_body_top');
+/**
+ * What do we reply to -- text only, if possible
+ */
+
+$body = ''; 
+
+/* experimental */
+/*
+if ($message->header->type0 == 'multipart' && $message->header->type1 == 'digest') {
+  listEntities($message);
+  for ($i = 0; $i < count($message->entities); $i++) {
+
+       $msg = $message->entities[$i];
+       $body .= $msg->header->type0 .'/'.$msg->header->type1 .'<BR>';
+
+       $msg->header->type0 = 'message';
+       $msg->header->type1 = 'rfc822';
+       $ent_ar = findDisplayEntity($msg, false);
+       for ($i = 0; $i < count($ent_ar); $i++) {
+           $body .= formatBody($imapConnection, $msg, $color, $wrap_at, $ent_ar[$i]);
+       }
+       $i++;
+   }
+} else {
+*/    
+    $ent_ar = findDisplayEntity($message, false);
+    $i = 0;
+    for ($i = 0; $i < count($ent_ar); $i++) {
+        $body .= formatBody($imapConnection, $message, $color, $wrap_at, $ent_ar[$i]);
+    }
+/*
+}
+*/
+
+/* first step in displaying multiple entities */
+$ent_ar = findDisplayEntity($message,true);
+
+$ent_num = $ent_ar[0];
+for ($i = 1 ; $i < count($ent_ar); $i++) {
+    $ent_num .= '_'.$ent_ar[$i];
+}
 echo '<BR>' .
      '<TABLE CELLSPACING="0" WIDTH="100%" BORDER="0" ALIGN="CENTER" CELLPADDING="0">' .
         '<TR><TD BGCOLOR="' . $color[9] . '" WIDTH="100%">' .
@@ -690,19 +727,31 @@ if ($where && $what) {
 }
 echo _("Delete") . '</A>&nbsp;';
 if (($mailbox == $draft_folder) && ($save_as_draft)) {
-    echo '|&nbsp;<A HREF="' . $base_uri .
-         "src/compose.php?mailbox=$mailbox&amp;identity=$identity&amp;send_to=$url_to_string&amp;send_to_cc=$url_cc_string&amp;send_to_bcc=$url_bcc_string&amp;subject=$url_subj&amp;mailprio=$priority_level&amp;draft_id=$passed_id&amp;ent_num=$ent_num" . '"';
+    $comp_uri = $base_uri . "src/compose.php?mailbox=$mailbox&amp;".
+                "identity=$identity&amp;send_to=$url_to_string&amp;".
+                "send_to_cc=$url_cc_string&amp;send_to_bcc=$url_bcc_string&amp;".
+                "subject=$url_subj&amp;mailprio=$priority_level&amp;".
+                "draft_id=$passed_id&amp;ent_num=$ent_num";
+
     if ($compose_new_win == '1') {
-        echo ' TARGET="compose_window" onClick="comp_in_new()"';
+        echo "<a href=\"javascript:void(0)\" onclick=\"comp_in_new(false,'$comp_uri')\"";
+    } else {
+        echo '|&nbsp;<A HREF="' . $comp_uri .'"';
     }
     echo '>'.
          _("Resume Draft") . '</a>';
 }
 if ($mailbox == $sent_folder) {
-    echo '|&nbsp;<A HREF="' . $base_uri .
-         "src/compose.php?mailbox=$mailbox&amp;identity=$identity&amp;send_to=$url_to_string&amp;send_to_cc=$url_cc_string&amp;send_to_bcc=$url_bcc_string&amp;subject=$url_subj&amp;mailprio=$priority_level&amp;ent_num=$ent_num" . '"';
+    $comp_uri = $base_uri . "src/compose.php?mailbox=$mailbox&amp;".
+                "identity=$identity&amp;send_to=$url_to_string&amp;".
+                "send_to_cc=$url_cc_string&amp;send_to_bcc=$url_bcc_string&amp;".
+                "subject=$url_subj&amp;mailprio=$priority_level&amp;".
+                "ent_num=$ent_num&amp;passed_id=$passed_id&amp;edit_as_new=1";
+
     if ($compose_new_win == '1') {
-        echo ' TARGET="compose_window" onClick="comp_in_new()"';
+        echo "<a href=\"javascript:void(0)\" onclick=\"comp_in_new(false,'$comp_uri')\"";
+    } else {
+        echo '|&nbsp;<A HREF="' . $comp_uri .'"';
     }
     echo '>'.
           _("Edit Message as New") . '</a>';
@@ -737,31 +786,49 @@ if ( !($where && $what) ) {
 
 echo                '</SMALL>' .
                 '</TD><TD WIDTH="33%" ALIGN="RIGHT">' .
-                   '<SMALL>' .
-                   '<A HREF="' . $base_uri . "src/compose.php?forward_id=$passed_id&amp;forward_subj=$url_subj&amp;".
-                    ($default_use_priority?"mailprio=$priority_level&amp;":'')
-                    ."mailbox=$urlMailbox&amp;ent_num=$ent_num\"";
-    if ($compose_new_win == '1') {
-        echo 'TARGET="compose_window" onClick="comp_in_new()"';
-    }
+                   '<SMALL>' ;
+
+$comp_uri = $base_uri . "src/compose.php?forward_id=$passed_id&amp;".
+            "forward_subj=$url_subj&amp;".
+            ($default_use_priority?"mailprio=$priority_level&amp;":'').
+            "mailbox=$urlMailbox&amp;ent_num=$ent_num";
+
+if ($compose_new_win == '1') {
+    echo "<a href=\"javascript:void(0)\" onclick=\"comp_in_new(false,'$comp_uri')\"";
+} else {
+    echo '|&nbsp;<A HREF="' . $comp_uri .'"';
+}
+
     echo '>'.
     _("Forward") .
-    '</A>&nbsp;|&nbsp;' .
-                   '<A HREF="' . $base_uri . "src/compose.php?send_to=$url_replyto&amp;reply_subj=$url_subj&amp;".
-                    ($default_use_priority?"mailprio=$priority_level&amp;":'').
-                    "reply_id=$passed_id&amp;mailbox=$urlMailbox&amp;ent_num=$ent_num\"";
-    if ($compose_new_win == '1') {
-        echo 'TARGET="compose_window" onClick="comp_in_new()"';
-    }
+    '</A>&nbsp;|&nbsp;';
+
+$comp_uri = $base_uri . "src/compose.php?send_to=$url_replyto&amp;".
+            "reply_subj=$url_subj&amp;".
+            ($default_use_priority?"mailprio=$priority_level&amp;":'').
+            "reply_id=$passed_id&amp;mailbox=$urlMailbox&amp;ent_num=$ent_num";
+
+if ($compose_new_win == '1') {
+    echo "<a href=\"javascript:void(0)\" onclick=\"comp_in_new(false,'$comp_uri')\"";
+} else {
+    echo '|&nbsp;<A HREF="' . $comp_uri .'"';
+}
+
     echo '>'.
     _("Reply") .
-    '</A>&nbsp;|&nbsp;' .
-                   '<A HREF="' . $base_uri . "src/compose.php?send_to=$url_replytoall&amp;send_to_cc=$url_replytoallcc&amp;reply_subj=$url_subj&amp;".
-                    ($default_use_priority?"mailprio=$priority_level&amp;":'').
-                    "reply_id=$passed_id&amp;mailbox=$urlMailbox&amp;ent_num=$ent_num\"";
-    if ($compose_new_win == '1') {
-        echo 'TARGET="compose_window" onClick="comp_in_new()"';
-    }
+    '</A>&nbsp;|&nbsp;';
+
+$comp_uri = $base_uri . "src/compose.php?send_to=$url_replytoall&amp;".
+            "send_to_cc=$url_replytoallcc&amp;reply_subj=$url_subj&amp;".
+            ($default_use_priority?"mailprio=$priority_level&amp;":'').
+            "reply_id=$passed_id&amp;mailbox=$urlMailbox&amp;ent_num=$ent_num";
+
+if ($compose_new_win == '1') {
+    echo "<a href=\"javascript:void(0)\" onclick=\"comp_in_new(false,'$comp_uri')\"";
+} else {
+    echo '|&nbsp;<A HREF="' . $comp_uri .'"';
+}
+
     echo '>'.
     _("Reply All") .
     '</A>&nbsp;&nbsp;' .
@@ -807,8 +874,9 @@ echo       '<TR>' .
              '<TD BGCOLOR="' . $color[0] . '" ALIGN="RIGHT">' .
     _("From:") .
              '</TD><TD BGCOLOR="' . $color[0] . '">' .
-                "<B>$from_name</B>&nbsp;\n" .
-             '</TD>' .
+                "<B>$from_name</B>&nbsp;\n";
+                do_hook("read_body_after_from");
+echo             '</TD>' .
           '</TR>';
 /** date **/
 echo       '<TR>' . "\n" .
@@ -890,7 +958,6 @@ if ($default_use_mdn) {
 
         $read = sqimap_run_command ($imapConnection, "FETCH $passed_id FLAGS", true,
                                 $response, $readmessage);
-
         $MDN_flag_present = preg_match( '/.*\$MDNSent/i', $read[0]);
 
         if (trim($MDN_to) &&
@@ -957,8 +1024,7 @@ if ($default_use_mdn) {
                     "               if (window.confirm(\"" .
                     _("The message sender has requested a response to indicate that you have read this message. Would you like to send a receipt?") .
                     "\")) {  \n" .
-                    "                       window.location=($url); \n" .
-                    '                       window.reload()' . "\n" .
+                    '                       window.open('.$url.',"right");' . "\n" .
                     '               }' . "\n" .
                     '// -->' . "\n" .
                     '</script>' . "\n";
@@ -992,6 +1058,7 @@ if ($default_use_mdn) {
                 if ( SendMDN( $MDN_to, $final_recipient ) > 0 && $supportMDN ) {
                     ToggleMDNflag( true);
                 }
+                ClearAttachments();
             }
             $sendreceipt = 'removeMDN';
             $url = "\"read_body.php?mailbox=$mailbox&amp;passed_id=$passed_id&amp;startMessage=$startMessage&amp;show_more=$show_more&amp;sendreceipt=$sendreceipt\"";
@@ -1043,12 +1110,12 @@ echo '</TABLE>' .
     '   </TD></TR>' .
     '</TABLE>';
 flush();
-
 echo "<TABLE CELLSPACING=0 WIDTH=\"97%\" BORDER=0 ALIGN=CENTER CELLPADDING=0>\n" .
     "   <TR><TD BGCOLOR=\"$color[4]\" WIDTH=\"100%\">\n" .
-    '<BR>'.
-    formatBody($imapConnection, $message, $color, $wrap_at).
-    '</TD></TR></TABLE>' .
+    '<BR>';
+echo $body;
+
+echo '</TD></TR></TABLE>' .
     '<TABLE CELLSPACING="0" WIDTH="100%" BORDER="0" ALIGN="CENTER" CELLPADDING="0">' . "\n" .
     "   <TR><TD BGCOLOR=\"$color[9]\">&nbsp;</TD></TR>" .
     '</TABLE>' . "\n";