moved address-parsing to the displayable headers
[squirrelmail.git] / functions / mailbox_display.php
index 2db6507ed345d344667c17245974079194ad2b90..97f1418bbac8958512b97d7e590d1ded1fd80ff0 100644 (file)
@@ -37,7 +37,7 @@ function elapsed($start)
 function printMessageInfo($imapConnection, $t, $not_last=true, $key, $mailbox,
                           $start_msg, $where, $what) {
     global $checkall,
-           $color, $msgs, $msort,
+           $color, $msgs, $msort, $td_str, $msg, 
            $default_use_priority,
            $message_highlight_list,
            $index_order,
@@ -73,11 +73,13 @@ function printMessageInfo($imapConnection, $t, $not_last=true, $key, $mailbox,
     if (handleAsSent($mailbox)) {
        $msg['FROM'] = $msg['TO'];
     }
+    $msg['FROM'] = parseAddress($msg['FROM']);
+    
        /*
         * This is done in case you're looking into Sent folders,
         * because you can have multiple receivers.
         */
-        
+
     $senderNames = $msg['FROM'];
     $senderName  = '';
     if (sizeof($senderNames)){
@@ -91,11 +93,11 @@ function printMessageInfo($imapConnection, $t, $not_last=true, $key, $mailbox,
                 $senderName .= htmlspecialchars($senderNames_part[0]);
             }
         }
-    } 
-    
-    $subject_full = decodeHeader($msg['SUBJECT']);
-    $subject = processSubject($subject_full, $indent_array[$msg['ID']]);
+    }
 
+    $msg['SUBJECT'] = decodeHeader($msg['SUBJECT']);
+    $subject = processSubject($msg['SUBJECT'], $indent_array[$msg['ID']]);
+    
     echo html_tag( 'tr','','','','VALIGN="top"') . "\n";
 
     if (isset($msg['FLAG_FLAGGED']) && ($msg['FLAG_FLAGGED'] == true)) {
@@ -136,31 +138,56 @@ function printMessageInfo($imapConnection, $t, $not_last=true, $key, $mailbox,
     * AAAAH! Make my eyes stop bleeding!
     * Who wrote this?!
     */
-    if (is_array($message_highlight_list) && count($message_highlight_list)){
+    if (is_array($message_highlight_list) && count($message_highlight_list)) {
+       $msg['TO'] = parseAddress($msg['TO']);
+       $msg['CC'] = parseAddress($msg['CC']);
         foreach ($message_highlight_list as $message_highlight_list_part) {
             if (trim($message_highlight_list_part['value']) != '') {
                 $high_val   = strtolower($message_highlight_list_part['value']);
                 $match_type = strtoupper($message_highlight_list_part['match_type']);
-                if ($match_type == 'TO_CC') {
-                    foreach ($msg['TO'] as $address) {
-                        if (strstr('^^' . strtolower($address[0]), $high_val) ||
-                            strstr('^^' . strtolower($address[1]), $high_val)) {
-                            $hlt_color = $message_highlight_list_part['color'];
-                            continue;
+                switch($match_type) {
+                    case('TO'):
+                    case('TO_CC'):
+                        foreach ($msg['TO'] as $address) {
+                            $address[0] = decodeHeader($address[0]);
+                            $address[1] = decodeHeader($address[1]);
+                            if (strstr('^^' . strtolower($address[0]), $high_val) ||
+                                strstr('^^' . strtolower($address[1]), $high_val)) {
+                                $hlt_color = $message_highlight_list_part['color'];
+                                continue;
+                            }
                         }
-                    }
-                    foreach ($msg['CC'] as $address) {
-                        if( strstr('^^' . strtolower($address[0]), $high_val) ||
-                            strstr('^^' . strtolower($address[1]), $high_val)) {
+                        if($match_type != 'TO_CC') {
+                            break;
+                        }
+                    case('CC'):
+                        foreach ($msg['CC'] as $address) {
+                            $address[0] = decodeHeader($address[0]);
+                            $address[1] = decodeHeader($address[1]);
+                            if( strstr('^^' . strtolower($address[0]), $high_val) ||
+                                strstr('^^' . strtolower($address[1]), $high_val)) {
+                                $hlt_color = $message_highlight_list_part['color'];
+                                continue;
+                            }
+                        }
+                        break;
+                    case('FROM'):
+                        foreach ($msg['FROM'] as $address) {
+                            $address[0] = decodeHeader($address[0]);
+                            $address[1] = decodeHeader($address[1]);
+                            if( strstr('^^' . strtolower($address[0]), $high_val) ||
+                                strstr('^^' . strtolower($address[1]), $high_val)) {
+                                $hlt_color = $message_highlight_list_part['color'];
+                                continue;
+                            }
+                        }
+                        break;
+                    default:
+                        if (strstr('^^' . strtolower($msg[$match_type]), $high_val)) {
                             $hlt_color = $message_highlight_list_part['color'];
                             continue;
                         }
-                    }
-                } else {
-                    if (strstr('^^' . strtolower($msg[$match_type]), $high_val)) {
-                        $hlt_color = $message_highlight_list_part['color'];
-                        continue;
-                    }
+                        break;
                 }
             }
         }
@@ -209,11 +236,11 @@ function printMessageInfo($imapConnection, $t, $not_last=true, $key, $mailbox,
                 $td_str .= '<a href="read_body.php?mailbox='.$urlMailbox
                         .  '&amp;passed_id='. $msg["ID"]
                         .  '&amp;startMessage='.$start_msg.$searchstr.'"';
-                do_hook("subject_link");
-                if ($subject != $subject_full) {
+                $td_str .= ' ' .concat_hook_function('subject_link'); 
+                if ($subject != $msg['SUBJECT']) {
                     $title = get_html_translation_table(HTML_SPECIALCHARS);
                     $title = array_flip($title);
-                    $title = strtr($subject_full, $title);
+                    $title = strtr($msg['SUBJECT'], $title);
                     $title = str_replace('"', "''", $title);
                     $td_str .= " title=\"$title\"";
                 }
@@ -352,6 +379,20 @@ function showMessagesForMailbox($imapConnection, $mailbox, $num_msgs,
     global $msgs, $msort, $auto_expunge, $thread_sort_messages,
            $allow_server_sort, $server_sort_order;
 
+    /*
+     * For some reason, on PHP 4.3+, this being unset, and set in the session causes havoc
+     * so setting it to an empty array beforehand seems to clean up the issue, and stopping the
+     * "Your script possibly relies on a session side-effect which existed until PHP 4.2.3" error
+     */
+
+    if (!isset($msort)) {
+        $msort = array();
+    }
+
+    if (!isset($msgs)) {
+        $msgs = array();
+    }
+
     $start = microtime();
     /* If autoexpunge is turned on, then do it now. */
     $mbxresponse = sqimap_mailbox_select($imapConnection, $mailbox);
@@ -806,7 +847,7 @@ function printHeader($mailbox, $sort, $color, $showsort=true) {
             echo "</td>\n";
             break;
         case 6: /* size */
-            echo html_tag( 'td', '<b>' . _("Size") . '</b>', 'center', '', 'width="5%"' );
+            echo html_tag( 'td', '<b>' . _("Size") . '</b>', 'center', '', 'width="5%" nowrap' );
             break;
         }
     }
@@ -1234,4 +1275,5 @@ function handleAsSent($mailbox) {
     /* And return the result. */
     return $handleAsSent_result;
 }
+
 ?>