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