Truncate sender taking html entities in account (like Subject)
[squirrelmail.git] / functions / mailbox_display.php
CommitLineData
59177427 1<?php
2ba13803 2
35586184 3/**
4 * mailbox_display.php
5 *
76911253 6 * Copyright (c) 1999-2003 The SquirrelMail Project Team
35586184 7 * Licensed under the GNU GPL. For full terms see the file COPYING.
8 *
9 * This contains functions that display mailbox information, such as the
10 * table row that has sender, date, subject, etc...
11 *
12 * $Id$
13 */
a4c2cd49 14
b68edc75 15require_once(SM_PATH . 'functions/strings.php');
16require_once(SM_PATH . 'functions/html.php');
17require_once(SM_PATH . 'class/html.class.php');
18require_once(SM_PATH . 'functions/imap_mailbox.php');
26454147 19require_once(SM_PATH . 'functions/imap_messages.php');
20require_once(SM_PATH . 'functions/mime.php');
43fdb2a4 21
6dc5eca4 22/* Constants:
23 * PG_SEL_MAX: default value for page_selector_max
24 * SUBJ_TRIM_AT: the length at which we trim off subjects
25 */
6c930ade 26define('PG_SEL_MAX', 10);
6dc5eca4 27define('SUBJ_TRIM_AT', 55);
6c930ade 28
098ea084 29function elapsed($start)
30{
31 $end = microtime();
32 list($start2, $start1) = explode(" ", $start);
33 list($end2, $end1) = explode(" ", $end);
34 $diff1 = $end1 - $start1;
35 $diff2 = $end2 - $start2;
36 if( $diff2 < 0 ){
37 $diff1 -= 1;
38 $diff2 += 1.0;
39 }
40 return $diff2 + $diff1;
41}
42
7b887886 43function printMessageInfo($imapConnection, $t, $not_last=true, $key, $mailbox,
d215ca7d 44 $start_msg, $where, $what) {
8008456a 45 global $checkall,
5bba30b5 46 $color, $msgs, $msort, $td_str, $msg,
c1c17724 47 $default_use_priority,
48 $message_highlight_list,
49 $index_order,
459e3347 50 $indent_array, /* indent subject by */
51 $pos, /* Search postion (if any) */
c1c17724 52 $thread_sort_messages, /* thread sorting on/off */
459e3347 53 $server_sort_order, /* sort value when using server-sorting */
c1c17724 54 $row_count,
459e3347 55 $allow_server_sort, /* enable/disable server-side sorting */
53ad5f60 56 $truncate_sender, /* number of characters for From/To field (<= 0 for unchanged) */
57 $email_address;
459e3347 58
e9e5f0fa 59 $color_string = $color[4];
8008456a 60
61 if ($GLOBALS['alt_index_colors']) {
62 if (!isset($row_count)) {
63 $row_count = 0;
64 }
65 $row_count++;
66 if ($row_count % 2) {
67 if (!isset($color[12])) {
68 $color[12] = '#EAEAEA';
69 }
70 $color_string = $color[12];
71 }
bdfb67f8 72 }
8008456a 73 $msg = $msgs[$key];
74
6a622b59 75 if($mailbox == 'None') {
76 $boxes = sqimap_mailbox_list($imapConnection);
8008456a 77 $mailbox = $boxes[0]['unformatted'];
6a622b59 78 unset($boxes);
bdfb67f8 79 }
8008456a 80 $urlMailbox = urlencode($mailbox);
e9e5f0fa 81
53ad5f60 82 $bSentFolder = handleAsSent($mailbox);
83 // If the From address is the same as $email_address, then handle as Sent
84 $from_array = parseAddress($msg['FROM'], 1);
85 if (!isset($email_address)) {
86 global $datadir, $username;
87 $email_address = getPref($datadir, $username, 'email_address');
098ea084 88 }
53ad5f60 89 $bHandleAsSent = ($bSentFolder) || ((isset($from_array[0][0])) && ($from_array[0][0] == $email_address));
90 // If this is a Sent message, display To address instead of From
91 if ($bHandleAsSent)
92 $msg['FROM'] = $msg['TO'];
93 // Passing 1 below results in only 1 address being parsed, thus defeating the following code
94 $msg['FROM'] = parseAddress($msg['FROM']/*,1*/);
9701e9c8 95
e9e5f0fa 96 /*
97 * This is done in case you're looking into Sent folders,
98 * because you can have multiple receivers.
99 */
098ea084 100 $senderNames = $msg['FROM'];
101 $senderName = '';
26454147 102 $senderAddress = '';
098ea084 103 if (sizeof($senderNames)){
104 foreach ($senderNames as $senderNames_part) {
e9e5f0fa 105 if ($senderName != '') {
106 $senderName .= ', ';
26454147 107 $senderAddress .= ', ';
e9e5f0fa 108 }
26454147 109 $sender_address_part = htmlspecialchars($senderNames_part[0]);
53ad5f60 110 $sender_name_part = str_replace('&nbsp;',' ', decodeHeader($senderNames_part[1]));
26454147 111 if ($sender_name_part) {
112 $senderName .= $sender_name_part;
113 $senderAddress .= $sender_name_part . ' <' . $sender_address_part . '>';
098ea084 114 } else {
26454147 115 $senderName .= $sender_address_part;
116 $senderAddress .= $sender_address_part;
098ea084 117 }
118 }
937c81fa 119 }
53ad5f60 120 // If Sent, prefix with To: but only if not Sent folder
121 if ($bHandleAsSent ^ $bSentFolder) {
122 $senderName = _("To:") . ' ' . $senderName;
123 $senderAddress = _("To:") . ' ' . $senderAddress;
124 }
459e3347 125
eaa4f45f 126 if ($truncate_sender > 0)
127 $senderName = truncateWithEntities($senderName, $truncate_sender);
459e3347 128
5786ef5a 129 echo html_tag( 'tr','','','','VALIGN="top"') . "\n";
8008456a 130
131 if (isset($msg['FLAG_FLAGGED']) && ($msg['FLAG_FLAGGED'] == true)) {
132 $flag = "<font color=\"$color[2]\">";
133 $flag_end = '</font>';
134 } else {
135 $flag = '';
136 $flag_end = '';
bdfb67f8 137 }
8008456a 138 if (!isset($msg['FLAG_SEEN']) || ($msg['FLAG_SEEN'] == false)) {
139 $bold = '<b>';
140 $bold_end = '</b>';
141 } else {
142 $bold = '';
143 $bold_end = '';
bdfb67f8 144 }
53ad5f60 145 if ($bHandleAsSent) {
8008456a 146 $italic = '<i>';
147 $italic_end = '</i>';
148 } else {
149 $italic = '';
150 $italic_end = '';
151 }
152 if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED']) {
153 $fontstr = "<font color=\"$color[9]\">";
154 $fontstr_end = '</font>';
155 } else {
156 $fontstr = '';
157 $fontstr_end = '';
158 }
159
d215ca7d 160 if ($where && $what) {
161 $searchstr = '&amp;where='.$where.'&amp;what='.$what;
162 } else {
163 $searchstr = '';
6a622b59 164 }
9701e9c8 165
937c81fa 166 if (is_array($message_highlight_list) && count($message_highlight_list)) {
8415b2d3 167 $msg['TO'] = parseAddress($msg['TO']);
168 $msg['CC'] = parseAddress($msg['CC']);
8008456a 169 foreach ($message_highlight_list as $message_highlight_list_part) {
170 if (trim($message_highlight_list_part['value']) != '') {
c0d04f97 171 $high_val = strtolower($message_highlight_list_part['value']);
172 $match_type = strtoupper($message_highlight_list_part['match_type']);
8415b2d3 173 if($match_type == 'TO_CC') {
174 $match = array('TO', 'CC');
175 } else {
176 $match = array($match_type);
177 }
178 foreach($match as $match_type) {
179 switch($match_type) {
180 case('TO'):
181 case('CC'):
182 case('FROM'):
183 foreach ($msg[$match_type] as $address) {
9701e9c8 184 $address[0] = decodeHeader($address[0], true, false);
185 $address[1] = decodeHeader($address[1], true, false);
8415b2d3 186 if (strstr('^^' . strtolower($address[0]), $high_val) ||
187 strstr('^^' . strtolower($address[1]), $high_val)) {
188 $hlt_color = $message_highlight_list_part['color'];
189 break 4;
190 }
937c81fa 191 }
937c81fa 192 break;
8415b2d3 193 default:
9701e9c8 194 $headertest = strtolower(decodeHeader($msg[$match_type], true, false));
195 if (strstr('^^' . $headertest, $high_val)) {
937c81fa 196 $hlt_color = $message_highlight_list_part['color'];
8415b2d3 197 break 3;
937c81fa 198 }
8415b2d3 199 break;
200 }
8008456a 201 }
202 }
203 }
204 }
205
206 if (!isset($hlt_color)) {
207 $hlt_color = $color_string;
208 }
59352d08 209 $checked = ($checkall == 1) ? ' CHECKED' : '';
5e0efebf 210 $col = 0;
26454147 211 $msg['SUBJECT'] = str_replace('&nbsp;', ' ', decodeHeader($msg['SUBJECT']));
9701e9c8 212 $subject = processSubject($msg['SUBJECT'], $indent_array[$msg['ID']]);
6a622b59 213 if (sizeof($index_order)) {
8008456a 214 foreach ($index_order as $index_order_part) {
215 switch ($index_order_part) {
216 case 1: /* checkbox */
217 echo html_tag( 'td',
218 "<input type=checkbox name=\"msg[$t]\" value=\"".$msg['ID']."\"$checked>",
6a622b59 219 'center',
8008456a 220 $hlt_color );
221 break;
222 case 2: /* from */
26454147 223 if ($senderAddress != $senderName) {
224 $senderAddress = strtr($senderAddress, array_flip(get_html_translation_table(HTML_SPECIALCHARS)));
225 $title = ' title="' . str_replace('"', "''", $senderAddress) . '"';
226 }
227 else
228 $title = '';
8008456a 229 echo html_tag( 'td',
098ea084 230 $italic . $bold . $flag . $fontstr . $senderName .
8008456a 231 $fontstr_end . $flag_end . $bold_end . $italic_end,
c1c17724 232 'left',
26454147 233 $hlt_color, $title );
8008456a 234 break;
235 case 3: /* date */
53d9fbc5 236 $date_string = $msg['DATE_STRING'] . '';
237 if ($date_string == '') {
238 $date_string = _("Unknown date");
239 }
8008456a 240 echo html_tag( 'td',
53d9fbc5 241 $bold . $flag . $fontstr . $date_string .
8008456a 242 $fontstr_end . $flag_end . $bold_end,
243 'center',
244 $hlt_color,
245 'nowrap' );
246 break;
247 case 4: /* subject */
248 $td_str = $bold;
249 if ($thread_sort_messages == 1) {
6903c7bd 250 if (isset($indent_array[$msg['ID']])) {
8008456a 251 $td_str .= str_repeat("&nbsp;&nbsp;&nbsp;&nbsp;",$indent_array[$msg['ID']]);
252 }
253 }
e9e5f0fa 254 $td_str .= '<a href="read_body.php?mailbox='.$urlMailbox
6a622b59 255 . '&amp;passed_id='. $msg["ID"]
256 . '&amp;startMessage='.$start_msg.$searchstr.'"';
158fa340 257 $td_str .= ' ' .concat_hook_function('subject_link', array($start_msg, $searchstr));
306b6393 258 if ($subject != $msg['SUBJECT']) {
8008456a 259 $title = get_html_translation_table(HTML_SPECIALCHARS);
260 $title = array_flip($title);
306b6393 261 $title = strtr($msg['SUBJECT'], $title);
8008456a 262 $title = str_replace('"', "''", $title);
263 $td_str .= " title=\"$title\"";
264 }
265 $td_str .= ">$flag$subject$flag_end</a>$bold_end";
c1c17724 266 echo html_tag( 'td', $td_str, 'left', $hlt_color );
8008456a 267 break;
268