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