add proper decoding to To fields, thanks Thierry Godefroy
[squirrelmail.git] / src / read_body.php
index 4197319073ce8585797b5bf9f4c2a6da5cf8dda8..fce8783e244688123968846b7e36299d1170f0ac 100644 (file)
@@ -12,6 +12,9 @@
  * @package squirrelmail
  */
 
+/** This is the read_body page */
+define('PAGE_NAME', 'read_body');
+
 /**
  * Include the SquirrelMail initialization file.
  */
@@ -125,9 +128,9 @@ function ServerMDNSupport($aFlags) {
 }
 
 function SendMDN ( $mailbox, $passed_id, $message, $imapConnection) {
-    global $username, $attachment_dir, $color,
-           $squirrelmail_language, $default_charset,
-           $languages, $useSendmail, $domain, $sent_folder;
+    global $squirrelmail_language, $default_charset, $default_move_to_sent,
+           $languages, $useSendmail, $domain, $sent_folder, $username,
+           $data_dir;
 
     sqgetGlobalVar('SERVER_NAME', $SERVER_NAME, SQ_SERVER);
 
@@ -143,7 +146,7 @@ function SendMDN ( $mailbox, $passed_id, $message, $imapConnection) {
     }
     $rfc822_header->content_type = $content_type;
     $rfc822_header->to[] = $header->dnt;
-    $rfc822_header->subject = _("Read:") . ' ' . encodeHeader($header->subject);
+    $rfc822_header->subject = _("Read:") . ' ' . decodeHeader($header->subject,true,false);
 
     $idents = get_identities();
     $needles = array();
@@ -260,7 +263,7 @@ function SendMDN ( $mailbox, $passed_id, $message, $imapConnection) {
     }
     $success = false;
     if ($stream) {
-        $length  = $deliver->mail($composeMessage, $stream);
+        $deliver->mail($composeMessage, $stream);
         $success = $deliver->finalizeStream($stream);
     }
     if (!$success) {
@@ -271,15 +274,40 @@ function SendMDN ( $mailbox, $passed_id, $message, $imapConnection) {
                 _("Server replied:") . ' ' . $deliver->dlv_ret_nr . ' ' .
                 nl2br(htmlspecialchars($deliver->dlv_server_msg));
         }
-        plain_error_message($msg, $color);
+        plain_error_message($msg);
     } else {
         unset ($deliver);
-        if (sqimap_mailbox_exists ($imapConnection, $sent_folder)) {
-            $sid = sqimap_append ($imapConnection, $sent_folder, $length);
+
+        // move to sent folder
+        //
+        $move_to_sent = getPref($data_dir,$username,'move_to_sent');
+        if (isset($default_move_to_sent) && ($default_move_to_sent != 0)) {
+            $svr_allow_sent = true;
+        } else {
+            $svr_allow_sent = false;
+        }
+
+        if (isset($sent_folder) && (($sent_folder != '') || ($sent_folder != 'none'))
+                && sqimap_mailbox_exists( $imapConnection, $sent_folder)) {
+            $fld_sent = true;
+        } else {
+            $fld_sent = false;
+        }
+
+        if ((isset($move_to_sent) && ($move_to_sent != 0)) || (!isset($move_to_sent))) {
+            $lcl_allow_sent = true;
+        } else {
+            $lcl_allow_sent = false;
+        }
+
+        if (($fld_sent && $svr_allow_sent && !$lcl_allow_sent) || ($fld_sent && $lcl_allow_sent)) {
+            $save_reply_with_orig=getPref($data_dir,$username,'save_reply_with_orig');
+            if ($save_reply_with_orig) {
+                $sent_folder = $mailbox;
+            }
             require_once(SM_PATH . 'class/deliver/Deliver_IMAP.class.php');
             $imap_deliver = new Deliver_IMAP();
-            $imap_deliver->mail($composeMessage, $imapConnection);
-            sqimap_append_done ($imapConnection, $sent_folder);
+            $imap_deliver->mail($composeMessage, $imapConnection, 0, 0, $sent_folder);
             unset ($imap_deliver);
         }
     }
@@ -294,7 +322,7 @@ function ToggleMDNflag ($set ,$imapConnection, $mailbox, $passed_id) {
 }
 
 function formatRecipientString($recipients, $item ) {
-    global $show_more_cc, $show_more, $show_more_bcc,
+    global $show_more, $show_more_cc, $show_more_bcc,
            $PHP_SELF, $oTemplate;
 
     $string = '';
@@ -327,9 +355,10 @@ function formatRecipientString($recipients, $item ) {
         $a = array();
         foreach ($recipients as $r) {
             $a[] = array(
-                            'Name'  => htmlspecialchars($r->getAddress(false)),
+                            // note: decodeHeader is htmlsafe by default
+                            'Name'  => decodeHeader($r->getAddress(false)),
                             'Email' => htmlspecialchars($r->getEmail()),
-                            'Full'  => htmlspecialchars($r->getAddress(true))
+                            'Full'  => decodeHeader($r->getAddress(true))
                         );
         }
 
@@ -374,6 +403,10 @@ function formatEnvheader($aMailbox, $passed_id, $passed_ent_id, $message,
         $oTemplate->assign('xmailer', decodeHeader($header->xmailer));
         $env[_("Mailer")] = $oTemplate->fetch('read_xmailer.tpl');
     }
+
+    // this is used for both mdn and also general use for plugins, etc
+    $oTemplate->assign('first_time_reading', $FirstTimeSee);
+
     if ($default_use_mdn) {
         if ($mdn_user_support) {
             if ($header->dnt) {
@@ -391,9 +424,6 @@ function formatEnvheader($aMailbox, $passed_id, $passed_ent_id, $message,
         }
     }
 
-    // this is used for both mdn and also general use for plugins, etc
-    $oTemplate->assign('first_time_reading', $FirstTimeSee);
-
     $statuses = array();
     if (isset($aMailbox['MSG_HEADERS'][$passed_id]['FLAGS'])) {
         if (isset($aMailbox['MSG_HEADERS'][$passed_id]['FLAGS']['\\deleted']) &&
@@ -428,7 +458,7 @@ function formatEnvheader($aMailbox, $passed_id, $passed_ent_id, $message,
 /**
  * Format message toolbar
  *
- * @param string $mailbox Name of current mailbox
+ * @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
@@ -447,8 +477,6 @@ function formatMenubar($aMailbox, $passed_id, $passed_ent_id, $message, $removed
 
     $urlMailbox = urlencode($mailbox);
 
-    $msgs_url = $base_uri . 'src/';
-
     // Create Prev & Next links
     // Handle nested entities first (i.e. Mime Attach parts)
     $prev_href = $next_href = $up_href = $del_href = $del_prev_href = $del_next_href = '';
@@ -530,11 +558,11 @@ function formatMenubar($aMailbox, $passed_id, $passed_ent_id, $message, $removed
         }
     }
 
-    // Start with Search Results or Message List link.
-    $list_xtra = "?where=read_body.php&what=$what&mailbox=" . $urlMailbox.
-                 "&startMessage=$startMessage";
-    $msg_list_href = $base_uri .'src/right_main.php'. $list_xtra;
-    $search_href = $where=='search.php' ? $base_uri .'src/search.php?'.$list_xtra : '';
+    $msg_list_href = get_message_list_uri($aMailbox['NAME'], $startMessage, $what);
+    if ($where == 'search.php')
+        $search_href = str_replace('read_body.php', 'search.php', $msg_list_href);
+    else
+        $search_href = '';
 
     $comp_uri = $base_uri.'src/compose.php' .
                 '?passed_id=' . $passed_id .
@@ -663,16 +691,26 @@ function formatToolbar($mailbox, $passed_id, $passed_ent_id, $message, $color) {
 
     // Build the printer friend link
     /* hackydiehack */
+
+    // Pull "view_unsafe_images" from the URL to find out if the unsafe images
+    // should be displayed. The default is not to display unsafe images.
     if( !sqgetGlobalVar('view_unsafe_images', $view_unsafe_images, SQ_GET) ) {
+        // If "view_unsafe_images" isn't part of the URL, default to not
+        // displaying unsafe images.
         $view_unsafe_images = false;
     } else {
+        //  If "view_unsafe_images" is part of the URL, display unsafe images
+        //  regardless of the value of the URL variable.
+        // FIXME: Do we really want to display the unsafe images regardless of the value in URL variable?
         $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,
@@ -781,13 +819,13 @@ if(sqgetGlobalVar('view_unsafe_images', $temp)) {
 } else {
     $view_unsafe_images = 0;
 }
+
 /**
  * Retrieve mailbox cache
  */
 sqgetGlobalVar('mailbox_cache',$mailbox_cache,SQ_SESSION);
 
 /* end of get globals */
-global $sqimap_capabilities, $lastTargetMailbox;
 
 $imapConnection = sqimap_login($username, false, $imapServerAddress, $imapPort, 0);
 $aMailbox = sqm_api_mailbox_select($imapConnection, $iAccount, $mailbox,array('setindex' => $what, 'offset' => $startMessage),array());
@@ -947,8 +985,11 @@ $mailbox_cache[$iAccount.'_'.$aMailbox['NAME']] = $aMailbox;
 sqsession_register($mailbox_cache,'mailbox_cache');
 $_SESSION['mailbox_cache'] = $mailbox_cache;
 
+// message list URI is used in page header when on read_body
+$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);
+formatMenubar($aMailbox, $passed_id, $passed_ent_id, $message,false);
 formatEnvheader($aMailbox, $passed_id, $passed_ent_id, $message, $color, $FirstTimeSee);
 
 $oTemplate->assign('message_body', $messagebody);
@@ -977,9 +1018,8 @@ if ($attachment_common_show_images && is_array($attachment_common_show_images_li
     $oTemplate->display('read_display_images_inline.tpl');
 }
 
-formatMenuBar($aMailbox, $passed_id, $passed_ent_id, $message, false, FALSE);
+formatMenubar($aMailbox, $passed_id, $passed_ent_id, $message, false, FALSE);
 
 do_hook('read_body_bottom', $null);
 sqimap_logout($imapConnection);
 $oTemplate->display('footer.tpl');
-?>