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