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