put all the information returned from a select in the result
[squirrelmail.git] / src / read_body.php
index 810e158a774ffb6f79b028287d8c7d5bed386837..574284da6f0c1755665df35fe64bc0dd866d2c7d 100644 (file)
@@ -18,6 +18,7 @@ require_once('../functions/mime.php');
 require_once('../functions/date.php');
 require_once('../functions/url_parser.php');
 require_once('../functions/smtp.php');
+require_once('../functions/html.php');
 
 /**
  * Given an IMAP message id number, this will look it up in the cached
@@ -156,13 +157,12 @@ function printer_friendly_link() {
 
     if (!$pf_subtle_link) {
         /* The link is large, on the bottom of the header panel. */
-        $result = '<tr bgcolor="' . $color[0] . '">' .
-            '<td class="medText" align="right" valign="top">' .
-            '&nbsp;' .
-            '</td><td class="medText" valign="top" colspan="2">'."\n";
+        $result = html_tag( 'tr', '', '', $color[0] ) .
+            html_tag( 'td', '&nbsp;', 'right', '', 'class="medText" valign="top"' ) .
+            html_tag( 'td', '', 'left', '', 'class="medText" valign="top" colspan="2"' ) . "\n";
     } else {
         /* The link is subtle, below "view full header". */
-        $result = "<BR>\n";
+        $result = "<br>\n";
     }
 
     /* Output the link. */
@@ -175,10 +175,10 @@ function printer_friendly_link() {
                 "  }\n" .
                 "// -->\n" .
                 "</script>\n" .
-                "<A HREF=\"javascript:printFormat();\">$print_text</A>\n";
+                "<a href=\"javascript:printFormat();\">$print_text</a>\n";
     } else {
-        $result .= '<A TARGET="_blank" HREF="../src/printer_friendly_bottom.php' .
-                "$params\">$print_text</A>\n";
+        $result .= '<A target="_blank" HREF="../src/printer_friendly_bottom.php' .
+                "$params\">$print_text</a>\n";
     }
 
     if (!$pf_subtle_link) {
@@ -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);
@@ -337,31 +336,31 @@ function formatRecipientString($recipients, $item ) {
                 if ($show_more == false) {
                    if ($i == 1) {
                         /* From a search... */
-                        $string .= '&nbsp;(<A HREF="' . $base_uri .
+                        $string .= '&nbsp;(<a href="' . $base_uri .
                             "src/read_body.php?mailbox=$urlMailbox&amp;".
                             "passed_id=$passed_id&amp;";
                         if (isset($where) && isset($what)) {
                            $string .= 'what=' . urlencode($what).
                                 "&amp;where=".urlencode($where).
-                                "$show\">$echo_more</A>)";
+                                "$show\">$echo_more</a>)";
                         } else {
                            $string .= "sort=$sort&amp;startMessage=".
-                                "$startMessage"."$show\">$echo_more</A>)";
+                                "$startMessage"."$show\">$echo_more</a>)";
                         }
                         $i = count($ary);
                    }
                 } else if ($i == 1) {
                    /* From a search... */
-                   $string .= '&nbsp;(<A HREF="' . $base_uri .
+                   $string .= '&nbsp;(<a href="' . $base_uri .
                         "src/read_body.php?mailbox=$urlMailbox&amp;".
                         "passed_id=$passed_id&amp;";
                    if (isset($where) && isset($what)) {
                         $string .= 'what=' . urlencode($what).
                             "&amp;where=".urlencode($where).
-                            "$show_n\">$echo_less</A>)";
+                            "$show_n\">$echo_less</a>)";
                    } else {
                         $string .= "sort=$sort&amp;startMessage=$startMessage".
-                            "$show_n\">$echo_less</A>)";
+                            "$show_n\">$echo_less</a>)";
                    }
                 }
            }
