Removed extra SMALL tags, they were already incased in a
[squirrelmail.git] / src / read_body.php
index a5b1052c3c324787e4591d9a4649fef744997eba..bc4a6aba079f9221876a30aec7edf0b179e7a22d 100644 (file)
@@ -1,9 +1,8 @@
 <?php
-
 /**
  * read_body.php
  *
- * Copyright (c) 1999-2003 The SquirrelMail Project Team
+ * Copyright (c) 1999-2004 The SquirrelMail Project Team
  * Licensed under the GNU GPL. For full terms see the file COPYING.
  *
  * This file is used for reading the msgs array and displaying
@@ -91,10 +90,9 @@ function findPreviousMessage($numMessages, $passed_id) {
     if ($thread_sort_messages || $allow_server_sort ) {
         foreach($server_sort_array as $key=>$value) {
             if ($passed_id == $value) {
-                if ($key == 0) {
-                    break;
+                if ($key != 0) {
+                    $result = $server_sort_array[$key - 1];
                 }
-                $result = $server_sort_array[$key - 1];
                 break;
             }
         }
@@ -316,11 +314,11 @@ function SendMDN ( $mailbox, $passed_id, $sender, $message, $imapConnection) {
     return $success;
 }
 
-function ToggleMDNflag ($set ,$imapConnection, $mailbox, $passed_id, $uid_support) {
+function ToggleMDNflag ($set ,$imapConnection, $mailbox, $passed_id) {
     $sg   =  $set?'+':'-';
     $cmd  = 'STORE ' . $passed_id . ' ' . $sg . 'FLAGS ($MDNSent)';
     $read = sqimap_run_command ($imapConnection, $cmd, true, $response, 
-                                $readmessage, $uid_support);
+                                $readmessage, TRUE);
 }
 
 function ClearAttachments() {
@@ -488,20 +486,15 @@ function formatEnvheader($mailbox, $passed_id, $passed_ent_id, $message,
  */
 function formatMenubar($mailbox, $passed_id, $passed_ent_id, $message, $mbx_response, $nav_on_top = TRUE) {
     global $base_uri, $draft_folder, $where, $what, $color, $sort,
-           $startMessage, $PHP_SELF, $save_as_draft, $uid_support,
+           $startMessage, $PHP_SELF, $save_as_draft, 
            $enable_forward_as_attachment, $imapConnection, $lastTargetMailbox,
-           $data_dir, $username;
+           $data_dir, $username, $delete_prev_next_display,
+           $compose_new_win, $javascript_on;
 
     $topbar_delimiter = '&nbsp;|&nbsp;';
     $double_delimiter = '&nbsp;&nbsp;&nbsp;&nbsp;';
     $urlMailbox = urlencode($mailbox);
 
-    $comp_uri = 'src/compose.php' .
-                '?passed_id=' . $passed_id .
-                '&amp;mailbox=' . $urlMailbox .
-                '&amp;startMessage=' . $startMessage .
-                 (isset($passed_ent_id)?'&amp;passed_ent_id='.$passed_ent_id:'');
-
     $msgs_url = $base_uri . 'src/';
 
     // BEGIN NAV ROW - PREV/NEXT, DEL PREV/NEXT, LINKS TO INDEX, etc.
@@ -552,7 +545,7 @@ function formatMenubar($mailbox, $passed_id, $passed_ent_id, $message, $mbx_resp
         }
 
         $nav_row .= $prev_link . $up_link . $topbar_delimiter . $next_link;
-        $nav_row .= $double_delimiter . '<a href="'.$url.'">'._("View Message").'</a>';
+        $nav_row .= $double_delimiter . '[<a href="'.$url.'">'._("View Message").'</a>]';
 
     // Prev/Next links for regular messages
     } else if ( !(isset($where) && isset($what)) ) {
@@ -576,9 +569,8 @@ function formatMenubar($mailbox, $passed_id, $passed_ent_id, $message, $mbx_resp
         }
 
         // Only bother with Delete & Prev and Delete & Next IF
-        // we have UID support, and top display is enabled.
-        $delete_prev_next_display = getPref($data_dir, $username, 'delete_prev_next_display', 1);
-        if ( $uid_support && $delete_prev_next_display == 1 ) {
+        // top display is enabled.
+        if ( $delete_prev_next_display == 1 ) {
             $del_prev_link = _("Delete & Prev");
             if ($prev >= 0) {
                 $uri = $base_uri . 'src/read_body.php?passed_id='.$prev.
@@ -587,7 +579,6 @@ function formatMenubar($mailbox, $passed_id, $passed_ent_id, $message, $mbx_resp
                        '&amp;delete_id='.$passed_id;
                 $del_prev_link = '<a href="'.$uri.'">'.$del_prev_link.'</a>';       
             }
-            $del_prev_link .= $topbar_delimiter;
 
             $del_next_link = _("Delete & Next");
             if ($next >= 0) {
@@ -597,15 +588,11 @@ function formatMenubar($mailbox, $passed_id, $passed_ent_id, $message, $mbx_resp
                        '&amp;delete_id='.$passed_id;
                 $del_next_link = '<a href="'.$uri.'">'.$del_next_link.'</a>';
             }
-            $del_next_link .= $topbar_delimiter;
-        } else {
-            $del_prev_link = '';
-            $del_next_link = '';
         }
 
-        $nav_row .= $prev_link.$topbar_delimiter 
-                    .$del_prev_link.$del_next_link 
-                    .$next_link;
+        $nav_row .= '['.$prev_link.$topbar_delimiter.$next_link.']';
+        if ( isset($del_prev_link) && isset($del_next_link) )
+            $nav_row .= $double_delimiter.'['.$del_prev_link.$topbar_delimiter.$del_next_link.']';
     }
 
     // Start with Search Results or Message List link.
@@ -619,84 +606,122 @@ function formatMenubar($mailbox, $passed_id, $passed_ent_id, $message, $mbx_resp
         $msgs_str  = _("Message List");
     }
     $nav_row .= $double_delimiter .
-                '<a href="' . $msgs_url . '">' . $msgs_str . '</a>';
+                '[<a href="' . $msgs_url . '">' . $msgs_str . '</a>]';
 
     $nav_row .= '</small></td></tr>';
 
 
     // BEGIN MENU ROW - DELETE/REPLY/FORWARD/MOVE/etc.
     $menu_row = '<tr bgcolor="'.$color[9].'"><td><small>';
+    $comp_uri = $base_uri.'src/compose.php' .
+                '?passed_id=' . $passed_id .
+                '&amp;mailbox=' . $urlMailbox .
+                '&amp;startMessage=' . $startMessage .
+                 (isset($passed_ent_id) ? '&amp;passed_ent_id='.$passed_ent_id : '');
+    // Start form for reply/reply all/forward.. 
+    $target = '';
+    $on_click='';
+    $method='method="post" ';
+    if ($compose_new_win == '1') {
+        if ( $javascript_on ) {
+          $on_click=' onclick="comp_in_new_form(\''.$comp_uri.'\', this, this.form)"';
+          $comp_uri = 'javascript:void(0)';
+          $method='method="get" ';
+        } else {
+          $target = 'target="_blank"';
+        }
+    }
+
+    $menu_row .= "\n".'<form name="composeForm" action="'.$comp_uri.'" '.$method.$target.' style="display: inline">'."\n";
 
     // If Draft folder - create Resume link
     if (($mailbox == $draft_folder) && ($save_as_draft)) {
-        $comp_alt_uri = $comp_uri . '&amp;smaction=draft';
+        $new_button = 'smaction_draft';
         $comp_alt_string = _("Resume Draft");
     } else if (handleAsSent($mailbox)) {
     // If in Sent folder, edit as new
-        $comp_alt_uri = $comp_uri . '&amp;smaction=edit_as_new';
+        $new_button = 'smaction_edit_new';
         $comp_alt_string = _("Edit Message as New");
     }
-
     // Show Alt URI for Draft/Sent
-    if (isset($comp_alt_uri)) {
-        $menu_row .= $topbar_delimiter;
-        $menu_row .= makeComposeLink($comp_alt_uri, $comp_alt_string);
-        $menu_row .= $topbar_delimiter;
-    }
+    if (isset($comp_alt_string))
+        $menu_row .= getButton('SUBMIT', $new_button, $comp_alt_string, $on_click) . "\n";
+
+    $menu_row .= getButton('SUBMIT', 'smaction_reply', _("Reply"), $on_click) . "\n";
+    $menu_row .= getButton('SUBMIT', 'smaction_reply_all', _("Reply All"), $on_click) ."\n";
+    $menu_row .= getButton('SUBMIT', 'smaction_forward', _("Forward"), $on_click);
+    if ($enable_forward_as_attachment)
+        $menu_row .= '<input type="checkbox" name="smaction_attache">' . _("As Attachment") .'&nbsp;&nbsp;'."\n";
+
+    $menu_row .= '</form>&nbsp;';
+
+    // Form for deletion
+    $delete_url = $base_uri . 'src/delete_message.php?mailbox=' . $urlMailbox;
+    $menu_row .= '<form action="'.$delete_url.'" method="post" style="display: inline">';
 
-    $delete_link = _("Delete");
     if (!(isset($passed_ent_id) && $passed_ent_id)) {
-        $delete_url = $base_uri . 'src/delete_message.php?mailbox=' . $urlMailbox .
-                  '&amp;message=' . $passed_id . '&amp;';
+        $menu_row .= '<input type="hidden" name="message" value="'.$passed_id.'" />';
 
         if ($where && $what) {
-            $delete_url .= 'where=' . urlencode($where) . '&amp;what=' . urlencode($what);
+            $menu_row .= '<input type="hidden" name="where" value="'.$where.'" />';
+            $menu_row .= '<input type="hidden" name="what" value="'.$what.'" />';
         } else {
-            $delete_url .= 'sort=' . $sort . '&amp;startMessage=' . $startMessage;
+            $menu_row .= '<input type="hidden" name="sort" value="'.$sort.'" />';
+            $menu_row .= '<input type="hidden" name="startMessage" value="'.$startMessage.'" />';
         }
-        $delete_link = '<a href="' . $delete_url . '">' . $delete_link . '</a>';
+        $menu_row .= getButton('SUBMIT', 'delete', _("Delete"));
+        $menu_row .= '<input type="checkbox" name="bypass_trash">' . _("Bypass Trash");
     }
-    $menu_row .= $delete_link;
-
-    $comp_action_uri = $comp_uri . '&amp;smaction=reply';
-    $menu_row .= $topbar_delimiter;
-    $menu_row .= makeComposeLink($comp_action_uri, _("Reply"));
-
-    $comp_action_uri = $comp_uri . '&amp;smaction=reply_all';
-    $menu_row .= $topbar_delimiter;
-    $menu_row .= makeComposeLink($comp_action_uri, _("Reply All"));
-
+    else
+      $menu_row .= getButton('SUBMIT', 'delete', _("Delete"), '', FALSE) . "\n"; // delete button is disabled
 
-    $comp_action_uri = $comp_uri . '&amp;smaction=forward';
-    $menu_row .= $topbar_delimiter;
-    $menu_row .= makeComposeLink($comp_action_uri, _("Forward"));
+    $menu_row .= '</form>';
 
-    if ($enable_forward_as_attachment) {
-        $comp_action_uri = $comp_uri . '&amp;smaction=forward_as_attachment';
-        $menu_row .= $topbar_delimiter;
-        $menu_row .= makeComposeLink($comp_action_uri, _("Forward as Attachment"));
-    }
 
     // Add top move link
     $menu_row .= '</small></td><td align="right">';
-    if (!(isset($passed_ent_id) && $passed_ent_id)) {
-        $menu_row .= '<form action="read_body.php?mailbox='.$mailbox.'&sort='.$sort.'&startMessage='.$startMessage.'&passed_id='.$next.'" method="post">'.
+    if ( !(isset($passed_ent_id) && $passed_ent_id) ) {
+        
+        $current_box = 'mailbox='.$mailbox.'&sort='.$sort.'&startMessage='.$startMessage;
+
+        // Set subsequent location based on whether or not there is a 'next' message.
+        if ( isset($next) && $next >= 0 ) {
+            $location = $base_uri . 'src/read_body.php?passed_id='.$next.'&';
+        } elseif (isset($prev) && $prev >= 0) {
+            $location = $base_uri . 'src/read_body.php?passed_id='.$prev.'&';
+        } else {
+            $location = $base_uri . 'src/right_main.php?';
+        }
+
+        $menu_row .= '<form action="'.$base_uri.'src/move_messages.php?'.$current_box.'" method="post" style="display: inline">'.
               '<small><input type="hidden" name="show_more" value="0" />'.
-              '<input type="hidden" name="move_id" value="'.$passed_id.'" />'._("Move to:") .
+              '<input type="hidden" name="dmn" value="1" />'.
+              '<input type="hidden" name="location" value="'.$location.$current_box.'" />'.
+              '<input type="hidden" name="msg[0]" value="'.$passed_id.'" />'._("Move to:") .
               '<select name="targetMailbox" style="padding: 0px; margin: 0px">';
+
         if (isset($lastTargetMailbox) && !empty($lastTargetMailbox)) {
             $menu_row .= sqimap_mailbox_option_list($imapConnection, array(strtolower($lastTargetMailbox)));
         } else {
             $menu_row .= sqimap_mailbox_option_list($imapConnection);
         }
-        $menu_row .= '</select> '.
-              '<input type="submit" value="' . _("Move") . '" style="padding: 0px; margin: 0px"/>'.
-              '</small></form>';
+        $menu_row .= '</select> ';
+
+        $menu_row .= getButton('SUBMIT', 'moveButton',_("Move")) . "\n" . '</form>';
     }
     $menu_row .= '</td></tr>';
 
     // echo rows, with hooks
-    do_hook('read_body_menu_top');
+    $ret = do_hook_function('read_body_menu_top', array($nav_row, $menu_row));
+    if (is_array($ret)) {
+        if (isset($ret[0]) && !empty($ret[0])) {
+            $nav_row = $ret[0];
+        }
+        if (isset($ret[1]) && !empty($ret[1])) {
+            $menu_row = $ret[1];
+        }
+    }
     echo '<table width="100%" cellpadding="3" cellspacing="0" align="center" border="0">';
     echo $nav_on_top ? $nav_row . $menu_row : $menu_row . $nav_row;
     echo '</table>'."\n";
@@ -778,7 +803,7 @@ if ( sqgetGlobalVar('startMessage', $temp) ) {
 }
 
 /* end of get globals */
-global $uid_support, $sqimap_capabilities, $auto_expunge, $lastTargetMailbox;
+global $sqimap_capabilities, $lastTargetMailbox;
 
 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
 $mbx_response   = sqimap_mailbox_select($imapConnection, $mailbox, false, false, true);
@@ -788,34 +813,11 @@ $mbx_response   = sqimap_mailbox_select($imapConnection, $mailbox, false, false,
  * but only if delete_id was set
  */
 if ( sqgetGlobalVar('delete_id', $delete_id, SQ_GET) ) {
-//    sqimap_messages_delete($imapConnection, $delete_id, $delete_id, $mailbox);
+    sqimap_messages_delete($imapConnection, $delete_id, $delete_id, $mailbox);
 
-//    if ($auto_expunge) {
-//        sqimap_mailbox_expunge($imapConnection, $mailbox, true);
-//    }    
+    sqimap_mailbox_expunge_dmn($delete_id);
 }
 
-/**
- * Process Move from delete-move-next
- * but only if move_id and target_mailbox were set
- */
-if ( sqgetGlobalVar('move_id', $move_id, SQ_POST) &&
-     sqgetGlobalVar('targetMailbox', $targetMailbox, SQ_POST) ) {
-    // Move message
-//    sqimap_messages_copy($imapConnection, $move_id, $move_id, $targetMailbox);
-//    sqimap_messages_flag($imapConnection, $move_id, $move_id, 'Deleted', true);
-
-//    if ($auto_expunge) {
-//        sqimap_mailbox_expunge($imapConnection, $mailbox, true);
-//    }
-
-//    if ($targetMailbox != $lastTargetMailbox) {
-//        $lastTargetMailbox = $targetMailbox;
-//        sqsession_register('lastTargetMailbox' , $lastTargetMailbox);
-//    }
-}
-
-
 /**
  * $message contains all information about the message
  * including header and body
@@ -826,7 +828,7 @@ $uidvalidity = $mbx_response['UIDVALIDITY'];
 if (!isset($messages[$uidvalidity])) {
    $messages[$uidvalidity] = array();
 }
-if (!isset($messages[$uidvalidity][$passed_id]) || !$uid_support) {
+if (!isset($messages[$uidvalidity][$passed_id])) {
    $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
    $FirstTimeSee = !$message->is_seen;
    $message->is_seen = true;
@@ -842,7 +844,7 @@ if (isset($passed_ent_id) && $passed_ent_id) {
    if ($message->type0 != 'message'  && $message->type1 != 'rfc822') {
       $message = $message->parent;
    }
-   $read = sqimap_run_command ($imapConnection, "FETCH $passed_id BODY[$passed_ent_id.HEADER]", true, $response, $msg, $uid_support);
+   $read = sqimap_run_command ($imapConnection, "FETCH $passed_id BODY[$passed_ent_id.HEADER]", true, $response, $msg, TRUE);
    $rfc822_header = new Rfc822Header();
    $rfc822_header->parseHeader($read);
    $message->rfc822_header = $rfc822_header;
@@ -866,7 +868,7 @@ if (isset($sendreceipt)) {
          $final_recipient = trim(getPref($data_dir, $username, 'email_address', '' ));
       $supportMDN = ServerMDNSupport($mbx_response["PERMANENTFLAGS"]);
       if ( SendMDN( $mailbox, $passed_id, $final_recipient, $message, $imapConnection ) > 0 && $supportMDN ) {
-         ToggleMDNflag( true, $imapConnection, $mailbox, $passed_id, $uid_support);
+         ToggleMDNflag( true, $imapConnection, $mailbox, $passed_id);
          $message->is_mdnsent = true;
          $messages[$uidvalidity][$passed_id]=$message;
       }