Print javascript Content-Type to be HTML 4.0 complient
[squirrelmail.git] / src / read_body.php
index 0aa2c9ef5b46366ec484ab9e161a3f671532bef6..3f0f0bbe8ebf805a98678772dd46d978ec841249 100644 (file)
@@ -139,22 +139,8 @@ function printer_friendly_link() {
 }
 
 function ServerMDNSupport( $read ) {
-
-    $num = 0;
-    $resp = '';
-    while ($num < count($read) ) {
-        $resp .= $read[$num];
-        $num++;
-    }
-    $read[] = split(' * ', $resp);
-    $num = 0;
-    $ret = FALSE;
-    while ( !$ret && $num < count($read) ) {
-        if ( ereg('PERMANENTFLAGS', $read[$num] ) ) {
-            $ret = ( ereg('mdnsent',strtolower($read[$num]) ) || ereg("\\\*", $read[$num] ) );
-        }
-        $num++;
-    }
+    /* escaping $ doesn't work -> \x36 */    
+    $ret = preg_match( '/(\x36MDNSent|\\\*)/i', $read );
     return ( $ret );
 }
 
@@ -162,9 +148,7 @@ function SendMDN ( $recipient , $sender) {
     global $imapConnection, $mailbox, $username, $attachment_dir, $SERVER_NAME,
            $version, $attachments, $identity, $data_dir, $passed_id;
 
-    $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
-    $header = $message->header;
-
+    $header = sqimap_get_message_header($imapConnection, $passed_id, $mailbox);
     $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
 
     // part 1 (RFC2298)
@@ -185,12 +169,7 @@ function SendMDN ( $recipient , $sender) {
             "\t" . _("Sent:") . ' ' . $senton . "\r\n" .
             "\r\n" .
             sprintf( _("Was displayed on %s"), $now );
-/*
-    $body = sprintf( _("This message sent on %s to %s with subject \"%s\" has been displayed on %s."),
-                      $senton, $to, $subject, $now ) .
-            "\r\n" .
-            _("This is no guarantee that the message has been read or understood.") . "\r\n";
-*/
+
     // part2  (RFC2298)
 
     $original_recipient = $to;
@@ -226,20 +205,13 @@ function SendMDN ( $recipient , $sender) {
 
 
 function ToggleMDNflag ( $set ) {
-
     global $imapConnection, $passed_id, $mailbox;
-
-    if ( $set ) {
-        $sg = '+';
-
-    } else {
-        $sg = '-';
-    }
-
-    $cmd = 'STORE ' . $passed_id . ' ' . $sg . 'FLAGS ($MDNSent)';
     sqimap_mailbox_select($imapConnection, $mailbox);
-    $read = sqimap_run_command ($imapConnection, $cmd, true, $response, $readmessage);
-
+    
+    $sg =  $set?'+':'-';
+    $cmd = 'STORE ' . $passed_id . ' ' . $sg . 'FLAGS ($MDNSent)';
+    $read = sqimap_run_command ($imapConnection, $cmd, true, $response, 
+                                $readmessage);
 }
 
 function ClearAttachments() {
@@ -268,8 +240,11 @@ function ClearAttachments() {
     $passed_id
 */
 
+if ( isset( $mailbox ) ) {
+    $mailbox = urldecode( $mailbox );
+}
 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
-$read = sqimap_mailbox_select($imapConnection, $mailbox);
+$read = sqimap_mailbox_select($imapConnection, $mailbox, false, false, true);
 
 do_hook('html_top');
 
@@ -279,7 +254,7 @@ do_hook('html_top');
 if( $default_use_mdn &&
     ( $mdn_user_support = getPref($data_dir, $username, 'mdn_user_support', $default_use_mdn) ) ) {
 
-    $supportMDN = ServerMDNSupport($read);
+    $supportMDN = ServerMDNSupport($read["PERMANENTFLAGS"]);
     $flags = sqimap_get_flags ($imapConnection, $passed_id);
     $FirstTimeSee = !(in_array( 'Seen', $flags ));
 }
@@ -518,6 +493,9 @@ if (isset ($message->header->cc[0]) && trim($message->header->cc[0])) {
         }
     }
 }
+else {
+    $cc_string = '';
+}
 
 /** FORMAT THE BCC STRING **/
 $i = 0;
@@ -559,6 +537,9 @@ if (isset ($message->header->bcc[0]) && trim($message->header->bcc[0])){
         }
     }
 }
+else {
+    $bcc_string = '';
+}
 
 if ($default_use_priority) {
     $priority_level = substr($message->header->priority,0,1);
@@ -619,7 +600,11 @@ 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&send_to=$to_string&send_to_cc=$cc_string&send_to_bcc=$bcc_string&subject=$url_subj&draft_id=$passed_id&ent_num=$ent_num\">".
+         "src/compose.php?mailbox=$mailbox&send_to=$to_string&send_to_cc=$cc_string&send_to_bcc=$bcc_string&subject=$url_subj&draft_id=$passed_id&ent_num=$ent_num\"";
+    if ($compose_new_win == '1') {
+        echo 'TARGET="compose_window" onClick="comp_in_new()"';
+    }
+    echo '>'.
          _("Resume Draft") . '</a>';
 }
 
@@ -656,17 +641,29 @@ echo                '</SMALL>' .
                    '<SMALL>' .
                    '<A HREF="' . $base_uri . "src/compose.php?forward_id=$passed_id&forward_subj=$url_subj&".
                     ($default_use_priority?"mailprio=$priority_level&":"")
-                    ."mailbox=$urlMailbox&ent_num=$ent_num\">" .
+                    ."mailbox=$urlMailbox&ent_num=$ent_num\"";
+    if ($compose_new_win == '1') {
+        echo 'TARGET="compose_window" onClick="comp_in_new()"';
+    }
+    echo '>'.
     _("Forward") .
     '</A>&nbsp;|&nbsp;' .
                    '<A HREF="' . $base_uri . "src/compose.php?send_to=$url_replyto&reply_subj=$url_subj&".
                     ($default_use_priority?"mailprio=$priority_level&":"").
-                    "reply_id=$passed_id&mailbox=$urlMailbox&ent_num=$ent_num\">" .
+                    "reply_id=$passed_id&mailbox=$urlMailbox&ent_num=$ent_num\"";
+    if ($compose_new_win == '1') {
+        echo 'TARGET="compose_window" onClick="comp_in_new()"';
+    }
+    echo '>'.
     _("Reply") .
     '</A>&nbsp;|&nbsp;' .
                    '<A HREF="' . $base_uri . "src/compose.php?send_to=$url_replytoall&send_to_cc=$url_replytoallcc&reply_subj=$url_subj&".
                     ($default_use_priority?"mailprio=$priority_level&":"").
-                    "reply_id=$passed_id&mailbox=$urlMailbox&ent_num=$ent_num\">" .
+                    "reply_id=$passed_id&mailbox=$urlMailbox&ent_num=$ent_num\"";
+    if ($compose_new_win == '1') {
+        echo 'TARGET="compose_window" onClick="comp_in_new()"';
+    }
+    echo '>'.
     _("Reply All") .
     '</A>&nbsp;&nbsp;' .
                    '</SMALL>' .
@@ -732,7 +729,7 @@ echo       "<TR>\n" .
              '</TD>' . "\n" .
           '</TR>' . "\n";
 /** cc **/
-if (isset($cc_string)) {
+if (isset($cc_string) && $cc_string <> '') {
     echo       '<TR>' .
                  "<TD BGCOLOR=\"$color[0]\" ALIGN=RIGHT VALIGN=TOP>" .
                     'Cc:' .
@@ -743,7 +740,7 @@ if (isset($cc_string)) {
 }
 
 /** bcc **/
-if (isset($bcc_string)) {
+if (isset($bcc_string) && $bcc_string <> '') {
     echo       '<TR>'.
                  "<TD BGCOLOR=\"$color[0]\" ALIGN=RIGHT VALIGN=TOP>" .
                     'Bcc:' .
@@ -752,16 +749,14 @@ if (isset($bcc_string)) {
                  '</TD>' .
               '</TR>' . "\n";
 }
-if ($default_use_priority) {
-    if (isset($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";
-    }
+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";
 }
 
 if ($show_xmailer_default) {
@@ -788,7 +783,7 @@ if ($default_use_mdn) {
     if ($mdn_user_support) {
 
         // debug gives you the capability to remove mdn-flags
-        $debug = false;
+        $MDNDebug = false;
         $read = sqimap_run_command ($imapConnection, "FETCH $passed_id BODY.PEEK[HEADER.FIELDS (Disposition-Notification-To)]", true,
                                 $response, $readmessage);
         $MDN_to = substr($read[1], strpos($read[1], ' '));
@@ -806,7 +801,7 @@ if ($default_use_mdn) {
                 $sendreceipt = 'removeMDN';
                 $url = "\"read_body.php?mailbox=$mailbox&passed_id=$passed_id&startMessage=$startMessage&show_more=$show_more&sendreceipt=$sendreceipt\"";
                 $sendreceipt="";
-                if ($debug ) {
+                if ($MDNDebug ) {
                     echo       '<TR>' .
                                  "<TD BGCOLOR=\"$color[9]\"  ALIGN=RIGHT VALIGN=TOP>" .
                                        _("Read receipt") . ': ' .
@@ -827,7 +822,7 @@ if ($default_use_mdn) {
                 }
 
             } // 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])) ) {
+            else if ( ereg('\\Draft',$read[0] || ereg('\\Deleted',$read[0])) ) {
                 echo       '<TR>' .
                             "<TD BGCOLOR=\"$color[9]\"  ALIGN=RIGHT VALIGN=TOP>" .
                                 _("Read receipt") . ': '.
@@ -899,7 +894,7 @@ if ($default_use_mdn) {
             $url = "\"read_body.php?mailbox=$mailbox&passed_id=$passed_id&startMessage=$startMessage&show_more=$show_more&sendreceipt=$sendreceipt\"";
             $sendreceipt="";
 
-            if ($debug && $supportMDN) {
+            if ($MDNDebug && $supportMDN) {
             echo "      <TR>\n" .
                     "         <TD BGCOLOR=\"$color[9]\"  ALIGN=RIGHT VALIGN=TOP>\n" .
                     "            "._("Read receipt").": \n".