Added All messages display
[squirrelmail.git] / functions / mailbox_display.php
1 <?php
2
3 /**
4 * mailbox_display.php
5 *
6 * Copyright (c) 1999-2001 The SquirrelMail Development Team
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 */
14
15 define('PG_SEL_MAX', 10); /* Default value for page_selector_max. */
16
17 function printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $start_msg, $where, $what) {
18 global $checkall;
19 global $color, $msgs, $msort;
20 global $sent_folder, $draft_folder;
21 global $default_use_priority;
22 global $message_highlight_list;
23 global $index_order;
24
25 $color_string = $color[4];
26 if ($GLOBALS['alt_index_colors']) {
27 if (!isset($GLOBALS["row_count"])) {
28 $GLOBALS["row_count"] = 0;
29 }
30 $GLOBALS["row_count"]++;
31 if ($GLOBALS["row_count"] % 2) {
32 if (!isset($color[12])) $color[12] = '#EAEAEA';
33 $color_string = $color[12];
34 }
35 }
36 $msg = $msgs[$key];
37
38 $senderName = htmlspecialchars(sqimap_find_displayable_name($msg['FROM']));
39 if( $mailbox == 'None' ) {
40 // $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
41 $boxes = sqimap_mailbox_list($imapConnection);
42 // sqimap_logout($imapConnection);
43 $mailbox = $boxes[0]['unformatted'];
44 unset( $boxes );
45 }
46 $urlMailbox = urlencode($mailbox);
47 $subject = processSubject($msg['SUBJECT']);
48 echo "<TR>\n";
49
50 if (isset($msg['FLAG_FLAGGED']) && ($msg['FLAG_FLAGGED'] == true)) {
51 $flag = "<font color=$color[2]>";
52 $flag_end = '</font>';
53 } else {
54 $flag = '';
55 $flag_end = '';
56 }
57 if (!isset($msg['FLAG_SEEN']) || ($msg['FLAG_SEEN'] == false)) {
58 $bold = '<b>';
59 $bold_end = '</b>';
60 } else {
61 $bold = '';
62 $bold_end = '';
63 }
64
65 if (($mailbox == $sent_folder) || ($mailbox == $draft_folder)) {
66 $italic = '<i>';
67 $italic_end = '</i>';
68 } else {
69 $italic = '';
70 $italic_end = '';
71 }
72
73 if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED']) {
74 $fontstr = "<font color=\"$color[9]\">";
75 $fontstr_end = '</font>';
76 } else {
77 $fontstr = '';
78 $fontstr_end = '';
79 }
80
81 for ($i=0; $i < count($message_highlight_list); $i++) {
82 if (trim($message_highlight_list[$i]['value']) != '') {
83 if ($message_highlight_list[$i]['match_type'] == 'to_cc') {
84 if (strpos('^^'.strtolower($msg['TO']), strtolower($message_highlight_list[$i]['value'])) || strpos('^^'.strtolower($msg['CC']), strtolower($message_highlight_list[$i]['value']))) {
85 $hlt_color = $message_highlight_list[$i]['color'];
86 continue;
87 }
88 } else if (strpos('^^'.strtolower($msg[strtoupper($message_highlight_list[$i]['match_type'])]),strtolower($message_highlight_list[$i]['value']))) {
89 $hlt_color = $message_highlight_list[$i]['color'];
90 continue;
91 }
92 }
93 }
94
95 if (!isset($hlt_color)) {
96 $hlt_color = $color_string;
97 }
98
99 if ($where && $what) {
100 $search_stuff = '&where='.urlencode($where).'&what='.urlencode($what);
101 }
102
103 $checked = ($checkall == 1 ?' checked' : '');
104
105 for ($i=1; $i <= count($index_order); $i++) {
106 switch ($index_order[$i]) {
107 case 1: /* checkbox */
108 echo " <td bgcolor=$hlt_color align=center><input type=checkbox name=\"msg[$t]\" value=".$msg["ID"]."$checked></TD>\n";
109 break;
110 case 2: /* from */
111 echo " <td bgcolor=$hlt_color>$italic$bold$flag$fontstr$senderName$fontstr_end$flag_end$bold_end$italic_end</td>\n";
112 break;
113 case 3: /* date */
114 echo " <td nowrap bgcolor=$hlt_color><center>$bold$flag$fontstr".$msg["DATE_STRING"]."$fontstr_end$flag_end$bold_end</center></td>\n";
115 break;
116 case 4: /* subject */
117 echo " <td bgcolor=$hlt_color>$bold";
118 if (! isset($search_stuff)) { $search_stuff = ''; }
119 echo "<a href=\"read_body.php?mailbox=$urlMailbox&passed_id=".$msg["ID"]."&startMessage=$start_msg&show_more=0$search_stuff\"";
120 do_hook("subject_link");
121
122 if ($subject != $msg['SUBJECT']) {
123 $title = get_html_translation_table(HTML_SPECIALCHARS);
124 $title = array_flip($title);
125 $title = strtr($msg['SUBJECT'], $title);
126 $title = str_replace('"', "''", $title);
127 echo " title=\"$title\"";
128 }
129 echo ">$flag$subject$flag_end</a>$bold_end</td>\n";
130 break;
131 case 5: /* flags */
132 $stuff = false;
133 echo " <td bgcolor=$hlt_color align=center nowrap><b><small>\n";
134 if (isset($msg['FLAG_ANSWERED']) &&
135 $msg['FLAG_ANSWERED'] == true) {
136 echo "A\n";
137 $stuff = true;
138 }
139 if ($msg['TYPE0'] == 'multipart') {
140 echo "+\n";
141 $stuff = true;
142 }
143 if ($default_use_priority) {
144 if (ereg('(1|2)',substr($msg['PRIORITY'],0,1))) {
145 echo "<font color=$color[1]>!</font>\n";
146 $stuff = true;
147 }
148 if (ereg('(5)',substr($msg['PRIORITY'],0,1))) {
149 echo "<font color=$color[8]>?</font>\n";
150 $stuff = true;
151 }
152 }
153 if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED']) {
154 echo "<font color=\"$color[1]\">D</font>\n";
155 $stuff = true;
156 }
157
158 if (!$stuff) {
159 echo "&nbsp;\n";
160 }
161 echo "</small></b></td>\n";
162 break;
163 case 6: /* size */
164 echo " <td bgcolor=$hlt_color>$bold$fontstr" .
165 show_readable_size($msg['SIZE']) .
166 "$fontstr_end$bold_end</td>\n";
167 break;
168 }
169 }
170 echo "</tr>\n";
171 }
172
173 /**
174 * This function loops through a group of messages in the mailbox
175 * and shows them to the user.
176 */
177 function showMessagesForMailbox
178 ($imapConnection, $mailbox, $num_msgs, $start_msg,
179 $sort, $color,$show_num, $use_cache) {
180 global $msgs, $msort;
181 global $sent_folder, $draft_folder;
182 global $message_highlight_list;
183 global $auto_expunge;
184
185 /* If autoexpunge is turned on, then do it now. */
186 if ($auto_expunge == true) {
187 sqimap_mailbox_expunge($imapConnection, $mailbox, false);
188 }
189 sqimap_mailbox_select($imapConnection, $mailbox);
190
191 $issent = (($mailbox == $sent_folder) || ($mailbox == $draft_folder));
192 if (!$use_cache) {
193 /* If it is sorted... */
194 if ($num_msgs >= 1) {
195 if ($sort < 6) {
196 $id = range(1, $num_msgs);
197 } else {
198 // if it's not sorted
199 if ($start_msg + ($show_num - 1) < $num_msgs) {
200 $end_msg = $start_msg + ($show_num-1);
201 } else {
202 $end_msg = $num_msgs;
203 }
204
205 if ($end_msg < $start_msg) {
206 $start_msg = $start_msg - $show_num;
207 if ($start_msg < 1) {
208 $start_msg = 1;
209 }
210 }
211
212 $real_startMessage = $num_msgs - $start_msg + 1;
213 $real_endMessage = $num_msgs - $start_msg - $show_num + 2;
214 if ($real_endMessage <= 0) {
215 $real_endMessage = 1;
216 }
217 $id = array_reverse(range($real_endMessage, $real_startMessage));
218 }
219
220 $msgs_list = sqimap_get_small_header_list($imapConnection, $id, $issent);
221 $flags = sqimap_get_flags_list($imapConnection, $id, $issent);
222 foreach ($msgs_list as $hdr) {
223 $from[] = $hdr->from;
224 $date[] = $hdr->date;
225 $subject[] = $hdr->subject;
226 $to[] = $hdr->to;
227 $priority[] = $hdr->priority;
228 $cc[] = $hdr->cc;
229 $size[] = $hdr->size;
230 $type[] = $hdr->type0;
231 }
232 }
233
234 $j = 0;
235 if ($sort == 6) {
236 $end = $start_msg + $show_num - 1;
237 if ($num_msgs < $show_num) {
238 $end_loop = $num_msgs;
239 } else if ($end > $num_msgs) {
240 $end_loop = $num_msgs - $start_msg + 1;
241 } else {
242 $end_loop = $show_num;
243 }
244 } else {
245 $end = $num_msgs;
246 $end_loop = $end;
247 }
248
249 while ($j < $end_loop) {
250 if (isset($date[$j])) {
251 $date[$j] = ereg_replace(' ', ' ', $date[$j]);
252 $tmpdate = explode(' ', trim($date[$j]));
253 } else {
254 $tmpdate = $date = array('', '', '', '', '', '');
255 }
256
257 $messages[$j]['TIME_STAMP'] = getTimeStamp($tmpdate);
258 $messages[$j]['DATE_STRING'] = getDateString($messages[$j]['TIME_STAMP']);
259 $messages[$j]['ID'] = $id[$j];
260 $messages[$j]['FROM'] = decodeHeader($from[$j]);
261 $messages[$j]['FROM-SORT'] = strtolower(sqimap_find_displayable_name(decodeHeader($from[$j])));
262 $messages[$j]['SUBJECT'] = decodeHeader($subject[$j]);
263 $messages[$j]['SUBJECT-SORT'] = strtolower(decodeHeader($subject[$j]));
264 $messages[$j]['TO'] = decodeHeader($to[$j]);
265 $messages[$j]['PRIORITY'] = $priority[$j];
266 $messages[$j]['CC'] = $cc[$j];
267 $messages[$j]['SIZE'] = $size[$j];
268 $messages[$j]['TYPE0'] = $type[$j];
269
270 # fix SUBJECT-SORT to remove Re:
271 $re_abbr = /* Add more here! */
272 'vedr|sv|' . /* Danish */
273 're|aw'; /* English */
274
275 if (eregi( "^($re_abbr):[ ]*(.*)$", $messages[$j]['SUBJECT-SORT'], $regs)) {
276 $messages[$j]['SUBJECT-SORT'] = $regs[2];
277 }
278
279 $num = 0;
280 while ($num < count($flags[$j])) {
281 if ($flags[$j][$num] == 'Deleted') {
282 $messages[$j]['FLAG_DELETED'] = true;
283 } else if ($flags[$j][$num] == 'Answered') {
284 $messages[$j]['FLAG_ANSWERED'] = true;
285 } else if ($flags[$j][$num] == 'Seen') {
286 $messages[$j]['FLAG_SEEN'] = true;
287 } else if ($flags[$j][$num] == 'Flagged') {
288 $messages[$j]['FLAG_FLAGGED'] = true;
289 }
290 $num++;
291 }
292 $j++;
293 }
294
295 /* Only ignore messages flagged as deleted if we are using a
296 * trash folder or auto_expunge */
297 if (((isset($move_to_trash) && $move_to_trash)
298 || (isset($auto_expunge) && $auto_expunge)) && $sort != 6) {
299
300 /** Find and remove the ones that are deleted */
301 $i = 0;
302 $j = 0;
303
304 while ($j < $num_msgs) {
305 if (isset($messages[$j]['FLAG_DELETED']) && $messages[$j]['FLAG_DELETED'] == true) {
306 $j++;
307 continue;
308 }
309 $msgs[$i] = $messages[$j];
310
311 $i++;
312 $j++;
313 }
314 $num_msgs = $i;
315 } else {
316 if (!isset($messages)) {
317 $messages = array();
318 }
319 $msgs = $messages;
320 }
321 }
322
323 // There's gotta be messages in the array for it to sort them.
324 if ($num_msgs > 0 && ! $use_cache) {
325 /** 0 = Date (up) 4 = Subject (up)
326 ** 1 = Date (dn) 5 = Subject (dn)
327 ** 2 = Name (up)
328 ** 3 = Name (dn)
329 **/
330 session_unregister("msgs");
331 if (($sort == 0) || ($sort == 1))
332 $msort = array_cleave ($msgs, 'TIME_STAMP');
333 elseif (($sort == 2) || ($sort == 3))
334 $msort = array_cleave ($msgs, 'FROM-SORT');
335 elseif (($sort == 4) || ($sort == 5))
336 $msort = array_cleave ($msgs, 'SUBJECT-SORT');
337 else // ($sort == 6)
338 $msort = $msgs;
339
340 if ($sort < 6) {
341 if ($sort % 2) {
342 asort($msort);
343 } else {
344 arsort($msort);
345 }
346 }
347 session_register('msort');
348 }
349 displayMessageArray($imapConnection, $num_msgs, $start_msg, $msgs, $msort, $mailbox, $sort, $color,$show_num);
350 session_register('msgs');
351 }
352
353 /**
354 * Generic function to convert the msgs array into an HTML table.
355 */
356 function displayMessageArray($imapConnection, $num_msgs, $start_msg, &$msgs, $msort, $mailbox, $sort, $color, $show_num) {
357 global $folder_prefix, $sent_folder;
358 global $imapServerAddress, $data_dir, $username, $use_mailbox_cache;
359 global $index_order, $real_endMessage, $real_startMessage, $checkall;
360
361 /* If cache isn't already set, do it now. */
362 if (!session_is_registered('msgs')) { session_register('msgs'); }
363 if (!session_is_registered('msort')) { session_register('msort'); }
364
365 if ($start_msg + ($show_num - 1) < $num_msgs) {
366 $end_msg = $start_msg + ($show_num-1);
367 } else {
368 $end_msg = $num_msgs;
369 }
370
371 if ($end_msg < $start_msg) {
372 $start_msg = $start_msg - $show_num;
373 if ($start_msg < 1) { $start_msg = 1; }
374 }
375
376 $urlMailbox = urlencode($mailbox);
377
378 do_hook('mailbox_index_before');
379
380 $msg_cnt_str = get_msgcnt_str($start_msg, $end_msg, $num_msgs);
381 $paginator_str = get_paginator_str($urlMailbox, $start_msg, $end_msg, $num_msgs, $show_num, $sort);
382
383 if (! isset($msg)) {
384 $msg = '';
385 }
386
387 mail_message_listing_beginning
388 ($imapConnection,
389 "move_messages.php?msg=$msg&mailbox=$urlMailbox&startMessage=$start_msg",
390 $mailbox, $sort, $msg_cnt_str, $paginator_str, $start_msg);
391
392 $groupNum = $start_msg % ($show_num - 1);
393 $real_startMessage = $start_msg;
394 if ($sort == 6) {
395 if ($end_msg - $start_msg < $show_num - 1) {
396 $end_msg = $end_msg - $start_msg + 1;
397 $start_msg = 1;
398 } else if ($start_msg > $show_num) {
399 $end_msg = $show_num;
400 $start_msg = 1;
401 }
402 }
403 $endVar = $end_msg + 1;
404
405 /* Loop through and display the info for each message. */
406 $t = 0; // $t is used for the checkbox number
407 if ($num_msgs == 0) { // if there's no messages in this folder
408 echo "<TR><TD BGCOLOR=\"$color[4]\" COLSPAN=" . count($index_order) . ">\n".
409 " <CENTER><BR><B>". _("THIS FOLDER IS EMPTY") ."</B><BR>&nbsp;</CENTER>\n".
410 "</TD></TR>";
411 } elseif ($start_msg == $end_msg) {
412 /* If there's only one message in the box, handle it differently. */
413 if ($sort != 6) {
414 $i = $start_msg;
415 } else {
416 $i = 1;
417 }
418
419 reset($msort);
420 $k = 0;
421 do {
422 $key = key($msort);
423 next($msort);
424 $k++;
425 } while (isset ($key) && ($k < $i));
426 printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $real_startMessage, 0, 0);
427 } else {
428 $i = $start_msg;
429
430 reset($msort);
431 $k = 0;
432 do {
433 $key = key($msort);
434 next($msort);
435 $k++;
436 } while (isset ($key) && ($k < $i));
437
438 do {
439 printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $real_startMessage, 0, 0);
440 $key = key($msort);
441 $t++;
442 $i++;
443 next($msort);
444 } while ($i && $i < $endVar);
445 }
446
447 echo '</table>'.
448 "<table bgcolor=\"$color[9]\" width=100% border=0 cellpadding=1 cellspacing=1>" .
449 "<tr BGCOLOR=\"$color[4]\">" .
450 "<table width=100% BGCOLOR=\"$color[4]\" border=0 cellpadding=1 cellspacing=0><tr><td>$paginator_str</td>".
451 "<td align=right>$msg_cnt_str</td></tr></table>".
452 "</tr>".
453 "</table>";
454 /** End of message-list table */
455
456 do_hook('mailbox_index_after');
457 echo "</TABLE></FORM>\n";
458 }
459
460 /**
461 * Displays the standard message list header. To finish the table,
462 * you need to do a "</table></table>";
463 *
464 * $moveURL is the URL to submit the delete/move form to
465 * $mailbox is the current mailbox
466 * $sort is the current sorting method (-1 for no sorting available [searches])
467 * $Message is a message that is centered on top of the list
468 * $More is a second line that is left aligned
469 */
470 function mail_message_listing_beginning
471 ($imapConnection, $moveURL, $mailbox = '', $sort = -1,
472 $msg_cnt_str = '', $paginator = '&nbsp;', $start_msg = 1) {
473 global $color, $index_order, $auto_expunge, $move_to_trash;
474 global $checkall, $sent_folder, $draft_folder;
475 $urlMailbox = urlencode($mailbox);
476
477 /*
478 * This is the beginning of the message list table.
479 * It wraps around all messages
480 */
481 echo "<TABLE WIDTH=\"100%\" BORDER=\"0\" CELLPADDING=\"1\" CELLSPACING=\"0\">\n".
482 "<TR BGCOLOR=\"$color[0]\"><TD>".
483 "<TABLE BGCOLOR=\"$color[4]\" width=\"100%\" CELLPADDING=\"2\" CELLSPACING=\"0\" BORDER=\"0\"><TR>\n".
484 " <TD ALIGN=LEFT>$paginator";
485
486 if( $paginator <> '&nbsp;' ) {
487 echo ' | ';
488 }
489
490 echo get_selectall_link($start_msg, $sort) . "</TD>\n".
491 " <TD ALIGN=RIGHT>$msg_cnt_str</TD>\n".
492 " </TR></TABLE>\n".
493 '</TD></TR>'.
494 "<TR><TD BGCOLOR=\"$color[0]\">\n".
495 "<FORM name=messageList method=post action=\"$moveURL\">\n".
496 "<TABLE BGCOLOR=\"$color[0]\" COLS=2 BORDER=0 cellpadding=0 cellspacing=0 width=\"100%\">\n".
497 " <TR>\n" .
498 " <TD ALIGN=LEFT VALIGN=CENTER NOWRAP>\n" .
499 ' <SMALL>&nbsp;' . _("Move selected to:") . "</SMALL>\n" .
500 " </TD>\n" .
501 " <TD ALIGN=RIGHT NOWRAP>\n" .
502 ' <SMALL>&nbsp;' . _("Transform Selected Messages") . ": &nbsp; </SMALL><BR>\n" .
503 " </TD>\n" .
504 " </TR>\n" .
505 " <TR>\n" .
506 " <TD ALIGN=LEFT VALIGN=CENTER NOWRAP>\n" .
507 ' <SMALL>&nbsp;<TT><SELECT NAME="targetMailbox">';
508
509 $boxes = sqimap_mailbox_list($imapConnection);
510 for ($i = 0; $i < count($boxes); $i++) {
511 if (!in_array("noselect", $boxes[$i]['flags'])) {
512 $box = $boxes[$i]['unformatted'];
513 $box2 = str_replace(' ', '&nbsp;', $boxes[$i]['unformatted-disp']);
514 echo " <OPTION VALUE=\"$box\">$box2</option>\n";
515 }
516 }
517 echo ' </SELECT></TT></SMALL>'.
518 "<SMALL><INPUT TYPE=SUBMIT NAME=\"moveButton\" VALUE=\"" . _("Move") . "\"></SMALL>\n".
519 " </TD>\n".
520 " <TD ALIGN=RIGHT NOWRAP>&nbsp;&nbsp;&nbsp;\n";
521 if (!$auto_expunge) {
522 echo ' <INPUT TYPE=SUBMIT NAME="expungeButton" VALUE="'. _("Expunge") .'">&nbsp;'. _("mailbox") ."&nbsp;\n";
523 }
524 echo " <INPUT TYPE=SUBMIT NAME=\"markRead\" VALUE=\"". _("Read")."\">\n".
525 " <INPUT TYPE=SUBMIT NAME=\"markUnread\" VALUE=\"". _("Unread")."\">\n".
526 " <INPUT TYPE=SUBMIT VALUE=\"". _("Delete") . "\">&nbsp;\n".
527 " </TD>\n".
528 " </TR>\n".
529 "</TABLE>\n";
530 do_hook('mailbox_form_before');
531 echo '</TD></TR>'.
532
533 "<TR><TD BGCOLOR=\"$color[0]\">".
534 "<TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=";
535 if ($GLOBALS['alt_index_colors']) {
536 echo "0";
537 } else {
538 echo "1";
539 }
540 echo " BGCOLOR=\"$color[0]\">".
541 "<TR BGCOLOR=\"$color[5]\" ALIGN=\"center\">";
542
543 /* Print the headers. */
544 for ($i=1; $i <= count($index_order); $i++) {
545 switch ($index_order[$i]) {
546 case 1: /* checkbox */
547 case 5: /* flags */
548 echo ' <TD WIDTH="1%"><B>&nbsp;</B></TD>';
549 break;
550
551 case 2: /* from */
552 if (($mailbox == $sent_folder)
553 || ($mailbox == $draft_folder)) {
554 echo ' <TD WIDTH="25%"><B>'. _("To") .'</B>';
555 } else {
556 echo ' <TD WIDTH="25%"><B>'. _("From") .'</B>';
557 }
558
559 ShowSortButton($sort, $mailbox, 2, 3);
560 echo "</TD>\n";
561 break;
562
563 case 3: /* date */
564 echo ' <TD NOWRAP WIDTH="5%"><B>'. _("Date") .'</B>';
565 ShowSortButton($sort, $mailbox, 0, 1);
566 echo "</TD>\n";
567 break;
568
569 case 4: /* subject */
570 echo ' <TD><B>'. _("Subject") .'</B> ';
571 ShowSortButton($sort, $mailbox, 4, 5);
572 echo "</TD>\n";
573 break;
574
575 case 6: /* size */
576 echo ' <TD WIDTH="5%"><b>' . _("Size")."</b></TD>\n";
577 break;
578 }
579 }
580 echo "</TR>\n";
581 }
582
583 /*
584 * This function shows the sort button. Isn't this a good comment?
585 */
586 function ShowSortButton($sort, $mailbox, $Up, $Down) {
587 /* Figure out which image we want to use. */
588 if ($sort != $Up && $sort != $Down) {
589 $img = 'sort_none.gif';
590 $which = $Up;
591 } elseif ($sort == $Up) {
592 $img = 'up_pointer.gif';
593 $which = $Down;
594 } else {
595 $img = 'down_pointer.gif';
596 $which = 6;
597 }
598
599 /* Now that we have everything figured out, show the actual button. */
600 echo ' <a href="right_main.php?newsort=' . $which .
601 '&startMessage=1&mailbox=' . urlencode($mailbox) .
602 '"><IMG SRC="../images/' . $img .
603 '" BORDER=0 WIDTH=12 HEIGHT=10></a>';
604 }
605
606 function get_selectall_link($start_msg, $sort) {
607 global $checkall, $PHP_SELF, $what, $where, $mailbox, $javascript_on;
608
609 if ($javascript_on) {
610 $result =
611 '<script language="JavaScript">' .
612 "\n<!-- \n" .
613 "function CheckAll() {\n" .
614 " for (var i = 0; i < document.messageList.elements.length; i++) {\n" .
615 " if( document.messageList.elements[i].type == 'checkbox' ) {\n" .
616 " document.messageList.elements[i].checked = !(document.messageList.elements[i].checked);\n".
617 " }\n" .
618 " }\n" .
619 "}\n" .
620 "//-->\n" .
621 '</script><a href=# onClick="CheckAll();">' . _("Toggle All") . "</a>\n";
622 } else {
623 $result .= "<a href=\"$PHP_SELF?mailbox=" . urlencode($mailbox)
624 . "&startMessage=$start_msg&sort=$sort&checkall=";
625 if (isset($checkall) && $checkall == '1') {
626 $result .= '0';
627 } else {
628 $result .= '1';
629 }
630
631 if (isset($where) && isset($what)) {
632 $result .= '&where=' . urlencode($where)
633 . '&what=' . urlencode($what);
634 }
635
636 $result .= "\">";
637
638 if (isset($checkall) && ($checkall == '1')) {
639 $result .= _("Unselect All");
640 } else {
641 $result .= _("Select All");
642 }
643
644 $result .= "</A>\n";
645 }
646
647 /* Return our final result. */
648 return ($result);
649 }
650
651 /**
652 * This function computes the "Viewing Messages..." string.
653 */
654 function get_msgcnt_str($start_msg, $end_msg, $num_msgs) {
655 /* Compute the $msg_cnt_str. */
656 $result = '';
657 if ($start_msg < $end_msg) {
658 $result = sprintf(_("Viewing Messages: <B>%s</B> to <B>%s</B> (%s total)"), $start_msg, $end_msg, $num_msgs);
659 } else if ($start_msg == $end_msg) {
660 $result = sprintf(_("Viewing Message: <B>%s</B> (1 total)"), $start_msg);
661 } else {
662 $result = '<br>';
663 }
664
665 /* Return our result string. */
666 return ($result);
667 }
668
669 /**
670 * This function computes the paginator string.
671 */
672 function get_paginator_str
673 ($urlMailbox, $start_msg, $end_msg, $num_msgs, $show_num, $sort) {
674 global $username, $data_dir, $use_mailbox_cache, $color;
675
676 $nextGroup = $start_msg + $show_num;
677 $prevGroup = $start_msg - $show_num;
678
679 if ($sort == 6) {
680 $use = 0;
681 } else {
682 $use = 1;
683 }
684 $lMore = '';
685 $rMore = '';
686 if (($nextGroup <= $num_msgs) && ($prevGroup >= 0)) {
687 $lMore = "<A HREF=\"right_main.php?use_mailbox_cache=$use&startMessage=$prevGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Previous") . '</A>';
688 $rMore = "<A HREF=\"right_main.php?use_mailbox_cache=$use&&startMessage=$nextGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Next") ."</A>\n";
689 } else if (($nextGroup > $num_msgs) && ($prevGroup >= 0)) {
690 $lMore = "<A HREF=\"right_main.php?use_mailbox_cache=$use&startMessage=$prevGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Previous") . '</A>';
691 $rMore = "<FONT COLOR=\"$color[9]\">"._("Next")."</FONT>\n";
692 } else if (($nextGroup <= $num_msgs) && ($prevGroup < 0)) {
693 $lMore = "<FONT COLOR=\"$color[9]\">"._("Previous") . '</FONT>';
694 $rMore = "<A HREF=\"right_main.php?use_mailbox_cache=$use&startMessage=$nextGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Next") ."</A>\n";
695 }
696 if ($lMore <> '') {
697 $lMore .= ' | ';
698 }
699 if ($rMore <> '' || $lMore <> '' ) {
700 $rMore = "<A HREF=\"right_main.php?PG_SHOWNUM=9999use_mailbox_cache=$use&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\">" .
701 _("All") . '</A> | ' . $rMore;
702 }
703 /* Page selector block. Following code computes page links. */
704 $mMore = '';
705 if (getPref($data_dir, $username, 'page_selector')
706 && ($num_msgs > $show_num)) {
707 $j = intval( $num_msgs / $show_num ); // Max pages
708 $k = max( 1, $j / getPref($data_dir, $username, 'page_selector_max', PG_SEL_MAX ) );
709 if ($num_msgs % $show_num <> 0 ) {
710 $j++;
711 }
712 $start_msg = min( $start_msg, $num_msgs );
713 $p = intval( $start_msg / $show_num ) + 1;
714 $i = 1;
715 while( $i < $p ) {
716 $pg = intval( $i );
717 $start = ( ($pg-1) * $show_num ) + 1;
718 $mMore .= "<a href=\"right_main.php?use_mailbox_cache=$use_mailbox_cache&startMessage=$start" .
719 "&mailbox=$urlMailbox\" TARGET=\"right\">$pg</a>&nbsp;";
720 $i += $k;
721 }
722 $mMore .= "<B>$p</B>&nbsp;";
723 $i += $k;
724 while( $i <= $j ) {
725 $pg = intval( $i );
726 $start = ( ($pg-1) * $show_num ) + 1;
727 $mMore .= "<a href=\"right_main.php?use_mailbox_cache=$use_mailbox_cache&startMessage=$start"
728 . "&mailbox=$urlMailbox\" TARGET=\"right\">$pg</a>&nbsp;";
729 $i+=$k;
730 }
731 $mMore .= '&nbsp;|&nbsp;';
732 }
733
734 /* Return the resulting string. */
735 if( $lMore . $mMore . $rMore == '' ) {
736 $lMore = '&nbsp;';
737 }
738 return ($lMore . $mMore . $rMore);
739 }
740
741 function processSubject($subject) {
742 // Shouldn't ever happen -- caught too many times in the IMAP functions
743 if ($subject == '')
744 return _("(no subject)");
745
746 if (strlen($subject) <= 55)
747 return $subject;
748
749 $ent_strlen=strlen($subject);
750 $trim_val=50;
751 $ent_offset=0;
752 // see if this is entities-encoded string
753 // If so, Iterate through the whole string, find out
754 // the real number of characters, and if more
755 // than 55, substr with an updated trim value.
756 while (($ent_loc = strpos($subject, '&', $ent_offset)) !== false &&
757 ($ent_loc_end = strpos($subject, ';', $ent_loc)) !== false)
758 {
759 $trim_val += ($ent_loc_end-$ent_loc)+1;
760 $ent_strlen -= $ent_loc_end-$ent_loc;
761 $ent_offset = $ent_loc_end+1;
762 }
763
764 if ($ent_strlen <= 55)
765 return $subject;
766
767 return substr($subject, 0, $trim_val) . '...';
768 }
769
770 ?>