* Removed the unnecessary function replace_escaped_spaces (never used)
[squirrelmail.git] / functions / mailbox_display.php
1 <?php
2
3 /**
4 ** mailbox_display.php
5 **
6 ** This contains functions that display mailbox information, such as the
7 ** table row that has sender, date, subject, etc...
8 **
9 ** $Id$
10 **/
11
12 $mailbox_display_php = true;
13
14 function printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $startMessage, $where, $what) {
15 global $checkall;
16 global $color, $msgs, $msort;
17 global $sent_folder;
18 global $message_highlight_list;
19 global $index_order;
20
21 $msg = $msgs[$key];
22
23 $senderName = sqimap_find_displayable_name($msg['FROM']);
24 $urlMailbox = urlencode($mailbox);
25 $subject = processSubject($msg['SUBJECT']);
26
27 echo "<TR>\n";
28
29 if (isset($msg['FLAG_FLAGGED']) && $msg['FLAG_FLAGGED'] == true)
30 {
31 $flag = "<font color=$color[2]>";
32 $flag_end = '</font>';
33 }
34 else
35 {
36 $flag = '';
37 $flag_end = '';
38 }
39 if (!isset($msg['FLAG_SEEN']) || $msg['FLAG_SEEN'] == false)
40 {
41 $bold = '<b>';
42 $bold_end = '</b>';
43 }
44 else
45 {
46 $bold = '';
47 $bold_end = '';
48 }
49 if ($mailbox == $sent_folder)
50 {
51 $italic = '<i>';
52 $italic_end = '</i>';
53 }
54 else
55 {
56 $italic = '';
57 $italic_end = '';
58 }
59 if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED'])
60 {
61 $fontstr = "<font color=\"$color[9]\">";
62 $fontstr_end = '</font>';
63 }
64 else
65 {
66 $fontstr = '';
67 $fontstr_end = '';
68 }
69
70 for ($i=0; $i < count($message_highlight_list); $i++) {
71 if (trim($message_highlight_list[$i]['value']) != '') {
72 if ($message_highlight_list[$i]['match_type'] == 'to_cc') {
73 if (strpos('^^'.strtolower($msg['TO']), strtolower($message_highlight_list[$i]['value'])) || strpos('^^'.strtolower($msg['CC']), strtolower($message_highlight_list[$i]['value']))) {
74 $hlt_color = $message_highlight_list[$i]['color'];
75 continue;
76 }
77 } else if (strpos('^^'.strtolower($msg[strtoupper($message_highlight_list[$i]['match_type'])]),strtolower($message_highlight_list[$i]['value']))) {
78 $hlt_color = $message_highlight_list[$i]['color'];
79 continue;
80 }
81 }
82 }
83
84 if (!isset($hlt_color))
85 $hlt_color = $color[4];
86
87 if ($where && $what) {
88 $search_stuff = '&where='.urlencode($where).'&what='.urlencode($what);
89 }
90
91 if ($checkall == 1)
92 $checked = ' checked';
93 else
94 $checked = '';
95
96 for ($i=1; $i <= count($index_order); $i++) {
97 switch ($index_order[$i]) {
98 case 1: # checkbox
99 echo " <td width=1% bgcolor=$hlt_color align=center><input type=checkbox name=\"msg[$t]\" value=".$msg["ID"]."$checked></TD>\n";
100 break;
101 case 2: # from
102 echo " <td width=30% bgcolor=$hlt_color>$italic$bold$flag$fontstr$senderName$fontstr_end$flag_end$bold_end$italic_end</td>\n";
103 break;
104 case 3: # date
105 echo " <td nowrap width=1% bgcolor=$hlt_color><center>$bold$flag$fontstr".$msg["DATE_STRING"]."$fontstr_end$flag_end$bold_end</center></td>\n";
106 break;
107 case 4: # subject
108 echo " <td bgcolor=$hlt_color>$bold";
109 if (! isset($search_stuff)) { $search_stuff = ''; }
110 echo "<a href=\"read_body.php?mailbox=$urlMailbox&passed_id=".$msg["ID"]."&startMessage=$startMessage&show_more=0$search_stuff\"";
111 do_hook("subject_link");
112 echo ">$flag$subject$flag_end</a>$bold_end</td>\n";
113 break;
114 case 5: # flags
115 $stuff = false;
116 echo " <td bgcolor=$hlt_color align=center width=1% nowrap><b><small>\n";
117 if (isset($msg['FLAG_ANSWERED']) &&
118 $msg['FLAG_ANSWERED'] == true) {
119 echo "A\n";
120 $stuff = true;
121 }
122 if ($msg['TYPE0'] == 'multipart') {
123 echo "+\n";
124 $stuff = true;
125 }
126 if (ereg('(1|2)',substr($msg['PRIORITY'],0,1))) {
127 echo "<font color=$color[1]>!</font>\n";
128 $stuff = true;
129 }
130 if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED']) {
131 echo "<font color=\"$color[1]\">D</font>\n";
132 $stuff = true;
133 }
134
135 if (!$stuff) echo "&nbsp;\n";
136 echo "</small></b></td>\n";
137 break;
138 case 6: # size
139 echo " <td bgcolor=$hlt_color width=1%>$bold$fontstr".show_readable_size($msg['SIZE'])."$fontstr_end$bold_end</td>\n";
140 break;
141 }
142 }
143
144
145 echo "</tr>\n";
146 }
147
148 /**
149 ** This function loops through a group of messages in the mailbox and shows them
150 **/
151 function showMessagesForMailbox($imapConnection, $mailbox, $numMessages, $startMessage, $sort, $color,$show_num, $use_cache) {
152 global $msgs, $msort;
153 global $sent_folder;
154 global $message_highlight_list;
155 global $auto_expunge;
156
157 if ($auto_expunge == true) sqimap_mailbox_expunge($imapConnection, $mailbox, false);
158 sqimap_mailbox_select($imapConnection, $mailbox);
159
160 if (!$use_cache) {
161 // if it's sorted
162 if ($numMessages >= 1) {
163 if ($sort < 6) {
164 for ($q = 0; $q < $numMessages; $q++) {
165 if($mailbox == $sent_folder)
166 $hdr = sqimap_get_small_header ($imapConnection, $q+1, true);
167 else
168 $hdr = sqimap_get_small_header ($imapConnection, $q+1, false);
169
170 $from[$q] = $hdr->from;
171 $date[$q] = $hdr->date;
172 $subject[$q] = $hdr->subject;
173 $to[$q] = $hdr->to;
174 $priority[$q] = $hdr->priority;
175 $cc[$q] = $hdr->cc;
176 $size[$q] = $hdr->size;
177 $type[$q] = $hdr->type0;
178 $flags[$q] = sqimap_get_flags ($imapConnection, $q+1);
179 $id[$q] = $q + 1;
180 }
181 } else {
182 // if it's not sorted
183 if ($startMessage + ($show_num - 1) < $numMessages) {
184 $endMessage = $startMessage + ($show_num-1);
185 } else {
186 $endMessage = $numMessages;
187 }
188
189 if ($endMessage < $startMessage) {
190 $startMessage = $startMessage - $show_num;
191 if ($startMessage < 1)
192 $startMessage = 1;
193 }
194
195
196 $real_startMessage = $numMessages - $startMessage + 1;
197 $real_endMessage = $numMessages - $startMessage - $show_num;
198 if ($real_endMessage <= 0)
199 $real_endMessage = 1;
200
201 $j = 0;
202 for ($q = $real_startMessage; $q >= $real_endMessage; $q--) {
203 if($mailbox == $sent_folder)
204 $hdr = sqimap_get_small_header ($imapConnection, $q, true);
205 else
206 $hdr = sqimap_get_small_header ($imapConnection, $q, false);
207
208 $from[$j] = $hdr->from;
209 $date[$j] = $hdr->date;
210 $subject[$j] = $hdr->subject;
211 $to[$j] = $hdr->to;
212 $priority[$j] = $hdr->priority;
213 $cc[$j] = $hdr->cc;
214 $size[$j] = $hdr->size;
215 $type[$j] = $hdr->type0;
216 $flags[$j] = sqimap_get_flags ($imapConnection, $q);
217 $id[$j] = $q;
218 $j++;
219 }
220 }
221 }
222
223 $j = 0;
224 if ($sort == 6) {
225 $end = $startMessage + $show_num - 1;
226 if ($numMessages < $show_num)
227 $end_loop = $numMessages;
228 else
229 $end_loop = $show_num;
230 } else {
231 $end = $numMessages;
232 $end_loop = $end;
233 }
234 if ($end > $numMessages) $end = $numMessages;
235 while ($j < $end_loop) {
236 if (isset($date[$j])) {
237 $date[$j] = ereg_replace(' ', ' ', $date[$j]);
238 $tmpdate = explode(' ', trim($date[$j]));
239 } else {
240 $tmpdate = $date = array("","","","","","");
241 }
242
243 $messages[$j]['TIME_STAMP'] = getTimeStamp($tmpdate);
244 $messages[$j]['DATE_STRING'] = getDateString($messages[$j]['TIME_STAMP']);
245 $messages[$j]['ID'] = $id[$j];
246 $messages[$j]['FROM'] = decodeHeader($from[$j]);
247 $messages[$j]['FROM-SORT'] = strtolower(sqimap_find_displayable_name(decodeHeader($from[$j])));
248 $messages[$j]['SUBJECT'] = decodeHeader($subject[$j]);
249 $messages[$j]['SUBJECT-SORT'] = strtolower(decodeHeader($subject[$j]));
250 $messages[$j]['TO'] = decodeHeader($to[$j]);
251 $messages[$j]['PRIORITY'] = $priority[$j];
252 $messages[$j]['CC'] = $cc[$j];
253 $messages[$j]['SIZE'] = $size[$j];
254 $messages[$j]['TYPE0'] = $type[$j];
255
256 # fix SUBJECT-SORT to remove Re:
257 $re_abbr = # Add more here!
258 'vedr|sv|' . # Danish
259 're|aw'; # English
260 if (eregi("^($re_abbr):[ ]*(.*)$", $messages[$j]['SUBJECT-SORT'], $regs))
261 $messages[$j]['SUBJECT-SORT'] = $regs[2];
262
263 $num = 0;
264 while ($num < count($flags[$j])) {
265 if ($flags[$j][$num] == 'Deleted') {
266 $messages[$j]['FLAG_DELETED'] = true;
267 }
268 elseif ($flags[$j][$num] == 'Answered') {
269 $messages[$j]['FLAG_ANSWERED'] = true;
270 }
271 elseif ($flags[$j][$num] == 'Seen') {
272 $messages[$j]['FLAG_SEEN'] = true;
273 }
274 elseif ($flags[$j][$num] == 'Flagged') {
275 $messages[$j]['FLAG_FLAGGED'] = true;
276 }
277 $num++;
278 }
279 $j++;
280 }
281
282 /* Only ignore messages flagged as deleted if we are using a
283 * trash folder or auto_expunge */
284 if (((isset($move_to_trash) && $move_to_trash)
285 || (isset($auto_expunge) && $auto_expunge)) && $sort != 6)
286 {
287 /** Find and remove the ones that are deleted */
288 $i = 0;
289 $j = 0;
290 while ($j < $numMessages) {
291 if (isset($messages[$j]['FLAG_DELETED']) && $messages[$j]['FLAG_DELETED'] == true) {
292 $j++;
293 continue;
294 }
295 $msgs[$i] = $messages[$j];
296
297 $i++;
298 $j++;
299 }
300 $numMessages = $i;
301 } else {
302 if (! isset($messages))
303 $messages = array();
304 $msgs = $messages;
305 }
306 }
307
308 // There's gotta be messages in the array for it to sort them.
309 if ($numMessages > 0 && ! $use_cache) {
310 /** 0 = Date (up) 4 = Subject (up)
311 ** 1 = Date (dn) 5 = Subject (dn)
312 ** 2 = Name (up)
313 ** 3 = Name (dn)
314 **/
315 session_unregister("msgs");
316 if (($sort == 0) || ($sort == 1))
317 $msort = array_cleave ($msgs, 'TIME_STAMP');
318 if (($sort == 2) || ($sort == 3))
319 $msort = array_cleave ($msgs, 'FROM-SORT');
320 if (($sort == 4) || ($sort == 5))
321 $msort = array_cleave ($msgs, 'SUBJECT-SORT');
322 if ($sort == 6)
323 $msort = $msgs;
324
325 if ($sort < 6) {
326 if($sort % 2) {
327 asort($msort);
328 } else {
329 arsort($msort);
330 }
331 }
332 session_register('msort');
333 }
334 displayMessageArray($imapConnection, $numMessages, $startMessage, $msgs, $msort, $mailbox, $sort, $color,$show_num);
335 session_register('msgs');
336 }
337
338 // generic function to convert the msgs array into an HTML table
339 function displayMessageArray($imapConnection, $numMessages, $startMessage, &$msgs, $msort, $mailbox, $sort, $color,$show_num) {
340 global $folder_prefix, $sent_folder;
341 global $imapServerAddress;
342 global $index_order, $real_endMessage, $real_startMessage, $checkall;
343
344 // if cache isn't already set, do it now
345 if (!session_is_registered('msgs'))
346 session_register('msgs');
347 if (!session_is_registered('msort'))
348 session_register('msort');
349
350 if ($startMessage + ($show_num - 1) < $numMessages) {
351 $endMessage = $startMessage + ($show_num-1);
352 } else {
353 $endMessage = $numMessages;
354 }
355
356 if ($endMessage < $startMessage) {
357 $startMessage = $startMessage - $show_num;
358 if ($startMessage < 1)
359 $startMessage = 1;
360 }
361
362 $nextGroup = $startMessage + $show_num;
363 $prevGroup = $startMessage - $show_num;
364 $urlMailbox = urlencode($mailbox);
365
366 do_hook('mailbox_index_before');
367
368 $Message = '';
369 if ($startMessage < $endMessage) {
370 $Message = _("Viewing messages") ." <B>$startMessage</B> ". _("to") ." <B>$endMessage</B> ($numMessages " . _("total") . ")\n";
371 } elseif ($startMessage == $endMessage) {
372 $Message = _("Viewing message") ." <B>$startMessage</B> ($numMessages " . _("total") . ")\n";
373 }
374
375 $More = '';
376 if ($sort == 6) {
377 $use = 0;
378 } else {
379 $use = 1;
380 }
381 if (($nextGroup <= $numMessages) && ($prevGroup >= 0)) {
382 $More = "<A HREF=\"right_main.php?use_mailbox_cache=$use&startMessage=$prevGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Previous") ."</A> | \n";
383 $More .= "<A HREF=\"right_main.php?use_mailbox_cache=$use&&startMessage=$nextGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Next") ."</A>\n";
384 }
385 elseif (($nextGroup > $numMessages) && ($prevGroup >= 0)) {
386 $More = "<A HREF=\"right_main.php?use_mailbox_cache=$use&startMessage=$prevGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Previous") ."</A> | \n";
387 $More .= "<FONT COLOR=\"$color[9]\">"._("Next")."</FONT>\n";
388 }
389 elseif (($nextGroup <= $numMessages) && ($prevGroup < 0)) {
390 $More = "<FONT COLOR=\"$color[9]\">"._("Previous")."</FONT> | \n";
391 $More .= "<A HREF=\"right_main.php?use_mailbox_cache=$use&startMessage=$nextGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Next") ."</A>\n";
392 }
393
394 if (! isset($msg))
395 $msg = "";
396 mail_message_listing_beginning($imapConnection,
397 "move_messages.php?msg=$msg&mailbox=$urlMailbox&startMessage=$startMessage",
398 $mailbox, $sort, $Message, $More, $startMessage);
399
400 $groupNum = $startMessage % ($show_num - 1);
401 $real_startMessage = $startMessage;
402 if ($sort == 6) {
403 if ($endMessage - $startMessage < $show_num - 1) {
404 $endMessage = $endMessage - $startMessage + 1;
405 $startMessage = 1;
406 } else if ($startMessage > $show_num) {
407 $endMessage = $show_num;
408 $startMessage = 1;
409 }
410 }
411
412 $endVar = $endMessage + 1;
413
414 // loop through and display the info for each message.
415 $t = 0; // $t is used for the checkbox number
416 if ($numMessages == 0) { // if there's no messages in this folder
417 echo "<TR><TD BGCOLOR=\"$color[4]\" COLSPAN=" . count($index_order);
418 echo "><CENTER><BR><B>". _("THIS FOLDER IS EMPTY") ."</B><BR>&nbsp;</CENTER></TD></TR>";
419 } else if ($startMessage == $endMessage) { // if there's only one message in the box, handle it different.
420 if ($sort != 6)
421 $i = $startMessage;
422 else
423 $i = 1;
424 reset($msort);
425 $k = 0;
426 do {
427 $key = key($msort);
428 next($msort);
429 $k++;
430 } while (isset ($key) && ($k < $i));
431 printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $real_startMessage, 0, 0);
432 } else {
433 $i = $startMessage;
434
435 reset($msort);
436 $k = 0;
437 do {
438 $key = key($msort);
439 next($msort);
440 $k++;
441 } while (isset ($key) && ($k < $i));
442
443 do {
444 printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $real_startMessage, 0, 0);
445 $key = key($msort);
446 $t++;
447 $i++;
448 next($msort);
449 } while ($i && $i < $endVar);
450 }
451 echo '</TABLE>';
452
453 echo "</td></tr>\n";
454
455 echo "<TR BGCOLOR=\"$color[4]\"><TD>";
456 echo '<table width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td>';
457 echo "$More</td><td align=right>\n";
458 if (!$startMessage) $startMessage=1;
459 ShowSelectAllLink($startMessage, $sort);
460
461 echo '</td></tr></table>';
462 echo '</td></tr>';
463 echo '</table>'; /** End of message-list table */
464
465 do_hook('mailbox_index_after');
466 }
467
468 /* Displays the standard message list header.
469 * To finish the table, you need to do a "</table></table>";
470 * $moveURL is the URL to submit the delete/move form to
471 * $mailbox is the current mailbox
472 * $sort is the current sorting method (-1 for no sorting available [searches])
473 * $Message is a message that is centered on top of the list
474 * $More is a second line that is left aligned
475 */
476 function mail_message_listing_beginning($imapConnection, $moveURL,
477 $mailbox = '', $sort = -1, $Message = '', $More = '', $startMessage = 1)
478 {
479 global $color, $index_order, $auto_expunge, $move_to_trash;
480 global $checkall, $sent_folder;
481 $urlMailbox = urlencode($mailbox);
482
483 /** This is the beginning of the message list table. It wraps around all messages */
484 echo '<TABLE WIDTH="100%" BORDER="0" CELLPADDING="2" CELLSPACING="0">';
485
486 if ($Message)
487 {
488 echo "<TR BGCOLOR=\"$color[4]\"><TD align=center>$Message</td></tr>\n";
489 }
490
491 echo "<TR BGCOLOR=\"$color[4]\"><TD>";
492 echo '<table width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td>';
493 echo "$More</td><td align=right>\n";
494 ShowSelectAllLink($startMessage, $sort);
495
496 echo '</td></tr></table>';
497 echo '</td></tr>';
498
499 /** The delete and move options */
500 echo "<TR><TD BGCOLOR=\"$color[0]\">";
501
502 echo "\n\n\n<FORM name=messageList method=post action=\"$moveURL\">\n";
503 echo "<TABLE BGCOLOR=\"$color[0]\" COLS=2 BORDER=0 cellpadding=0 cellspacing=0 width=100%>\n";
504 echo " <TR>\n";
505 echo " <TD WIDTH=60% ALIGN=LEFT VALIGN=CENTER>\n";
506
507
508 echo ' <NOBR><SMALL>'. _("Move selected to:") .'</SMALL>';
509 echo ' <TT><SMALL><SELECT NAME="targetMailbox">';
510
511 $boxes = sqimap_mailbox_list($imapConnection);
512 for ($i = 0; $i < count($boxes); $i++) {
513 if (!in_array("noselect", $boxes[$i]['flags'])) {
514 $box = $boxes[$i]['unformatted'];
515 $box2 = str_replace(' ', '&nbsp;', $boxes[$i]['unformatted-disp']);
516 echo " <OPTION VALUE=\"$box\">$box2</option>\n";
517 }
518 }
519 echo ' </SELECT></SMALL></TT>';
520 echo ' <SMALL><INPUT TYPE=SUBMIT NAME="moveButton" VALUE="'. _("Move") ."\"></SMALL></NOBR>\n";
521 echo " </TD>\n";
522 echo " <TD WIDTH=40% ALIGN=RIGHT>\n";
523 if (! $auto_expunge) {
524 echo ' <NOBR><SMALL><INPUT TYPE=SUBMIT NAME="expungeButton" VALUE="'. _("Expunge") .'">&nbsp;'. _("mailbox") ."</SMALL></NOBR>&nbsp;&nbsp;\n";
525 }
526 echo " <NOBR><SMALL><INPUT TYPE=SUBMIT VALUE=\"". _("Delete") ."\">&nbsp;". _("checked messages") ."</SMALL></NOBR>\n";
527 echo " </TD>\n";
528 echo " </TR>\n";
529
530 echo "</TABLE>\n";
531 do_hook('mailbox_form_before');
532 echo '</TD></TR>';
533
534 echo "<TR><TD BGCOLOR=\"$color[0]\">";
535 echo "<TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=1 BGCOLOR=\"$color[0]\">";
536 echo "<TR BGCOLOR=\"$color[5]\" ALIGN=\"center\">";
537
538 $urlMailbox=urlencode($mailbox);
539
540 // Print the headers
541 for ($i=1; $i <= count($index_order); $i++) {
542 switch ($index_order[$i]) {
543 case 1: # checkbox
544 case 5: # flags
545 echo ' <TD WIDTH="1%"><B>&nbsp;</B></TD>';
546 break;
547
548 case 2: # from
549 if ($mailbox == $sent_folder)
550 echo ' <TD WIDTH="30%"><B>'. _("To") .'</B>';
551 else
552 echo ' <TD WIDTH="30%"><B>'. _("From") .'</B>';
553
554 if ($sort == 2)
555 echo " <A HREF=\"right_main.php?newsort=3&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/up_pointer.gif\" BORDER=0></A></TD>\n";
556 elseif ($sort == 3)
557 echo " <A HREF=\"right_main.php?newsort=2&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/down_pointer.gif\" BORDER=0></A></TD>\n";
558 elseif ($sort != -1)
559 echo " <A HREF=\"right_main.php?newsort=3&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/sort_none.gif\" BORDER=0></A></TD>\n";
560 echo "</TD>";
561 break;
562
563 case 3: # date
564 echo ' <TD nowrap WIDTH="1%"><B>'. _("Date") .'</B>';
565 if ($sort == 0)
566 echo " <A HREF=\"right_main.php?newsort=1&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/up_pointer.gif\" BORDER=0></A></TD>\n";
567 elseif ($sort == 1)
568 echo " <A HREF=\"right_main.php?newsort=6&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/down_pointer.gif\" BORDER=0></A></TD>\n";
569 elseif ($sort == 6)
570 echo " <A HREF=\"right_main.php?newsort=0&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/sort_none.gif\" BORDER=0></A></TD>\n";
571 elseif ($sort != -1)
572 echo " <A HREF=\"right_main.php?newsort=0&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/sort_none.gif\" BORDER=0></A></TD>\n";
573 echo '</TD>';
574 break;
575
576 case 4: # subject
577 echo ' <TD WIDTH=%><B>'. _("Subject") ."</B>\n";
578 if ($sort == 4)
579 echo " <A HREF=\"right_main.php?newsort=5&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/up_pointer.gif\" BORDER=0></A></TD>\n";
580 elseif ($sort == 5)
581 echo " <A HREF=\"right_main.php?newsort=4&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/down_pointer.gif\" BORDER=0></A></TD>\n";
582 elseif ($sort != -1)
583 echo " <A HREF=\"right_main.php?newsort=5&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/sort_none.gif\" BORDER=0></A></TD>\n";
584 echo "</TD>";
585 break;
586
587 case 6: # size
588 echo ' <TD WIDTH="1%"><b>' . _("Size")."</b></TD>\n";
589 break;
590 }
591 }
592 echo "</TR>\n";
593 }
594
595 function ShowSelectAllLink($startMessage, $sort)
596 {
597 global $checkall, $PHP_SELF, $what, $where, $mailbox;
598
599 echo "\n<A HREF=\"$PHP_SELF?mailbox=" . urlencode($mailbox) .
600 "&startMessage=$startMessage&sort=$sort&";
601 if ( isset($checkall) && $checkall == '1')
602 echo "checkall=0";
603 else
604 echo "checkall=1";
605 if (isset($where) && isset($what))
606 echo "&where=" . urlencode($where) . "&what=" . urlencode($what);
607 echo "\">";
608 if (isset($checkall) && $checkall == '1')
609 echo _("Unselect All");
610 else
611 echo _("Select All");
612 echo "</A>\n";
613 }
614
615 function processSubject($subject)
616 {
617 // Shouldn't ever happen -- caught too many times in the IMAP functions
618 if ($subject == '')
619 return _("(no subject)");
620
621 if (strlen($subject) <= 55)
622 return $subject;
623
624 $ent_strlen=strlen($subject);
625 $trim_val=50;
626 $ent_offset=0;
627 // see if this is entities-encoded string
628 // If so, Iterate through the whole string, find out
629 // the real number of characters, and if more
630 // than 55, substr with an updated trim value.
631 while (($ent_loc = strpos($subject, '&', $ent_offset)) !== false &&
632 ($ent_loc_end = strpos($subject, ';', $ent_loc)) !== false)
633 {
634 $trim_val += ($ent_loc_end-$ent_loc)+1;
635 $ent_strlen -= $ent_loc_end-$ent_loc;
636 $ent_offset = $ent_loc_end+1;
637 }
638
639 if ($ent_strlen <= 55)
640 return $subject;
641
642 return substr($subject, 0, $trim_val) . '...';
643 }
644
645 ?>