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