Fix from stable that should have gone in here too.
[squirrelmail.git] / functions / mailbox_display.php
index f728bac07786449d2966a950c18f15ad7b363b1a..e3539e0be1c0e09d0bd4fe45607c21e43d15aff8 100644 (file)
  * table row that has sender, date, subject, etc...
  *
  * $Id$
+ * @package squirrelmail
  */
 
+/** The standard includes.. */
 require_once(SM_PATH . 'functions/strings.php');
 require_once(SM_PATH . 'functions/html.php');
 require_once(SM_PATH . 'class/html.class.php');
@@ -19,11 +21,14 @@ require_once(SM_PATH . 'functions/imap_mailbox.php');
 require_once(SM_PATH . 'functions/imap_messages.php');
 require_once(SM_PATH . 'functions/mime.php');
 
-/* Constants:
- *   PG_SEL_MAX:   default value for page_selector_max
+/**
+ * default value for page_selector_max
  */
 define('PG_SEL_MAX', 10);
 
+/**
+ * @param mixed $start UNDOCUMENTED
+ */
 function elapsed($start)
 {
    $end = microtime();
@@ -52,7 +57,8 @@ function printMessageInfo($imapConnection, $t, $not_last=true, $key, $mailbox,
            $row_count,
            $allow_server_sort,    /* enable/disable server-side sorting */
            $truncate_sender,      /* number of characters for From/To field (<= 0 for unchanged) */
-           $email_address;
+           $email_address,
+           $show_recipient_instead;    /* show recipient name instead of default identity */
 
     $color_string = $color[4];
 
@@ -78,13 +84,17 @@ function printMessageInfo($imapConnection, $t, $not_last=true, $key, $mailbox,
     $urlMailbox = urlencode($mailbox);
 
     $bSentFolder = handleAsSent($mailbox);
-    // If the From address is the same as $email_address, then handle as Sent
-    $from_array = parseAddress($msg['FROM'], 1);
-    if (!isset($email_address)) {
-        global $datadir, $username;
-        $email_address = getPref($datadir, $username, 'email_address');
+    if ((!$bSentFolder) && ($show_recipient_instead)) {
+        // If the From address is the same as $email_address, then handle as Sent
+        $from_array = parseAddress($msg['FROM'], 1);
+        if (!isset($email_address)) {
+            global $datadir, $username;
+            $email_address = getPref($datadir, $username, 'email_address');
+        }
+        $bHandleAsSent = ((isset($from_array[0][0])) && ($from_array[0][0] == $email_address));
     }
-    $bHandleAsSent = ($bSentFolder) || ((isset($from_array[0][0])) && ($from_array[0][0] == $email_address));
+    else
+        $bHandleAsSent = $bSentFolder;
     // If this is a Sent message, display To address instead of From
     if ($bHandleAsSent)        
        $msg['FROM'] = $msg['TO'];
@@ -757,7 +767,7 @@ function mail_message_listing_beginning ($imapConnection,
     echo getButton('SUBMIT', 'markRead',_("Read"));
     echo getButton('SUBMIT', 'markUnread',_("Unread"));
     echo getButton('SUBMIT', 'delete',_("Delete")) ."&nbsp;\n";
-    if (!strpos($php_self,'mailbox')) {
+    if (!strpos($php_self,'?')) {
         $location = $php_self.'?mailbox=INBOX&amp;startMessage=1';
     } else {
         $location = $php_self;
@@ -1103,8 +1113,8 @@ function get_paginator_str($box, $start_msg, $end_msg, $num_msgs,
             /* Adjust if the first and second quarters intersect. */
             } else if (($cur_pg - $q2_pgs - ceil($q2_pgs/3)) <= $q1_pgs) {
                 $extra_pgs = $q2_pgs;
-                $extra_pgs -= ceil(($cur_pg - $q1_pgs - 1) * 0.75);
-                $q2_pgs = ceil(($cur_pg - $q1_pgs - 1) * 0.75);
+                $extra_pgs -= ceil(($cur_pg - $q1_pgs - 1) * 3/4);
+                $q2_pgs = ceil(($cur_pg - $q1_pgs - 1) * 3/4);
                 $q3_pgs += ceil($extra_pgs / 2);
                 $q4_pgs += floor($extra_pgs / 2);
 
@@ -1119,8 +1129,8 @@ function get_paginator_str($box, $start_msg, $end_msg, $num_msgs,
             /* Adjust if the third and fourth quarter intersect. */
             } else if (($cur_pg + $q3_pgs + 1) >= ($tot_pgs - $q4_pgs + 1)) {
                 $extra_pgs = $q3_pgs;
-                $extra_pgs -= ceil(($tot_pgs - $cur_pg - $q4_pgs) * 0.75);
-                $q3_pgs = ceil(($tot_pgs - $cur_pg - $q4_pgs) * 0.75);
+                $extra_pgs -= ceil(($tot_pgs - $cur_pg - $q4_pgs) * 3/4);
+                $q3_pgs = ceil(($tot_pgs - $cur_pg - $q4_pgs) * 3/4);
                 $q1_pgs += floor($extra_pgs / 2);
                 $q2_pgs += ceil($extra_pgs / 2);
             }
@@ -1303,6 +1313,7 @@ function getEndMessage($start_msg, $show_num, $num_msgs) {
     return (array($start_msg,$end_msg));
 }
 
+// This should go in imap_mailbox.php
 function handleAsSent($mailbox) {
     global $handleAsSent_result;