fsf changes, meant to be rebased on upstream
[squirrelmail.git] / src / read_body.php
index 0f4990c841aab1d49bff10848814b1f3b91ba885..9e8bb97a52e66eefec90c1a47251608e752b0afe 100644 (file)
@@ -6,9 +6,9 @@
  * This file is used for reading the msgs array and displaying
  * the resulting emails in the right frame.
  *
- * @copyright 1999-2016 The SquirrelMail Project Team
+ * @copyright 1999-2022 The SquirrelMail Project Team
  * @license http://opensource.org/licenses/gpl-license.php GNU Public License
- * @version $Id$
+ * @version $Id: read_body.php 14845 2020-01-07 08:09:34Z pdontthink $
  * @package squirrelmail
  */
 
@@ -37,7 +37,7 @@ require_once(SM_PATH . 'functions/compose.php');
  * and sorted msgs array and return the index of the next message
  *
  * @param int $passed_id The current message UID
- * @return the index of the next valid message from the array
+ * @return the index of the next valid message from the array or -1 if there is no next message
  */
 function findNextMessage($uidset,$passed_id='backwards') {
     if (!is_array($uidset)) {
@@ -59,7 +59,7 @@ function findNextMessage($uidset,$passed_id='backwards') {
  * and sorted msgs array and return the index of the previous message
  *
  * @param int $passed_id The current message UID
- * @return the index of the next valid message from the array
+ * @return the index of the previous valid message from the array or -1 if there is no previous message
  */
 
 function findPreviousMessage($uidset, $passed_id) {
@@ -145,7 +145,10 @@ function SendMDN ( $mailbox, $passed_id, $message, $imapConnection) {
         $content_type->properties['charset']=$default_charset;
     }
     $rfc822_header->content_type = $content_type;
-    $rfc822_header->to[] = $header->dnt;
+    if (!empty($header->dnt))
+        $rfc822_header->to[] = $header->dnt;
+    else
+        $rfc822_header->to[] = $header->dsn;
     $rfc822_header->subject = _("Read:") . ' ' . decodeHeader($header->subject,true,false);
 
     $idents = get_identities();
@@ -410,7 +413,9 @@ function formatEnvheader($aMailbox, $passed_id, $passed_ent_id, $message,
 
     if ($default_use_mdn) {
         if ($mdn_user_support) {
-            if ($header->dnt) {
+            // We are generous to the sender because DSNs are commonly ignored by servers and
+            // technically offering a return receipt in the MUA for a DSN is overstepping the RFCs
+            if ($header->dnt || $header->dnt) {
                 $mdn_url = $PHP_SELF;
                 $mdn_url = set_url_var($mdn_url, 'mailbox', urlencode($mailbox));
                 $mdn_url = set_url_var($mdn_url, 'passed_id', $passed_id);
@@ -479,7 +484,7 @@ function formatMenubar($aMailbox, $passed_id, $passed_ent_id, $message,
            $enable_forward_as_attachment, $imapConnection, $lastTargetMailbox,
            $delete_prev_next_display, $show_copy_buttons,
            $compose_new_win, $compose_width, $compose_height,
-           $oTemplate;
+           $oTemplate, $return_to_message_list_after_move;
 
     //FIXME cleanup argument list, use $aMailbox where possible
     $mailbox = $aMailbox['NAME'];
@@ -640,16 +645,24 @@ function formatMenubar($aMailbox, $passed_id, $passed_ent_id, $message,
 
     $oTemplate->assign('mailboxes', sqimap_mailbox_option_array($imapConnection));
     if (in_array('\\deleted', $aMailbox['PERMANENTFLAGS'],true)) {
-        $delete_url = $base_uri . "src/$where";
         $oTemplate->assign('can_be_deleted', true);
-        $oTemplate->assign('move_delete_form_action', $base_uri.'src/'.$where);
+        // force return-to-message-list if this is the only message in the folder
+        if ($return_to_message_list_after_move || ($next < 0 && $prev < 0))
+            $oTemplate->assign('move_delete_form_action', $base_uri.'src/'.$where);
+        else
+            $oTemplate->assign('move_delete_form_action', $base_uri.'src/read_body.php');
         $oTemplate->assign('delete_form_extra', addHidden('mailbox', $aMailbox['NAME'])."\n" .
                                                 addHidden('msg[0]', $passed_id)."\n" .
+                                                // only need when $return_to_message_list_after_move is off
+                                                addHidden('passed_id', ($next >= 0 ? $next : $prev))."\n" .
                                                 addHidden('startMessage', $startMessage)."\n" );
         if (!(isset($passed_ent_id) && $passed_ent_id)) {
             $oTemplate->assign('can_be_moved', true);
             $oTemplate->assign('move_form_extra', addHidden('mailbox', $aMailbox['NAME'])."\n" .
-                                                  addHidden('msg[0]', $passed_id)."\n" );
+                                                  addHidden('msg[0]', $passed_id)."\n" .
+                                                  // only need when $return_to_message_list_after_move is off
+                                                  addHidden('passed_id', ($next >= 0 ? $next : $prev))."\n" .
+                                                  addHidden('startMessage', $startMessage)."\n" );
             $oTemplate->assign('last_move_target', isset($lastTargetMailbox) && !empty($lastTargetMailbox) ? $lastTargetMailbox : '');
             $oTemplate->assign('can_be_copied', $show_copy_buttons==1);
         } else {
@@ -929,6 +942,21 @@ if ( sqgetGlobalVar('delete_id', $delete_id, SQ_GET) ) {
     handleMessageListForm($imapConnection,$aMailbox,$sButton='setDeleted', array($delete_id));
 }
 
+/**
+ * or delete button... why is handleMessageListForm (per above) conditional anway?
+ */
+if ( sqgetGlobalVar('delete', $ignore, SQ_POST) ) {
+    $sError = handleMessageListForm($imapConnection,$aMailbox);
+}
+
+/**
+ * or move button... why is handleMessageListForm (per above) conditional anway?
+ */
+if ( sqgetGlobalVar('moveButton', $ignore, SQ_POST) ) {
+    $sError = handleMessageListForm($imapConnection,$aMailbox);
+    sqgetGlobalVar('targetMailbox', $lastTargetMailbox, SQ_POST);
+}
+
 /**
  * $message contains all information about the message
  * including header and body
@@ -973,7 +1001,7 @@ $header = $message->header;
 // they SHOULD be included as part of the FETCH responses."
 //
 if ($imap_server_type == 'gmail') {
-    sqimap_toggle_flag($imapConnection, $passed_id, '\\Seen', true, true);
+    sqimap_toggle_flag($imapConnection, array($passed_id), '\\Seen', true, true);
 }
 
 /****************************************/