Some user interface changes.
[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 $message_highlight_list;
25 global $index_order;
26
27 $color_string = $color[4];
28 if ($GLOBALS['alt_index_colors']) {
29 if (!isset($GLOBALS["row_count"])) {
30 $GLOBALS["row_count"] = 0;
31 }
32 $GLOBALS["row_count"]++;
33 if ($GLOBALS["row_count"] % 2) {
34 if (!isset($color[12])) $color[12] = '#EAEAEA';
35 $color_string = $color[12];
36 }
37 }
38 $msg = $msgs[$key];
39
40 $senderName = htmlentities(sqimap_find_displayable_name($msg['FROM']));
41 if( $mailbox == _("None") ) {
42 // $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
43 $boxes = sqimap_mailbox_list($imapConnection);
44 // sqimap_logout($imapConnection);
45 $mailbox = $boxes[0]['unformatted'];
46 unset( $boxes );
47 }
48 $urlMailbox = urlencode($mailbox);
49 $subject = processSubject($msg['SUBJECT']);
50 echo "<TR>\n";
51
52 if (isset($msg['FLAG_FLAGGED']) && ($msg['FLAG_FLAGGED'] == true)) {
53 $flag = "<font color=$color[2]>";
54 $flag_end = '</font>';
55 } else {
56 $flag = '';
57 $flag_end = '';
58 }
59 if (!isset($msg['FLAG_SEEN']) || ($msg['FLAG_SEEN'] == false)) {
60 $bold = '<b>';
61 $bold_end = '</b>';
62 } else {
63 $bold = '';
64 $bold_end = '';
65 }
66
67 if (($mailbox == $sent_folder) || ($mailbox == $draft_folder)) {
68 $italic = '<i>';
69 $italic_end = '</i>';
70 } else {
71 $italic = '';
72 $italic_end = '';
73 }
74
75 if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED']) {
76 $fontstr = "<font color=\"$color[9]\">";
77 $fontstr_end = '</font>';
78 } else {
79 $fontstr = '';
80 $fontstr_end = '';
81 }
82
83 for ($i=0; $i < count($message_highlight_list); $i++) {
84 if (trim($message_highlight_list[$i]['value']) != '') {
85 if ($message_highlight_list[$i]['match_type'] == 'to_cc') {
86 if (strpos('^^'.strtolower($msg['TO']), strtolower($message_highlight_list[$i]['value'])) || strpos('^^'.strtolower($msg['CC']), strtolower($message_highlight_list[$i]['value']))) {
87 $hlt_color = $message_highlight_list[$i]['color'];
88 continue;
89 }
90 } else if (strpos('^^'.strtolower($msg[strtoupper($message_highlight_list[$i]['match_type'])]),strtolower($message_highlight_list[$i]['value']))) {
91 $hlt_color = $message_highlight_list[$i]['color'];
92 continue;
93 }
94 }
95 }
96
97 if (!isset($hlt_color)) {
98 $hlt_color = $color_string;
99 }
100
101 if ($where && $what) {
102 $search_stuff = '&where='.urlencode($where).'&what='.urlencode($what);
103 }
104
105 $checked = ($checkall == 1 ?' checked' : '');
106
107 for ($i=1; $i <= count($index_order); $i++) {
108 switch ($index_order[$i]) {
109 case 1: /* checkbox */
110 echo " <td bgcolor=$hlt_color align=center><input type=checkbox name=\"msg[$t]\" value=".$msg["ID"]."$checked></TD>\n";
111 break;
112 case 2: /* from */
113 echo " <td bgcolor=$hlt_color>$italic$bold$flag$fontstr$senderName$fontstr_end$flag_end$bold_end$italic_end</td>\n";
114 break;
115 case 3: /* date */
116 echo " <td nowrap bgcolor=$hlt_color><center>$bold$flag$fontstr".$msg["DATE_STRING"]."$fontstr_end$flag_end$bold_end</center></td>\n";
117 break;
118 case 4: /* subject */
119 echo " <td bgcolor=$hlt_color>$bold";
120 if (! isset($search_stuff)) { $search_stuff = ''; }
121 echo "<a href=\"read_body.php?mailbox=$urlMailbox&passed_id=".$msg["ID"]."&startMessage=$start_msg&show_more=0$search_stuff\"";
122 do_hook("subject_link");
123
124 if ($subject != $msg['SUBJECT']) {
125 $title = get_html_translation_table(HTML_SPECIALCHARS);
126 $title = array_flip($title);
127 $title = strtr($msg['SUBJECT'], $title);
128 $title = str_replace('"', "''", $title);
129 echo " title=\"$title\"";
130 }
131 echo ">$flag$subject$flag_end</a>$bold_end</td>\n";
132 break;
133 case 5: /* flags */
134 $stuff = false;
135 echo " <td bgcolor=$hlt_color align=center nowrap><b><small>\n";
136 if (isset($msg['FLAG_ANSWERED']) &&
137 $msg['FLAG_ANSWERED'] == true) {
138 echo "A\n";
139 $stuff = true;
140 }
141 if (ereg('(5)',substr($msg['PRIORITY'],0,1))) {
142 echo "<font color=$color[8]>v</font>\n";
143 $stuff = true;
144 }
145 if ($msg['TYPE0'] == 'multipart') {
146 echo "+\n";
147 $stuff = true;
148 }
149 if (ereg('(1|2)',substr($msg['PRIORITY'],0,1))) {
150 echo "<font color=$color[1]>!</font>\n";
151 $stuff = true;
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);
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 echo " <CENTER><BR><B>". _("THIS FOLDER IS EMPTY") ."</B><BR>&nbsp;</CENTER>\n";
405 echo "</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 echo "<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 = '', $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
478 echo "<TR BGCOLOR=\"$color[0]\"><TD>";
479 echo " <TABLE BGCOLOR=\"$color[4]\" width=\"100%\" CELLPADDING=\"2\" CELLSPACING=\"0\" BORDER=\"0\"><TR>\n";
480 echo " <TD ALIGN=LEFT>$paginator</TD>\n";
481 echo ' <TD ALIGN=CENTER>' . get_selectall_link($start_msg, $sort) . "</TD>\n";
482 echo " <TD ALIGN=RIGHT>$msg_cnt_str</TD>\n";
483 echo " </TR></TABLE>\n";
484 echo "</TD></TR>";
485
486 /** The delete and move options */
487 echo "<TR><TD BGCOLOR=\"$color[0]\">";
488
489 echo "\n<FORM name=messageList method=post action=\"$moveURL\">\n";
490 echo "<TABLE BGCOLOR=\"$color[0]\" COLS=2 BORDER=0 cellpadding=0 cellspacing=0 width=100%>\n";
491
492 echo " <TR>\n" .
493 " <TD ALIGN=LEFT VALIGN=CENTER NOWRAP>\n" .
494 ' <SMALL>&nbsp;' . _("Move selected to:") . "</SMALL>\n" .
495 " </TD>\n" .
496 " <TD ALIGN=RIGHT NOWRAP>\n" .
497 ' <SMALL>&nbsp;' . _("Transform Selected Messages") . ": &nbsp; </SMALL><BR>\n" .
498 " </TD>\n" .
499 " </TR>\n" .
500 " <TR>\n" .
501 " <TD ALIGN=LEFT VALIGN=CENTER NOWRAP>\n" .
502 ' <SMALL>&nbsp;<TT><SELECT NAME="targetMailbox">';
503
504 $boxes = sqimap_mailbox_list($imapConnection);
505 for ($i = 0; $i < count($boxes); $i++) {
506 if (!in_array("noselect", $boxes[$i]['flags'])) {
507 $box = $boxes[$i]['unformatted'];
508 $box2 = str_replace(' ', '&nbsp;', $boxes[$i]['formatted']);
509 echo " <OPTION VALUE=\"$box\">$box2</option>\n";
510 }
511 }
512 echo ' </SELECT></TT></SMALL>';
513 echo " <SMALL><INPUT TYPE=SUBMIT NAME=\"moveButton\" VALUE=\"" . _("Move") . "\"></SMALL>\n";
514 echo " </TD>\n";
515 echo " <TD ALIGN=RIGHT NOWRAP>&nbsp;&nbsp;&nbsp;\n";
516 if (!$auto_expunge) {
517 echo ' <INPUT TYPE=SUBMIT NAME="expungeButton" VALUE="'. _("Expunge") .'">&nbsp;'. _("mailbox") ."&nbsp;\n";
518 }
519 echo " <INPUT TYPE=SUBMIT NAME=\"markRead\" VALUE=\"". _("Read")."\">\n";
520 echo " <INPUT TYPE=SUBMIT NAME=\"markUnread\" VALUE=\"". _("Unread")."\">\n";
521 echo " <INPUT TYPE=SUBMIT VALUE=\"". _("Delete") . "\">&nbsp;\n";
522 echo " </TD>\n";
523 echo " </TR>\n";
524 echo "</TABLE>\n";
525 do_hook('mailbox_form_before');
526 echo '</TD></TR>';
527
528 echo "<TR><TD BGCOLOR=\"$color[0]\">";
529 echo "<TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=";
530 if ($GLOBALS['alt_index_colors']) {
531 echo "0";
532 } else {
533 echo "1";
534 }
535 echo " BGCOLOR=\"$color[0]\">";
536 echo "<TR BGCOLOR=\"$color[5]\" ALIGN=\"center\">";
537
538 /* Print the headers. */
539 for ($i=1; $i <= count($index_order); $i++) {
540 switch ($index_order[$i]) {
541 case 1: /* checkbox */
542 case 5: /* flags */
543 echo ' <TD WIDTH="1%"><B>&nbsp;</B></TD>';
544 break;
545
546 case 2: /* from */
547 if (($mailbox == $sent_folder)
548 || ($mailbox == $draft_folder)) {
549 echo ' <TD WIDTH="25%"><B>'. _("To") .'</B>';
550 } else {
551 echo ' <TD WIDTH="25%"><B>'. _("From") .'</B>';
552 }
553
554 ShowSortButton($sort, $mailbox, 2, 3);
555 echo "</TD>\n";
556 break;
557
558 case 3: /* date */
559 echo ' <TD NOWRAP WIDTH="5%"><B>'. _("Date") .'</B>';
560 ShowSortButton($sort, $mailbox, 0, 1);
561 echo "</TD>\n";
562 break;
563
564 case 4: /* subject */
565 echo ' <TD><B>'. _("Subject") .'</B> ';
566 ShowSortButton($sort, $mailbox, 4, 5);
567 echo "</TD>\n";
568 break;
569
570 case 6: /* size */
571 echo ' <TD WIDTH="5%"><b>' . _("Size")."</b></TD>\n";
572 break;
573 }
574 }
575 echo "</TR>\n";
576 }
577
578 /*******************************************************************/
579 /* This function shows the sort button. Isn't this a good comment? */
580 /*******************************************************************/
581 function ShowSortButton($sort, $mailbox, $Up, $Down) {
582 /* Figure out which image we want to use. */
583 if ($sort != $Up && $sort != $Down) {
584 $img = 'sort_none.gif';
585 $which = $Up;
586 } elseif ($sort == $Up) {
587 $img = 'up_pointer.gif';
588 $which = $Down;
589 } else {
590 $img = 'down_pointer.gif';
591 $which = 6;
592 }
593
594 /* Now that we have everything figured out, show the actual button. */
595 echo ' <a href="right_main.php?newsort=' . $which .
596 '&startMessage=1&mailbox=' . urlencode($mailbox) .
597 '"><IMG SRC="../images/' . $img .
598 '" BORDER=0 WIDTH=12 HEIGHT=10></a>';
599 }
600
601 function get_selectall_link($start_msg, $sort) {
602 global $checkall, $PHP_SELF, $what, $where, $mailbox;
603
604 $result =
605 '&nbsp;<script language="JavaScript">' .
606 "\n<!-- \n" .
607 "function CheckAll() {\n" .
608 " for (var i = 0; i < document.messageList.elements.length; i++) {\n" .
609 " if( document.messageList.elements[i].type == 'checkbox' ) {\n" .
610 " document.messageList.elements[i].checked = !(document.messageList.elements[i].checked);\n".
611 " }\n" .
612 " }\n" .
613 "}\n" .
614 'window.document.write(\'<a href=# onClick="CheckAll();">' . _("Toggle All") . "</a>');\n" .
615 "//-->\n" .
616 "</script>\n<noscript>\n";
617
618 $result .= "<a href=\"$PHP_SELF?mailbox=" . urlencode($mailbox)
619 . "&startMessage=$start_msg&sort=$sort&checkall=";
620 if (isset($checkall) && $checkall == '1') {
621 $result .= '0';
622 } else {
623 $result .= '1';
624 }
625
626 if (isset($where) && isset($what)) {
627 $result .= '&where=' . urlencode($where) . '&what=' . urlencode($what);
628 }
629
630 $result .= "\">";
631
632 if (isset($checkall) && ($checkall == '1')) {
633 $result .= _("Unselect All");
634 } else {
635 $result .= _("Select All");
636 }
637
638 $result .= "</A>\n</noscript>\n";
639
640 /* Return our final result. */
641 return ($result);
642 }
643
644 /**
645 * This function computes the "Viewing Messages..." string.
646 */
647 function get_msgcnt_str($start_msg, $end_msg, $num_msgs) {
648 /* Compute the $msg_cnt_str. */
649 $result = '';
650 if ($start_msg < $end_msg) {
651 $result = sprintf(_("Viewing Messages: <B>%s</B> to <B>%s</B> (%s total)"), $start_msg, $end_msg, $num_msgs);
652 } else if ($start_msg == $end_msg) {
653 $result = sprintf(_("Viewing Message: <B>%s</B> (1 total)"), $start_msg);
654 } else {
655 $result = '<br>';
656 }
657
658 /* Return our result string. */
659 return ($result);
660 }
661
662 /**
663 * This function computes the paginator string.
664 */
665 function get_paginator_str
666 ($urlMailbox, $start_msg, $end_msg, $num_msgs, $show_num) {
667 $nextGroup = $start_msg + $show_num;
668 $prevGroup = $start_msg - $show_num;
669
670 if ($sort == 6) {
671 $use = 0;
672 } else {
673 $use = 1;
674 }
675 $lMore = '';
676 $rMore = '';
677 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 = "<A HREF=\"right_main.php?use_mailbox_cache=$use&&startMessage=$nextGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Next") ."</A>\n";
680 } else if (($nextGroup > $num_msgs) && ($prevGroup >= 0)) {
681 $lMore = "<A HREF=\"right_main.php?use_mailbox_cache=$use&startMessage=$prevGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Previous") . '</A>';
682 $rMore = "<FONT COLOR=\"$color[9]\">"._("Next")."</FONT>\n";
683 } else if (($nextGroup <= $num_msgs) && ($prevGroup < 0)) {
684 $lMore = "<FONT COLOR=\"$color[9]\">"._("Previous") . '</FONT>';
685 $rMore = "<A HREF=\"right_main.php?use_mailbox_cache=$use&startMessage=$nextGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Next") ."</A>\n";
686 }
687 if ($lMore <> '') {
688 $lMore .= ' | ';
689 }
690
691 /* Page selector block. Following code computes page links. */
692 $mMore = '';
693 if (!getPref($data_dir, $username, 'page_selector')
694 && ($num_msgs > $show_num)) {
695 $j = intval( $num_msgs / $show_num ); // Max pages
696 $k = max( 1, $j / getPref($data_dir, $username, 'page_selector_max', PG_SEL_MAX ) );
697 if ($num_msgs % $show_num <> 0 ) {
698 $j++;
699 }
700 $start_msgs = min( $start_msgs, $num_msgs );
701 $p = intval( $start_msgs / $show_num ) + 1;
702 $i = 1;
703 while( $i < $p ) {
704 $pg = intval( $i );
705 $start = ( ($pg-1) * $show_num ) + 1;
706 $mMore .= "<a href=\"right_main.php?use_mailbox_cache=$use_mailbox_cache&startMessage=$start" .
707 "&mailbox=$urlMailbox\" TARGET=\"right\">$pg</a> ";
708 $i += $k;
709 }
710 $mMore .= "<b>$p</b> ";
711 $i += $k;
712 while( $i <= $j ) {
713 $pg = intval( $i );
714 $start = ( ($pg-1) * $show_num ) + 1;
715 $mMore .= "<a href=\"right_main.php?use_mailbox_cache=$use_mailbox_cache&startMessage=$start"
716 . "&mailbox=$urlMailbox\" TARGET=\"right\">$pg</a> ";
717 $i+=$k;
718 }
719 $mMore .= ' | ';
720 }
721
722 /* Return the resulting string. */
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 ?>