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