Happy New Year
[squirrelmail.git] / src / read_body.php
index 6782f46b665850601cc80f19b8ceffb3a9be0148..1a0e54577d9e0b5aa118356a9d83d5f4916c4309 100644 (file)
@@ -6,7 +6,7 @@
  * This file is used for reading the msgs array and displaying
  * the resulting emails in the right frame.
  *
- * @copyright © 1999-2007 The SquirrelMail Project Team
+ * @copyright 1999-2020 The SquirrelMail Project Team
  * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  * @version $Id$
  * @package squirrelmail
@@ -206,7 +206,7 @@ function SendMDN ( $mailbox, $passed_id, $message, $imapConnection) {
     if ($special_encoding) {
         $mime_header->encoding = $special_encoding;
     } else {
-        $mime_header->encoding = 'us-ascii';
+        $mime_header->encoding = '7bit';
     }
     if ($default_charset) {
         $mime_header->parameters['charset'] = $default_charset;
@@ -230,7 +230,7 @@ function SendMDN ( $mailbox, $passed_id, $message, $imapConnection) {
     $mime_header = new MessageHeader;
     $mime_header->type0 = 'message';
     $mime_header->type1 = 'disposition-notification';
-    $mime_header->encoding = 'us-ascii';
+    $mime_header->encoding = '7bit';
     $part2->mime_header = $mime_header;
 
     $composeMessage = new Message();
@@ -255,11 +255,12 @@ function SendMDN ( $mailbox, $passed_id, $message, $imapConnection) {
     } else {
         require_once(SM_PATH . 'class/deliver/Deliver_SMTP.class.php');
         $deliver = new Deliver_SMTP();
-        global $smtpServerAddress, $smtpPort, $pop_before_smtp;
+        global $smtpServerAddress, $smtpPort, $pop_before_smtp, $pop_before_smtp_host;
         $authPop = (isset($pop_before_smtp) && $pop_before_smtp) ? true : false;
+        if (empty($pop_before_smtp_host)) $pop_before_smtp_host = $smtpServerAddress;
         get_smtp_user($user, $pass);
         $stream = $deliver->initStream($composeMessage,$domain,0,
-                                       $smtpServerAddress, $smtpPort, $user, $pass, $authPop);
+                                       $smtpServerAddress, $smtpPort, $user, $pass, $authPop, $pop_before_smtp_host);
     }
     $success = false;
     if ($stream) {
@@ -267,12 +268,12 @@ function SendMDN ( $mailbox, $passed_id, $message, $imapConnection) {
         $success = $deliver->finalizeStream($stream);
     }
     if (!$success) {
-        $msg = _("Message not sent.") . "<br />\n" .
+        $msg = _("Message not sent.") . "\n" .
             $deliver->dlv_msg;
         if (! empty($deliver->dlv_server_msg)) {
-            $msg.= '<br />' .
+            $msg.= "\n" .
                 _("Server replied:") . ' ' . $deliver->dlv_ret_nr . ' ' .
-                nl2br(htmlspecialchars($deliver->dlv_server_msg));
+                nl2br(sm_encode_html_special_chars($deliver->dlv_server_msg));
         }
         plain_error_message($msg);
     } else {
@@ -307,7 +308,7 @@ function SendMDN ( $mailbox, $passed_id, $message, $imapConnection) {
             }
             require_once(SM_PATH . 'class/deliver/Deliver_IMAP.class.php');
             $imap_deliver = new Deliver_IMAP();
-            $imap_deliver->mail($composeMessage, $imapConnection, 0, 0, $sent_folder);
+            $imap_deliver->mail($composeMessage, $imapConnection, 0, 0, $imapConnection, $sent_folder);
             unset ($imap_deliver);
         }
     }
@@ -355,9 +356,10 @@ function formatRecipientString($recipients, $item ) {
         $a = array();
         foreach ($recipients as $r) {
             $a[] = array(
-                            'Name'  => htmlspecialchars($r->getAddress(false)),
-                            'Email' => htmlspecialchars($r->getEmail()),
-                            'Full'  => htmlspecialchars($r->getAddress(true))
+                            // note: decodeHeader is htmlsafe by default
+                            'Name'  => decodeHeader($r->getAddress(false)),
+                            'Email' => sm_encode_html_special_chars($r->getEmail()),
+                            'Full'  => decodeHeader($r->getAddress(true))
                         );
         }
 
@@ -457,13 +459,21 @@ function formatEnvheader($aMailbox, $passed_id, $passed_ent_id, $message,
 /**
  * Format message toolbar
  *
- * @param array $aMailbox Current mailbox information array
- * @param int $passed_id UID of current message
- * @param int $passed_ent_id Id of entity within message
- * @param object $message Current message object
- * @param object $mbx_response
+ * @param array   $aMailbox      Current mailbox information array
+ * @param int     $passed_id     UID of current message
+ * @param int     $passed_ent_id Id of entity within message
+ * @param object  $message       Current message object
+ * @param void    $removedVar    This parameter is no longer used, but remains
+ *                               so as not to break this function's prototype
+ *                               (OPTIONAL)
+ * @param boolean $nav_on_top    When TRUE, the menubar is being constructed
+ *                               for use at the top of the page, otherwise it
+ *                               will be used for page bottom (OPTIONAL;
+ *                               default = TRUE)
  */
-function formatMenubar($aMailbox, $passed_id, $passed_ent_id, $message, $removedVar, $nav_on_top = TRUE) {
+function formatMenubar($aMailbox, $passed_id, $passed_ent_id, $message,
+                       $removedVar=FALSE, $nav_on_top=TRUE) {
+
     global $base_uri, $draft_folder, $where, $what, $sort,
            $startMessage, $PHP_SELF, $save_as_draft,
            $enable_forward_as_attachment, $imapConnection, $lastTargetMailbox,
@@ -544,7 +554,8 @@ function formatMenubar($aMailbox, $passed_id, $passed_ent_id, $message, $removed
                        '&amp;mailbox='.$urlMailbox.'&amp;sort='.$sort.
                        '&amp;startMessage='.$startMessage.'&amp;show_more=0'.
                        "&amp;where=$where&amp;what=$what" .
-                       '&amp;delete_id='.$passed_id;
+                       '&amp;delete_id='.$passed_id .
+                       '&amp;smtoken='.sm_generate_security_token();
             }
 
             if ($next >= 0) {
@@ -552,7 +563,8 @@ function formatMenubar($aMailbox, $passed_id, $passed_ent_id, $message, $removed
                        '&amp;mailbox='.$urlMailbox.'&amp;sort='.$sort.
                        '&amp;startMessage='.$startMessage.'&amp;show_more=0'.
                        "&amp;where=$where&amp;what=$what" .
-                       '&amp;delete_id='.$passed_id;
+                       '&amp;delete_id='.$passed_id .
+                       '&amp;smtoken='.sm_generate_security_token();
             }
         }
     }
@@ -618,8 +630,8 @@ function formatMenubar($aMailbox, $passed_id, $passed_ent_id, $message, $removed
 
     // If Draft folder - create Resume link
     $resume_draft = $edit_as_new = false;
-    if (($mailbox == $draft_folder) && ($save_as_draft)) {
-        $resume_draft = true; 'smaction_draft';
+    if (isDraftMailbox($mailbox) && ($save_as_draft)) {
+        $resume_draft = true;
     } else if (handleAsSent($mailbox)) {
         $edit_as_new = true;
     }
@@ -656,6 +668,33 @@ function formatMenubar($aMailbox, $passed_id, $passed_ent_id, $message, $removed
         $oTemplate->assign('can_be_copied', false);
     }
 
+    // access keys... only add to the top menubar, because adding
+    // them twice makes them less functional (press access key, *then*
+    // press <enter> to make it work)
+    //
+    if ($nav_on_top) {
+        global $accesskey_read_msg_reply, $accesskey_read_msg_reply_all,
+               $accesskey_read_msg_forward, $accesskey_read_msg_as_attach,
+               $accesskey_read_msg_delete, $accesskey_read_msg_bypass_trash,
+               $accesskey_read_msg_move, $accesskey_read_msg_move_to,
+               $accesskey_read_msg_copy;
+    } else {
+        $accesskey_read_msg_reply = $accesskey_read_msg_reply_all =
+        $accesskey_read_msg_forward = $accesskey_read_msg_as_attach =
+        $accesskey_read_msg_delete = $accesskey_read_msg_bypass_trash =
+        $accesskey_read_msg_move = $accesskey_read_msg_move_to =
+        $accesskey_read_msg_copy = 'NONE';
+    }
+    $oTemplate->assign('accesskey_read_msg_reply', $accesskey_read_msg_reply);
+    $oTemplate->assign('accesskey_read_msg_reply_all', $accesskey_read_msg_reply_all);
+    $oTemplate->assign('accesskey_read_msg_forward', $accesskey_read_msg_forward);
+    $oTemplate->assign('accesskey_read_msg_as_attach', $accesskey_read_msg_as_attach);
+    $oTemplate->assign('accesskey_read_msg_delete', $accesskey_read_msg_delete);
+    $oTemplate->assign('accesskey_read_msg_bypass_trash', $accesskey_read_msg_bypass_trash);
+    $oTemplate->assign('accesskey_read_msg_move_to', $accesskey_read_msg_move_to);
+    $oTemplate->assign('accesskey_read_msg_move', $accesskey_read_msg_move);
+    $oTemplate->assign('accesskey_read_msg_copy', $accesskey_read_msg_copy);
+
     global $null;
     do_hook('read_body_menu', $null);
 
@@ -671,7 +710,7 @@ function formatMenubar($aMailbox, $passed_id, $passed_ent_id, $message, $removed
 
 function formatToolbar($mailbox, $passed_id, $passed_ent_id, $message, $color) {
     global $base_uri, $where, $what, $show_html_default,
-           $oTemplate, $download_href,
+           $oTemplate, $download_href, $PHP_SELF,
            $unsafe_image_toggle_href, $unsafe_image_toggle_text;
 
     $urlMailbox = urlencode($mailbox);
@@ -687,35 +726,25 @@ function formatToolbar($mailbox, $passed_id, $passed_ent_id, $message, $color) {
     }
     $url = $base_uri.'src/view_header.php?'.$query_string;
 
-
-    // Build the printer friend link
-    /* hackydiehack */
-
-    // If there's no "view_unsafe_images" setting in the user's preferences,
-    // turn unsafe images off by default.
-    // FIXME: Check if the UIR plugin is enabled. If it's not, no unsafe images should be displayed regardless of the user's preferences. This test is done in several places in the code and they should all be fixed in the same way.
-    if( !sqgetGlobalVar('view_unsafe_images', $view_unsafe_images, SQ_GET) ) {
-        $view_unsafe_images = false;
-    } else {
-        // FIXME: Do we really want to display the unsafe images regardless of the user's preferences?
-        $view_unsafe_images = true;
-    }
-
-    $pf_params = '?passed_ent_id=' . $urlPassed_ent_id .
-                 '&mailbox=' . $urlMailbox .
-                 '&passed_id=' . $urlPassed_id .
-                 '&view_unsafe_images='. (bool) $view_unsafe_images .
-                 '&show_html_default=' . $show_html_default;
-
     $links = array();
     $links[] = array (
                         'URL'   => $url,
                         'Text'  => _("View Full Header")
                      );
-    $links[] = array (
-                        'URL'   => $pf_params,
-                        'Text'  => _("View Printable Version")
+
+    if ( checkForJavaScript() ) { 
+        $links[] = array (
+                        'URL'   => 'javascript:printThis();',
+                        'Text'  => _("Print"),
+                     );
+    } else {
+        $links[] = array (
+                        'URL'   => set_url_var($PHP_SELF, 'print', '1'),
+                        'Text'  => _("Print"),
+                        'Target' => '_blank'
                      );
+    }
+
     $links[] = array (
                         'URL'   => $download_href,
                         'Text'  => _("Download this as a file")
@@ -789,12 +818,10 @@ if ( sqgetGlobalVar('account', $temp,  SQ_GET) ) {
 }
 
 /** GET/POST VARS */
+sqgetGlobalVar('passed_id',     $passed_id, SQ_INORDER, NULL, SQ_TYPE_BIGINT);
 sqgetGlobalVar('passed_ent_id', $passed_ent_id);
 sqgetGlobalVar('mailbox',       $mailbox);
 
-if ( sqgetGlobalVar('passed_id', $temp) ) {
-    $passed_id = (int) $temp;
-}
 if ( sqgetGlobalVar('sort', $temp) ) {
     $sort = (int) $temp;
 }
@@ -815,6 +842,7 @@ if(sqgetGlobalVar('view_unsafe_images', $temp)) {
 } else {
     $view_unsafe_images = 0;
 }
+
 /**
  * Retrieve mailbox cache
  */
@@ -939,6 +967,14 @@ if (isset($passed_ent_id) && $passed_ent_id) {
 }
 $header = $message->header;
 
+// gmail does not mark messages as read when retrieving the message body
+// even though RFC 3501, section 6.4.5 (FETCH Command) says:
+// "The \Seen flag is implicitly set; if this causes the flags to change,
+// they SHOULD be included as part of the FETCH responses."
+//
+if ($imap_server_type == 'gmail') {
+    sqimap_toggle_flag($imapConnection, $passed_id, '\\Seen', true, true);
+}
 
 /****************************************/
 /* Block for handling incoming url vars */
@@ -958,6 +994,8 @@ if (isset($sendreceipt)) {
 /* End of block for handling incoming url vars */
 /***********************************************/
 
+$oTemplate->assign('aAttribs', array('class' => 'entity_sep'));
+$hr = $oTemplate->fetch('horizontal_rule.tpl');
 $messagebody = '';
 do_hook('read_body_top', $null);
 if ($show_html_default == 1) {
@@ -969,7 +1007,7 @@ $cnt = count($ent_ar);
 for ($i = 0; $i < $cnt; $i++) {
    $messagebody .= formatBody($imapConnection, $message, $color, $wrap_at, $ent_ar[$i], $passed_id, $mailbox);
    if ($i != $cnt-1) {
-       $messagebody .= '<hr />';
+       $messagebody .= $hr;
    }
 }
 
@@ -984,7 +1022,13 @@ $_SESSION['mailbox_cache'] = $mailbox_cache;
 $oTemplate->assign('message_list_href', get_message_list_uri($aMailbox['NAME'], $startMessage, $what));
 
 displayPageHeader($color, $mailbox,'','');
-formatMenubar($aMailbox, $passed_id, $passed_ent_id, $message,false);
+
+/* this is the non-javascript version of printer friendly */
+if ( sqgetGlobalVar('print', $print, SQ_GET) ) {
+    $oTemplate->display('read_message_print.tpl');
+} else {
+    formatMenubar($aMailbox, $passed_id, $passed_ent_id, $message,false);
+}
 formatEnvheader($aMailbox, $passed_id, $passed_ent_id, $message, $color, $FirstTimeSee);
 
 $oTemplate->assign('message_body', $messagebody);