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