@@ -420,11 +419,11 @@ if (isset($view_hdr)) {
     $read=sqimap_run_command ($imapConnection, "FETCH $passed_id BODY[HEADER]", 
                               true, $a, $b);
     
-    echo '<BR>' .
-        '<TABLE WIDTH="100%" CELLPADDING="2" CELLSPACING="0" BORDER="0"'.
-        ' ALIGN="CENTER">' . "\n" .
-        "   <TR><TD BGCOLOR=\"$color[9]\" WIDTH=\"100%\" ALIGN=\"CENTER\"><B>".
-        _("Viewing Full Header") . '</B> - '.
+    echo '<br>' .
+        html_tag( 'table', '', 'center', '', 'width="100%" cellpadding="2" cellspacing="0" border="0"' ) . "\n" .
+        html_tag( 'tr' ) .
+        html_tag( 'td', '', 'center', $color[9], 'width="100%"' ) .
+        '<b>' . _("Viewing Full Header") . '</b> - '.
         '<a href="' . $base_uri . 'src/read_body.php?mailbox='.
         urlencode($mailbox);
     if (isset($where) && isset($what)) {
@@ -436,9 +435,9 @@ if (isset($view_hdr)) {
             "&amp;show_more=$show_more\">";
     }
     echo _("View message") . "</a></b></td></tr></table>\n".
-        "<table width='99%' cellpadding='2' cellspacing='0' border='0'".
-        "align=center>\n".
-        '<tr><td>';
+        html_tag( 'table', '', 'center', '', 'width="99%" cellpadding="2" cellspacing="0" border="0"' ) . "\n" .
+        html_tag( 'tr' ) .
+        html_tag( 'td' ) .
     
     $cnum = 0;
     for ($i=1; $i < count($read); $i++) {
@@ -471,7 +470,9 @@ if (isset($view_hdr)) {
             $s .= '&nbsp;&nbsp;&nbsp;&nbsp;' . 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,14 +659,56 @@ if (!empty($idents) && $idents > 1) {
 }
 
 do_hook('read_body_top');
-echo '<BR>' .
-     '<TABLE CELLSPACING="0" WIDTH="100%" BORDER="0" ALIGN="CENTER" CELLPADDING="0">' .
-        '<TR><TD BGCOLOR="' . $color[9] . '" WIDTH="100%">' .
-           '<TABLE WIDTH="100%" CELLSPACING="0" BORDER="0" CELLPADDING="3">' .
-              '<TR>' .
-                 '<TD ALIGN="LEFT" WIDTH="33%">' .
-                    '<SMALL>' .
-     '<A HREF="' . $base_uri . 'src/';
+/**
+ * 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>' .
+     html_tag( 'table', '', 'center', '', 'width="100%" cellpadding="0" cellspacing="0" border="0"' ) . "\n" .
+     html_tag( 'tr' ) .
+     html_tag( 'td', '', 'left', $color[9], 'width="100%"' ) .
+     html_tag( 'table', '', '', '', 'width="100%" cellpadding="3" cellspacing="0" border="0"' ) . "\n" .
+     html_tag( 'tr' ) .
+     html_tag( 'td', '', 'left', '', 'width="33%"' ) .
+     '<small>' .
+     '<a href="' . $base_uri . 'src/';
 
 if ($where && $what) {
     if ($pos == '') {
@@ -681,25 +719,25 @@ if ($where && $what) {
     echo "right_main.php?sort=$sort&amp;startMessage=$startMessage&amp;mailbox=$urlMailbox\">";
 }
 echo _("Message List") .
-     '</A>&nbsp;|&nbsp;' .
-     '<A HREF="' . $base_uri . "src/delete_message.php?mailbox=$urlMailbox&amp;message=$passed_id&amp;";
+     '</a>&nbsp;|&nbsp;' .
+     '<a href="' . $base_uri . "src/delete_message.php?mailbox=$urlMailbox&amp;message=$passed_id&amp;";
 if ($where && $what) {
     echo 'where=' . urlencode($where) . '&amp;what=' . urlencode($what) . '">';
 } else {
     echo "sort=$sort&amp;startMessage=$startMessage\">";
 }
-echo _("Delete") . '</A>&nbsp;';
+echo _("Delete") . '</a>&nbsp;';
 if (($mailbox == $draft_folder) && ($save_as_draft)) {
     $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";
-    
+                "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 "<a href=\"javascript:void(0)\" onclick=\"comp_in_new(false,'$comp_uri')\"";
     } else {
-        echo '|&nbsp;<A HREF="' . $comp_uri .'"';
+        echo '|&nbsp;<a href="' . $comp_uri .'"';
     }
     echo '>'.
          _("Resume Draft") . '</a>';
@@ -707,24 +745,24 @@ if (($mailbox == $draft_folder) && ($save_as_draft)) {
 if ($mailbox == $sent_folder) {
     $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";
+                "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 "<a href=\"javascript:void(0)\" onclick=\"comp_in_new(false,'$comp_uri')\"";
     } else {
-        echo '|&nbsp;<A HREF="' . $comp_uri .'"';
+        echo '|&nbsp;<a href="' . $comp_uri .'"';
     }
     echo '>'.
           _("Edit Message as New") . '</a>';
 }
 
 echo '&nbsp;&nbsp;' .
-                   '</SMALL>' .
-                '</TD>' .
-                '<TD WIDTH="33%" ALIGN="CENTER">' .
-                   '<SMALL>';
+                   '</small>' .
+                '</td>' .
+                html_tag( 'td', '', 'center', '', 'width="33%"' ) .
+                   '<small>';
 
 if ( !($where && $what) ) {
     if ($currentArrayIndex == -1) {
@@ -734,52 +772,52 @@ if ( !($where && $what) ) {
         $next = findNextMessage();
 
         if ($prev != -1) {
-            echo '<a href="' . $base_uri . "src/read_body.php?passed_id=$prev&amp;mailbox=$urlMailbox&amp;sort=$sort&amp;startMessage=$startMessage&amp;show_more=0\">" . _("Previous") . "</A>&nbsp;|&nbsp;";
+            echo '<a href="' . $base_uri . "src/read_body.php?passed_id=$prev&amp;mailbox=$urlMailbox&amp;sort=$sort&amp;startMessage=$startMessage&amp;show_more=0\">" . _("Previous") . "</a>&nbsp;|&nbsp;";
         } else {
             echo _("Previous") . '&nbsp;|&nbsp;';
         }
 
         if ($next != -1) {
-            echo '<a href="' . $base_uri . "src/read_body.php?passed_id=$next&amp;mailbox=$urlMailbox&amp;sort=$sort&amp;startMessage=$startMessage&amp;show_more=0\">" . _("Next") . "</A>";
+            echo '<a href="' . $base_uri . "src/read_body.php?passed_id=$next&amp;mailbox=$urlMailbox&amp;sort=$sort&amp;startMessage=$startMessage&amp;show_more=0\">" . _("Next") . "</a>";
         } else {
             echo _("Next");
         }
     }
 }
 
-echo                '</SMALL>' .
-                '</TD><TD WIDTH="33%" ALIGN="RIGHT">' .
-                   '<SMALL>' ;
-
+echo                '</small>' .
+                '</td>' .
+                html_tag( 'td', '', 'right', '', 'width="33%"' ) .
+                   '<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;":'').
+            ($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 '|&nbsp;<a href="' . $comp_uri .'"';
 }
 
     echo '>'.
     _("Forward") .
-    '</A>&nbsp;|&nbsp;';
+    '</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 '|&nbsp;<a href="' . $comp_uri .'"';
 }
 
     echo '>'.
     _("Reply") .
-    '</A>&nbsp;|&nbsp;';
+    '</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;".
@@ -789,38 +827,35 @@ $comp_uri = $base_uri . "src/compose.php?send_to=$url_replytoall&amp;".
 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 '|&nbsp;<a href="' . $comp_uri .'"';
 }
 
     echo '>'.
     _("Reply All") .
-    '</A>&nbsp;&nbsp;' .
-                   '</SMALL>' .
-                '</TD>' .
-             '</TR>' .
-          '</TABLE>' .
-       '</TD></TR>' .
-       '<TR><TD WIDTH="100%">' .
-       '<TABLE WIDTH="100%" BORDER="0" CELLSPACING="0" CELLPADDING="3">' . "\n" .
-          '<TR>' . "\n";
+    '</a>&nbsp;&nbsp;' .
+                   '</small>' .
+                '</td>' .
+             '</tr>' .
+          '</table>' .
+       '</td></tr>' .
+       html_tag( 'tr' ) .
+       html_tag( 'td', '', 'left', '', 'width="100%"' ) .
+       html_tag( 'table', '', '', '', 'width="100%" border="0" cellspacing="0" cellpadding="3"' ) .
+       html_tag( 'tr' ) . "\n";
 
 /** subject **/
-echo          "<TD BGCOLOR=\"$color[0]\" WIDTH=\"10%\" ALIGN=\"right\" VALIGN=\"top\">\n" .
-    _("Subject:") .
-             "</TD><TD BGCOLOR=\"$color[0]\" WIDTH=\"80%\" VALIGN=\"top\">\n" .
-                "<B>$subject</B>&nbsp;\n" .
-             "</TD>\n" .
-             '<TD ROWSPAN="4" width="10%" BGCOLOR="' . $color[0] .
-    '" ALIGN=right VALIGN=top NOWRAP><small>'.
-    '<A HREF="' . $base_uri . "src/read_body.php?mailbox=$urlMailbox&amp;passed_id=$passed_id&amp;";
+echo html_tag( 'td', _("Subject:"), 'right', $color[0], 'width="10%" valign="top"' ) .
+        html_tag( 'td', '<b>' . $subject . '</b>&nbsp;' . "\n", 'left', $color[0], 'width="80%" valign="top"' ) .
+        html_tag( 'td', '', 'right', $color[0], 'rowspan="4" width="10%" valign="top" nowrap' ) .
+             '<a href="' . $base_uri . "src/read_body.php?mailbox=$urlMailbox&amp;passed_id=$passed_id&amp;";
 
 /* From a search... */
 if ($where && $what) {
     echo 'where=' . urlencode($where) . '&amp;what=' . urlencode($what) .
-         "&amp;view_hdr=1\">" . _("View Full Header") . "</A>\n";
+         "&amp;view_hdr=1\">" . _("View Full Header") . "</a>\n";
 } else {
     echo "startMessage=$startMessage&amp;show_more=$show_more&amp;view_hdr=1\">" .
-         _("View Full Header") . "</A>\n";
+         _("View Full Header") . "</a>\n";
 }
 
 /* Output the printer friendly link if we are in subtle mode. */
@@ -829,63 +864,57 @@ if ($pf_subtle_link) {
 }
 
 do_hook("read_body_header_right");
-echo '</small></TD>' .
-    ' </TR>';
+echo '</small></td>' .
+    ' </tr>';
 
 /** from **/
-echo       '<TR>' .
-             '<TD BGCOLOR="' . $color[0] . '" ALIGN="RIGHT">' .
-    _("From:") .
-             '</TD><TD BGCOLOR="' . $color[0] . '">' .
-                "<B>$from_name</B>&nbsp;\n" .
-             '</TD>' .
-          '</TR>';
+echo html_tag( 'tr', "\n" .
+            html_tag( 'td', _("From:"), 'right', $color[0], 'valign="top"' ) .
+            html_tag( 'td',
+                '<b>' . $from_name . '</b>&nbsp;' . "\n" ,
+            'left', $color[0] )
+       ) . "\n";
+       do_hook("read_body_after_from");
 /** date **/
-echo       '<TR>' . "\n" .
-             '<TD BGCOLOR="' . $color[0] . '" ALIGN="RIGHT">' . "\n" .
-    _("Date:") .
-             "</TD><TD BGCOLOR=\"$color[0]\">\n" .
-                "<B>$dateString</B>&nbsp;\n" .
-             '</TD>' . "\n" .
-          '</TR>' . "\n";
-
+echo html_tag( 'tr', "\n" .
+            html_tag( 'td', _("Date:"), 'right', $color[0], 'valign="top"' ) .
+            html_tag( 'td',
+                '<b>' . $dateString . '</b>&nbsp;' . "\n" ,
+            'left', $color[0] )
+       ) . "\n";
 /** to **/
-echo       "<TR>\n" .
-             "<TD BGCOLOR=\"$color[0]\" ALIGN=RIGHT VALIGN=TOP>\n" .
-    _("To:") .
-             '</TD><TD BGCOLOR="' . $color[0] . '" VALIGN="TOP">' . "\n" .
-                "<B>$to_string</B>&nbsp;\n" .
-             '</TD>' . "\n" .
-          '</TR>' . "\n";
+echo html_tag( 'tr', "\n" .
+            html_tag( 'td', _("To:"), 'right', $color[0], 'valign="top"' ) .
+            html_tag( 'td',
+                '<b>' . $to_string . '</b>&nbsp;' . "\n" ,
+            'left', $color[0] )
+       ) . "\n";
 /** cc **/
 if (isset($cc_string) && $cc_string <> '') {
-    echo       '<TR>' .
-                 "<TD BGCOLOR=\"$color[0]\" ALIGN=RIGHT VALIGN=TOP>" .
-                    'Cc:' .
-                 "</TD><TD BGCOLOR=\"$color[0]\" VALIGN=TOP colspan=2>" .
-                    "<B>$cc_string</B>&nbsp;" .
-                 '</TD>' .
-              '</TR>' . "\n";
+    echo html_tag( 'tr', "\n" .
+                html_tag( 'td', _("Cc:"), 'right', $color[0], 'valign="top"' ) .
+                html_tag( 'td',
+                    '<b>' . $cc_string . '</b>&nbsp;' . "\n" ,
+                'left', $color[0], 'colspan="2" valign="top"' )
+           ) . "\n";
 }
 
 /** bcc **/
 if (isset($bcc_string) && $bcc_string <> '') {
-    echo       '<TR>'.
-                 "<TD BGCOLOR=\"$color[0]\" ALIGN=RIGHT VALIGN=TOP>" .
-                    'Bcc:' .
-                 "</TD><TD BGCOLOR=\"$color[0]\" VALIGN=TOP colspan=2>" .
-                    "<B>$bcc_string</B>&nbsp;" .
-                 '</TD>' .
-              '</TR>' . "\n";
+    echo html_tag( 'tr', "\n" .
+                html_tag( 'td', _("Bcc:"), 'right', $color[0], 'valign="top"' ) .
+                html_tag( 'td',
+                    '<b>' . $bcc_string . '</b>&nbsp;' . "\n" ,
+                'left', $color[0], 'colspan="2" valign="top"' )
+           ) . "\n";
 }
 if ($default_use_priority && isset($priority_string) && $priority_string <> '' ) {
-    echo       '<TR>' .
-                 "<TD BGCOLOR=\"$color[0]\" ALIGN=RIGHT VALIGN=TOP>" .
-                       _("Priority") . ': '.
-                 "</TD><TD BGCOLOR=\"$color[0]\" VALIGN=TOP colspan=2>" .
-                    "<B>$priority_string</B>&nbsp;" .
-                 '</TD>' .
-              "</TR>" . "\n";
+    echo html_tag( 'tr', "\n" .
+                html_tag( 'td', _("Priority") . ':', 'right', $color[0], 'valign="top"' ) .
+                html_tag( 'td',
+                    '<b>' . $priority_string . '</b>&nbsp;' . "\n" ,
+                'left', $color[0], 'colspan="2" valign="top"' )
+           ) . "\n";
 }
 
 if ($show_xmailer_default) {
@@ -893,13 +922,12 @@ if ($show_xmailer_default) {
                             $response, $readmessage);
     $mailer = substr($read[1], strpos($read[1], " "));
     if (trim($mailer)) {
-        echo       '<TR>' .
-                     "<TD BGCOLOR=\"$color[0]\" ALIGN=RIGHT VALIGN=TOP>" .
-                           _("Mailer") . ': '.
-                     "</TD><TD BGCOLOR=\"$color[0]\" VALIGN=TOP colspan=2>" .
-                        "<B>$mailer</B>&nbsp;" .
-                     '</TD>' .
-                  "</TR>" . "\n";
+       echo html_tag( 'tr', "\n" .
+                   html_tag( 'td', _("Mailer") . ':', 'right', $color[0], 'valign="top"' ) .
+                   html_tag( 'td',
+                       '<b>' . $mailer . '</b>&nbsp;' ,
+                   'left', $color[0], 'colspan="2" valign="top"' )
+              ) . "\n";
     }
 }
 
@@ -920,7 +948,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) &&
@@ -932,50 +959,43 @@ if ($default_use_mdn) {
                 $sendreceipt='';
                 /*
                 if ($MDNDebug ) {
-                    echo       '<TR>' .
-                                 "<TD BGCOLOR=\"$color[9]\"  ALIGN=RIGHT VALIGN=TOP>" .
-                                       _("Read receipt") . ': ' .
-                                 "</TD><TD BGCOLOR=\"$color[9]\" VALIGN=TOP colspan=2>" .
-                                    '<B>' .
-                                    _("send") .
-                                    "</B> <a href=$url>[" . _("Remove MDN flag") . ']  </a>'  .
-                                 '</TD>' .
-                             '</TR>' . "\n";
+                    echo html_tag( 'tr', "\n" .
+                                html_tag( 'td', _("Read receipt") . ':', 'right', $color[9], 'valign="top"' ) .
+                                html_tag( 'td',
+                                    '<b>' . _("send") . '</b>&nbsp;<a href="' . $url . '">[' . _("Remove MDN flag") . ']  </a>&nbsp;' ,
+                                'left', $color[9], 'colspan="2" valign="top"' )
+                            ) . "\n";
                 } else {
                 */
-                echo       '<TR>' .
-                             "<TD BGCOLOR=\"$color[9]\"  ALIGN=RIGHT VALIGN=TOP>" .
-                                   _("Read receipt") . ': ' .
-                             "</TD><TD BGCOLOR=\"$color[9]\" VALIGN=TOP colspan=2>" .
-                                '<B>'._("send").'</B>'.
-                             '</TD>' .
-                         '</TR>' . "\n";
+                echo html_tag( 'tr', "\n" .
+                            html_tag( 'td', _("Read receipt") . ':', 'right', $color[9], 'valign="top"' ) .
+                                html_tag( 'td',
+                                    '<b>' . _("send") . '</b>&nbsp;' ,
+                                'left', $color[9], 'colspan="2" valign="top"' )
+                            ) . "\n";
                 /*
                 }
                 */
 
             } // when deleted or draft flag is set don't offer to send a MDN response
             else if ( ereg('\\Draft',$read[0] || ereg('\\Deleted',$read[0])) ) {
-                echo       '<TR>' .
-                            "<TD BGCOLOR=\"$color[9]\"  ALIGN=RIGHT VALIGN=TOP>" .
-                                _("Read receipt") . ': '.
-                            "</TD><TD BGCOLOR=\"$color[9]\" VALIGN=TOP colspan=2>" .
-                                '<B>' . _("requested") . "</B>" .
-                            '</TD>' .
-                        '</TR>' . "\n";
+                echo html_tag( 'tr', "\n" .
+                            html_tag( 'td', _("Read receipt") . ':', 'right', $color[9], 'valign="top"' ) .
+                                html_tag( 'td',
+                                    '<b>' . _("requested") . '</b>&nbsp;' ,
+                                'left', $color[9], 'colspan="2" valign="top"' )
+                            ) . "\n";
             }
             // if no MDNsupport don't use the annoying popup messages
             else if (  !$FirstTimeSee ) {
                 $sendreceipt = 'send';
                 $url = "\"read_body.php?mailbox=$mailbox&passed_id=$passed_id&startMessage=$startMessage&show_more=$show_more&sendreceipt=$sendreceipt\"";
-                echo       '<TR>' .
-                            "<TD BGCOLOR=\"$color[9]\"  ALIGN=RIGHT VALIGN=TOP>" .
-                                _("Read receipt") . ': ' .
-                            "</TD><TD BGCOLOR=\"$color[9]\" VALIGN=TOP colspan=2>" .
-                                '<B>' . _("requested") .
-                                "</B> &nbsp; <a href=$url>[" . _("Send read receipt now") . "]</a>" .
-                            '</TD>' .
-                        '</TR>' . "\n";
+                echo html_tag( 'tr', "\n" .
+                            html_tag( 'td', _("Read receipt") . ':', 'right', $color[9], 'valign="top"' ) .
+                                html_tag( 'td',
+                                    '<b>' . _("requested") . '</b> &nbsp; <a href="' . $url . '">[' . _("Send read receipt now") . ']</a>',
+                                'left', $color[9], 'colspan="2" valign="top"' )
+                            ) . "\n";
                 $sendreceipt='';
             }
             else {
@@ -987,20 +1007,17 @@ 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.location.reload()' . "\n" .
+                    '                       window.open('.$url.',"right");' . "\n" .
                     '               }' . "\n" .
                     '// -->' . "\n" .
                     '</script>' . "\n";
                 }
-                echo       '<TR>' .
-                            "<TD BGCOLOR=\"$color[9]\"  ALIGN=RIGHT VALIGN=TOP>" .
-                                    _("Read receipt") . ': ' .
-                            "</TD><TD BGCOLOR=\"$color[9]\" VALIGN=TOP colspan=2>" .
-                                '<B>' . _("requested") . "&nbsp&nbsp</B><a href=$url>" . '[' .
-                                _("Send read receipt now") . ']  </a>' ." \n" .
-                            '</TD>' .
-                            '</TR>' . "\n";
+                echo html_tag( 'tr', "\n" .
+                            html_tag( 'td', _("Read receipt") . ':', 'right', $color[9], 'valign="top"' ) .
+                                html_tag( 'td',
+                                    '<b>' . _("requested") . '</b>&nbsp&nbsp<a href="' . $url . '">[' . _("Send read receipt now") . ']</a>',
+                                'left', $color[9], 'colspan="2" valign="top"' )
+                            ) . "\n";
                 $sendreceipt = '';
             }
         }
@@ -1022,28 +1039,27 @@ 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\"";
             $sendreceipt='';
             /*
             if ($MDNDebug && $supportMDN) {
-            echo "      <TR>\n" .
-                    "         <TD BGCOLOR=\"$color[9]\"  ALIGN=RIGHT VALIGN=TOP>\n" .
-                    "            "._("Read receipt").": \n".
-                    "         </TD><TD BGCOLOR=\"$color[9]\" VALIGN=TOP colspan=2>\n" .
-                    '            <B>'._("send").'</B>'." <a href=$url>" . '[' . _("Remove MDN flag") . ']  </a>'  . "\n" .
-                    '         </TD>' . "\n" .
-                    '     </TR>' . "\n";
+            echo html_tag( 'tr', "\n" .
+                       html_tag( 'td', _("Read receipt") . ':', 'right', $color[9], 'valign="top"' ) .
+                           html_tag( 'td',
+                               '<b>' . _("send") . '</b>&nbsp&nbsp<a href="' . $url . '">[' . _("Remove MDN flag") . ']</a>',
+                           'left', $color[9], 'colspan="2" valign="top"' )
+                       ) . "\n";
             } else {
             */
-            echo "      <TR>\n" .
-                    "         <TD BGCOLOR=\"$color[9]\"  ALIGN=RIGHT VALIGN=TOP>\n" .
-                    "            "._("Read receipt").": \n".
-                    "         </TD><TD BGCOLOR=\"$color[9]\" VALIGN=TOP colspan=2>\n" .
-                    '            <B>'._("send").'</B>'. "\n" .
-                    '         </TD>' . "\n" .
-                    '     </TR>' . "\n";
+            echo html_tag( 'tr', "\n" .
+                       html_tag( 'td', _("Read receipt") . ':', 'right', $color[9], 'valign="top"' ) .
+                           html_tag( 'td',
+                               '<b>' . _("send") . '</b>&nbsp',
+                           'left', $color[9], 'colspan="2" valign="top"' )
+                       ) . "\n";
             /*
             }
             */
@@ -1053,14 +1069,12 @@ if ($default_use_mdn) {
 
             $sendreceipt = 'send';
                 $url = "\"read_body.php?mailbox=$mailbox&amp;passed_id=$passed_id&amp;startMessage=$startMessage&amp;show_more=$show_more&amp;sendreceipt=$sendreceipt\"";
-                echo       '<TR>'.
-                              "<TD BGCOLOR=\"$color[9]\"  ALIGN=RIGHT VALIGN=TOP>" .
-                                    _("Read receipt") . ': ' .
-                              "</TD><TD BGCOLOR=\"$color[9]\" VALIGN=TOP colspan=2>" .
-                                 '<B>' . _("requested") .
-                                 "</B> &nbsp; <a href=$url>[" . _("Send read receipt now") . "]</a>" .
-                              '</TD>' .
-                            '</TR>' . "\n";
+                echo html_tag( 'tr', "\n" .
+                           html_tag( 'td', _("Read receipt") . ':', 'right', $color[9], 'valign="top"' ) .
+                           html_tag( 'td',
+                               '<b>' . _("requested") . '</b> &nbsp; <a href="' . $url . '">[' . _("Send read receipt now") . ']</a>',
+                           'left', $color[9], 'colspan="2" valign="top"' )
+                       ) . "\n";
             $sendreceipt = '';
 
         }
@@ -1069,19 +1083,23 @@ if ($default_use_mdn) {
 
 do_hook('read_body_header');
 
-echo '</TABLE>' .
-    '   </TD></TR>' .
-    '</TABLE>';
+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>' .
-    '<TABLE CELLSPACING="0" WIDTH="100%" BORDER="0" ALIGN="CENTER" CELLPADDING="0">' . "\n" .
-    "   <TR><TD BGCOLOR=\"$color[9]\">&nbsp;</TD></TR>" .
-    '</TABLE>' . "\n";
+echo html_tag( 'table', "\n" .
+            html_tag( 'tr', "\n" .
+                html_tag( 'td', '<br>' . "\n" . $body . "\n", 'left', $color[4]
+                )
+            ) ,
+        'center', '', 'cellspacing=0 width="97%" border="0" cellpadding="0"') .
+
+        html_tag( 'table', "\n" .
+                   html_tag( 'tr', "\n" .
+                       html_tag( 'td', '&nbsp;', 'left', $color[9]
+                       )
+                   ) ,
+        'center', '', 'cellspacing=0 width="100%" border="0" cellpadding="0"');
 
 /* show attached images inline -- if pref'fed so */
 if (($attachment_common_show_images) &&
@@ -1095,14 +1113,12 @@ if (($attachment_common_show_images) &&
                 '&amp;passed_ent_id=' . urlencode($img['ent_id']) .
                 '&amp;absolute_dl=true';
 
-        echo "<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=2 ALIGN=CENTER>\n" .
-              '<TR>' .
-                '<TD>' .
-                  "<img src=\"$imgurl\">\n" .
-                "</TD>\n" .
-              "</TR>\n" .
-            "</TABLE>\n";
-
+        echo html_tag( 'table', "\n" .
+                   html_tag( 'tr', "\n" .
+                       html_tag( 'td', '<img src="' . $imgurl . '">' ."\n", 'left'
+                       )
+                   ) ,
+        'center', '', 'cellspacing=0 border="0" cellpadding="2"');
     }
 }