Search call back adjusted to fit new format
[squirrelmail.git] / functions / mailbox_display.php
CommitLineData
59177427 1<?php
2ba13803 2
35586184 3/**
4 * mailbox_display.php
5 *
15e6162e 6 * Copyright (c) 1999-2002 The SquirrelMail Project Team
35586184 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 */
a4c2cd49 14
35586184 15define('PG_SEL_MAX', 10); /* Default value for page_selector_max. */
16
17function printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $start_msg, $where, $what) {
bdfb67f8 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"])) {
ac53fb56 28 $GLOBALS["row_count"] = 0;
bdfb67f8 29 }
30 $GLOBALS["row_count"]++;
31 if ($GLOBALS["row_count"] % 2) {
32 if (!isset($color[12])) $color[12] = '#EAEAEA';
ac53fb56 33 $color_string = $color[12];
bdfb67f8 34 }
35 }
36 $msg = $msgs[$key];
37
8767fd29 38 $senderName = sqimap_find_displayable_name($msg['FROM']);
bdfb67f8 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)) {
bd9bbfef 51 $flag = "<font color=\"$color[2]\">";
bdfb67f8 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
a3439b27 65 if (handleAsSent($mailbox)) {
bdfb67f8 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']) != '') {
90bc0b93 83 if ($message_highlight_list[$i]['match_type'] == 'to_cc') {
bdfb67f8 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 }
90bc0b93 88 } else if (strpos('^^'.strtolower($msg[strtoupper($message_highlight_list[$i]['match_type'])]),strtolower($message_highlight_list[$i]['value']))) {
bdfb67f8 89 $hlt_color = $message_highlight_list[$i]['color'];
90 continue;
b60b58f9 91 }
bdfb67f8 92 }
93 }
94
95 if (!isset($hlt_color)) {
96 $hlt_color = $color_string;
97 }
98
99 if ($where && $what) {
a5ee5ac2 100 if( !isset( $pos ) || $pos == '' ) {
101 $pos = '0';
102 }
103 $search_stuff = "&pos=" . urlencode( $pos ) . "&where=".urlencode($where).'&what='.urlencode($what);
bdfb67f8 104 }
105
106 $checked = ($checkall == 1 ?' checked' : '');
107
108 for ($i=1; $i <= count($index_order); $i++) {
109 switch ($index_order[$i]) {
110 case 1: /* checkbox */
bd9bbfef 111 echo " <td bgcolor=\"$hlt_color\" align=center><input type=checkbox name=\"msg[$t]\" value=".$msg["ID"]."$checked></TD>\n";
bdfb67f8 112 break;
113 case 2: /* from */
bd9bbfef 114 echo " <td bgcolor=\"$hlt_color\">$italic$bold$flag$fontstr$senderName$fontstr_end$flag_end$bold_end$italic_end</td>\n";
bdfb67f8 115 break;
116 case 3: /* date */
bd9bbfef 117 echo " <td nowrap bgcolor=\"$hlt_color\"><center>$bold$flag$fontstr".$msg["DATE_STRING"]."$fontstr_end$flag_end$bold_end</center></td>\n";
bdfb67f8 118 break;
119 case 4: /* subject */
bd9bbfef 120 echo " <td bgcolor=\"$hlt_color\">$bold";
bdfb67f8 121 if (! isset($search_stuff)) { $search_stuff = ''; }
122 echo "<a href=\"read_body.php?mailbox=$urlMailbox&passed_id=".$msg["ID"]."&startMessage=$start_msg&show_more=0$search_stuff\"";
123 do_hook("subject_link");
124
125 if ($subject != $msg['SUBJECT']) {
126 $title = get_html_translation_table(HTML_SPECIALCHARS);
127 $title = array_flip($title);
128 $title = strtr($msg['SUBJECT'], $title);
129 $title = str_replace('"', "''", $title);
130 echo " title=\"$title\"";
131 }
132 echo ">$flag$subject$flag_end</a>$bold_end</td>\n";
133 break;
134 case 5: /* flags */
135 $stuff = false;
bd9bbfef 136 echo " <td bgcolor=\"$hlt_color\" align=center nowrap><b><small>\n";
bdfb67f8 137 if (isset($msg['FLAG_ANSWERED']) &&
138 $msg['FLAG_ANSWERED'] == true) {
139 echo "A\n";
140 $stuff = true;
141 }
142 if ($msg['TYPE0'] == 'multipart') {
143 echo "+\n";
144 $stuff = true;
145 }
146 if ($default_use_priority) {
147 if (ereg('(1|2)',substr($msg['PRIORITY'],0,1))) {
bd9bbfef 148 echo "<font color=\"$color[1]\">!</font>\n";
bdfb67f8 149 $stuff = true;
150 }
151 if (ereg('(5)',substr($msg['PRIORITY'],0,1))) {
bd9bbfef 152 echo "<font color=\"$color[8]\">?</font>\n";
bdfb67f8 153 $stuff = true;
154 }
155 }
156 if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED']) {
157 echo "<font color=\"$color[1]\">D</font>\n";
158 $stuff = true;
159 }
160
161 if (!$stuff) {
162 echo "&nbsp;\n";
163 }
164 echo "</small></b></td>\n";
165 break;
166 case 6: /* size */
bd9bbfef 167 echo " <td bgcolor=\"$hlt_color\">$bold$fontstr" .
bdfb67f8 168 show_readable_size($msg['SIZE']) .
169 "$fontstr_end$bold_end</td>\n";
170 break;
171 }
172 }
173 echo "</tr>\n";
174}
175
176/**
177 * This function loops through a group of messages in the mailbox
178 * and shows them to the user.
179 */
180function showMessagesForMailbox
f506bb2c 181($imapConnection, $mailbox, $num_msgs, $start_msg, $sort,
182 $color, $show_num, $use_cache) {
bdfb67f8 183 global $msgs, $msort;
184 global $sent_folder, $draft_folder;
185 global $message_highlight_list;
186 global $auto_expunge;
187
188 /* If autoexpunge is turned on, then do it now. */
189 if ($auto_expunge == true) {
190 sqimap_mailbox_expunge($imapConnection, $mailbox, false);
191 }
192 sqimap_mailbox_select($imapConnection, $mailbox);
193
a3439b27 194 $issent = handleAsSent($mailbox);
bdfb67f8 195 if (!$use_cache) {
196 /* If it is sorted... */
197 if ($num_msgs >= 1) {
0d455368 198 if ($sort < 6) {
bdfb67f8 199 $id = range(1, $num_msgs);
0d455368 200 } else {
bdfb67f8 201 // if it's not sorted
202 if ($start_msg + ($show_num - 1) < $num_msgs) {
203 $end_msg = $start_msg + ($show_num-1);
204 } else {
205 $end_msg = $num_msgs;
206 }
207
208 if ($end_msg < $start_msg) {
209 $start_msg = $start_msg - $show_num;
210 if ($start_msg < 1) {
211 $start_msg = 1;
212 }
213 }
214
215 $real_startMessage = $num_msgs - $start_msg + 1;
216 $real_endMessage = $num_msgs - $start_msg - $show_num + 2;
217 if ($real_endMessage <= 0) {
218 $real_endMessage = 1;
219 }
220 $id = array_reverse(range($real_endMessage, $real_startMessage));
91f68e94 221 }
b60b58f9 222
91f68e94 223 $msgs_list = sqimap_get_small_header_list($imapConnection, $id, $issent);
224 $flags = sqimap_get_flags_list($imapConnection, $id, $issent);
225 foreach ($msgs_list as $hdr) {
bdfb67f8 226 $from[] = $hdr->from;
227 $date[] = $hdr->date;
228 $subject[] = $hdr->subject;
229 $to[] = $hdr->to;
230 $priority[] = $hdr->priority;
231 $cc[] = $hdr->cc;
232 $size[] = $hdr->size;
233 $type[] = $hdr->type0;
234 }
235 }
236
237 $j = 0;
238 if ($sort == 6) {
239 $end = $start_msg + $show_num - 1;
240 if ($num_msgs < $show_num) {
241 $end_loop = $num_msgs;
242 } else if ($end > $num_msgs) {
243 $end_loop = $num_msgs - $start_msg + 1;
244 } else {
245 $end_loop = $show_num;
b60b58f9 246 }
bdfb67f8 247 } else {
23d6bd09 248 $end = $num_msgs;
cd928157 249 $end_loop = $end;
bdfb67f8 250 }
f7b1b3b1 251
bdfb67f8 252 while ($j < $end_loop) {
cd928157 253 if (isset($date[$j])) {
254 $date[$j] = ereg_replace(' ', ' ', $date[$j]);
255 $tmpdate = explode(' ', trim($date[$j]));
256 } else {
bdfb67f8 257 $tmpdate = $date = array('', '', '', '', '', '');
cd928157 258 }
90bc0b93 259
260 $messages[$j]['TIME_STAMP'] = getTimeStamp($tmpdate);
261 $messages[$j]['DATE_STRING'] = getDateString($messages[$j]['TIME_STAMP']);
262 $messages[$j]['ID'] = $id[$j];
263 $messages[$j]['FROM'] = decodeHeader($from[$j]);
264 $messages[$j]['FROM-SORT'] = strtolower(sqimap_find_displayable_name(decodeHeader($from[$j])));
265 $messages[$j]['SUBJECT'] = decodeHeader($subject[$j]);
266 $messages[$j]['SUBJECT-SORT'] = strtolower(decodeHeader($subject[$j]));
267 $messages[$j]['TO'] = decodeHeader($to[$j]);
268 $messages[$j]['PRIORITY'] = $priority[$j];
269 $messages[$j]['CC'] = $cc[$j];
270 $messages[$j]['SIZE'] = $size[$j];
271 $messages[$j]['TYPE0'] = $type[$j];
e9f8ea4e 272
273 # fix SUBJECT-SORT to remove Re:
bdfb67f8 274 $re_abbr = /* Add more here! */
275 'vedr|sv|' . /* Danish */
276 're|aw'; /* English */
f1e6f580 277
bdfb67f8 278 if (eregi( "^($re_abbr):[ ]*(.*)$", $messages[$j]['SUBJECT-SORT'], $regs)) {
279 $messages[$j]['SUBJECT-SORT'] = $regs[2];
280 }
b60b58f9 281
5b6ae78a 282 $num = 0;
283 while ($num < count($flags[$j])) {
bdfb67f8 284 if ($flags[$j][$num] == 'Deleted') {
285 $messages[$j]['FLAG_DELETED'] = true;
286 } else if ($flags[$j][$num] == 'Answered') {
287 $messages[$j]['FLAG_ANSWERED'] = true;
288 } else if ($flags[$j][$num] == 'Seen') {
289 $messages[$j]['FLAG_SEEN'] = true;
290 } else if ($flags[$j][$num] == 'Flagged') {
291 $messages[$j]['FLAG_FLAGGED'] = true;
292 }
293 $num++;
7151188f 294 }
5b6ae78a 295 $j++;
bdfb67f8 296 }
f9b3e5d9 297
bdfb67f8 298 /* Only ignore messages flagged as deleted if we are using a
299 * trash folder or auto_expunge */
300 if (((isset($move_to_trash) && $move_to_trash)
301 || (isset($auto_expunge) && $auto_expunge)) && $sort != 6) {
f7b1b3b1 302
f9b3e5d9 303 /** Find and remove the ones that are deleted */
304 $i = 0;
305 $j = 0;
f7b1b3b1 306
23d6bd09 307 while ($j < $num_msgs) {
bdfb67f8 308 if (isset($messages[$j]['FLAG_DELETED']) && $messages[$j]['FLAG_DELETED'] == true) {
309 $j++;
310 continue;
311 }
312 $msgs[$i] = $messages[$j];
313
314 $i++;
315 $j++;
5b6ae78a 316 }
23d6bd09 317 $num_msgs = $i;
bdfb67f8 318 } else {
319 if (!isset($messages)) {
320 $messages = array();
321 }
322 $msgs = $messages;
323 }
324 }
325
326 // There's gotta be messages in the array for it to sort them.
327 if ($num_msgs > 0 && ! $use_cache) {
328 /** 0 = Date (up) 4 = Subject (up)
329 ** 1 = Date (dn) 5 = Subject (dn)
330 ** 2 = Name (up)
331 ** 3 = Name (dn)
332 **/
333 session_unregister("msgs");
334 if (($sort == 0) || ($sort == 1))
90bc0b93 335 $msort = array_cleave ($msgs, 'TIME_STAMP');
bdfb67f8 336 elseif (($sort == 2) || ($sort == 3))
90bc0b93 337 $msort = array_cleave ($msgs, 'FROM-SORT');
bdfb67f8 338 elseif (($sort == 4) || ($sort == 5))
90bc0b93 339 $msort = array_cleave ($msgs, 'SUBJECT-SORT');
bdfb67f8 340 else // ($sort == 6)
0d455368 341 $msort = $msgs;
342
bdfb67f8 343 if ($sort < 6) {
9b0f85eb 344 if ($sort % 2) {
bdfb67f8 345 asort($msort);
0d455368 346 } else {
bdfb67f8 347 arsort($msort);
0d455368 348 }
bdfb67f8 349 }
350 session_register('msort');
351 }
352 displayMessageArray($imapConnection, $num_msgs, $start_msg, $msgs, $msort, $mailbox, $sort, $color,$show_num);
353 session_register('msgs');
354}
355
356/**
357 * Generic function to convert the msgs array into an HTML table.
358 */
359function displayMessageArray($imapConnection, $num_msgs, $start_msg, &$msgs, $msort, $mailbox, $sort, $color, $show_num) {
360 global $folder_prefix, $sent_folder;
361 global $imapServerAddress, $data_dir, $username, $use_mailbox_cache;
362 global $index_order, $real_endMessage, $real_startMessage, $checkall;
363
364 /* If cache isn't already set, do it now. */
365 if (!session_is_registered('msgs')) { session_register('msgs'); }
366 if (!session_is_registered('msort')) { session_register('msort'); }
367
368 if ($start_msg + ($show_num - 1) < $num_msgs) {
369 $end_msg = $start_msg + ($show_num-1);
370 } else {
371 $end_msg = $num_msgs;
372 }
373
374 if ($end_msg < $start_msg) {
375 $start_msg = $start_msg - $show_num;
376 if ($start_msg < 1) { $start_msg = 1; }
377 }
378
379 $urlMailbox = urlencode($mailbox);
380
381 do_hook('mailbox_index_before');
382
383 $msg_cnt_str = get_msgcnt_str($start_msg, $end_msg, $num_msgs);
7b294953 384 $paginator_str = get_paginator_str
385 ($urlMailbox, $start_msg, $end_msg, $num_msgs, $show_num, $sort);
bdfb67f8 386
387 if (! isset($msg)) {
388 $msg = '';
389 }
390
29eb5486 391 mail_message_listing_beginning( $imapConnection,
bdfb67f8 392 "move_messages.php?msg=$msg&mailbox=$urlMailbox&startMessage=$start_msg",
393 $mailbox, $sort, $msg_cnt_str, $paginator_str, $start_msg);
394
395 $groupNum = $start_msg % ($show_num - 1);
396 $real_startMessage = $start_msg;
397 if ($sort == 6) {
398 if ($end_msg - $start_msg < $show_num - 1) {
23d6bd09 399 $end_msg = $end_msg - $start_msg + 1;
400 $start_msg = 1;
bdfb67f8 401 } else if ($start_msg > $show_num) {
23d6bd09 402 $end_msg = $show_num;
403 $start_msg = 1;
bdfb67f8 404 }
405 }
406 $endVar = $end_msg + 1;
407
408 /* Loop through and display the info for each message. */
409 $t = 0; // $t is used for the checkbox number
410 if ($num_msgs == 0) { // if there's no messages in this folder
411 echo "<TR><TD BGCOLOR=\"$color[4]\" COLSPAN=" . count($index_order) . ">\n".
412 " <CENTER><BR><B>". _("THIS FOLDER IS EMPTY") ."</B><BR>&nbsp;</CENTER>\n".
413 "</TD></TR>";
414 } elseif ($start_msg == $end_msg) {
415 /* If there's only one message in the box, handle it differently. */
416 if ($sort != 6) {
417 $i = $start_msg;
418 } else {
419 $i = 1;
420 }
421
422 reset($msort);
423 $k = 0;
424 do {
425 $key = key($msort);
426 next($msort);
427 $k++;
428 } while (isset ($key) && ($k < $i));
429 printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $real_startMessage, 0, 0);
430 } else {
431 $i = $start_msg;
432
433 reset($msort);
434 $k = 0;
435 do {
436 $key = key($msort);
437 next($msort);
438 $k++;
439 } while (isset ($key) && ($k < $i));
440
441 do {
442 printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $real_startMessage, 0, 0);
443 $key = key($msort);
444 $t++;
445 $i++;
446 next($msort);
447 } while ($i && $i < $endVar);
448 }
449
450 echo '</table>'.
bd9bbfef 451 "<table bgcolor=\"$color[9]\" width=\"100%\" border=0 cellpadding=1 cellspacing=1>" .
452 "<tr BGCOLOR=\"$color[4]\"><td>" .
453 "<table width=\"100%\" BGCOLOR=\"$color[4]\" border=0 cellpadding=1 cellspacing=0><tr><td>$paginator_str</td>".
bdfb67f8 454 "<td align=right>$msg_cnt_str</td></tr></table>".
bd9bbfef 455 "</td></tr>".
bdfb67f8 456 "</table>";
457 /** End of message-list table */
458
459 do_hook('mailbox_index_after');
460 echo "</TABLE></FORM>\n";
461}
462
463/**
464 * Displays the standard message list header. To finish the table,
465 * you need to do a "</table></table>";
466 *
467 * $moveURL is the URL to submit the delete/move form to
468 * $mailbox is the current mailbox
469 * $sort is the current sorting method (-1 for no sorting available [searches])
470 * $Message is a message that is centered on top of the list
471 * $More is a second line that is left aligned
472 */
473function mail_message_listing_beginning
f7b1b3b1 474 ($imapConnection, $moveURL, $mailbox = '', $sort = -1,
bdfb67f8 475 $msg_cnt_str = '', $paginator = '&nbsp;', $start_msg = 1) {
476 global $color, $index_order, $auto_expunge, $move_to_trash;
477 global $checkall, $sent_folder, $draft_folder;
478 $urlMailbox = urlencode($mailbox);
479
480 /*
481 * This is the beginning of the message list table.
482 * It wraps around all messages
483 */
bd9bbfef 484 echo "<FORM name=messageList method=post action=\"$moveURL\">\n"
485 . "<TABLE WIDTH=\"100%\" BORDER=\"0\" CELLPADDING=\"1\" CELLSPACING=\"0\">\n"
7b294953 486 . "<TR BGCOLOR=\"$color[0]\"><TD>"
487 . " <TABLE BGCOLOR=\"$color[4]\" width=\"100%\" CELLPADDING=\"2\" CELLSPACING=\"0\" BORDER=\"0\"><TR>\n"
488 . " <TD ALIGN=LEFT>$paginator</TD>\n"
489 . " <TD ALIGN=RIGHT>$msg_cnt_str</TD>\n"
490 . " </TR></TABLE>\n"
491 . '</TD></TR>'
492 . "<TR><TD BGCOLOR=\"$color[0]\">\n"
7b294953 493 . "<TABLE BGCOLOR=\"$color[0]\" COLS=2 BORDER=0 cellpadding=0 cellspacing=0 width=\"100%\">\n"
494 . " <TR>\n"
bd9bbfef 495 . " <TD ALIGN=LEFT VALIGN=MIDDLE NOWRAP>\n"
b4b83736 496 . ' <SMALL>&nbsp;' . _("Move Selected To:") . "</SMALL>\n"
7b294953 497 . " </TD>\n"
498 . " <TD ALIGN=RIGHT NOWRAP>\n"
499 . ' <SMALL>&nbsp;' . _("Transform Selected Messages") . ": &nbsp; </SMALL><BR>\n"
500 . " </TD>\n"
501 . " </TR>\n"
502 . " <TR>\n"
bd9bbfef 503 . " <TD ALIGN=LEFT VALIGN=MIDDLE NOWRAP>\n"
7b294953 504 . ' <SMALL>&nbsp;<TT><SELECT NAME="targetMailbox">';
bdfb67f8 505
506 $boxes = sqimap_mailbox_list($imapConnection);
507 for ($i = 0; $i < count($boxes); $i++) {
508 if (!in_array("noselect", $boxes[$i]['flags'])) {
90bc0b93 509 $box = $boxes[$i]['unformatted'];
3b7e638f 510 $box2 = str_replace(' ', '&nbsp;', $boxes[$i]['unformatted-disp']);
14eb705c 511 echo " <OPTION VALUE=\"$box\">$box2</option>\n";
bdfb67f8 512 }
513 }
ac208bba 514 echo ' </SELECT></TT>&nbsp;'.
515 "<INPUT TYPE=SUBMIT NAME=\"moveButton\" VALUE=\"" . _("Move") . "\"></SMALL>\n".
bdfb67f8 516 " </TD>\n".
517 " <TD ALIGN=RIGHT NOWRAP>&nbsp;&nbsp;&nbsp;\n";
518 if (!$auto_expunge) {
519 echo ' <INPUT TYPE=SUBMIT NAME="expungeButton" VALUE="'. _("Expunge") .'">&nbsp;'. _("mailbox") ."&nbsp;\n";
520 }
521 echo " <INPUT TYPE=SUBMIT NAME=\"markRead\" VALUE=\"". _("Read")."\">\n".
522 " <INPUT TYPE=SUBMIT NAME=\"markUnread\" VALUE=\"". _("Unread")."\">\n".
523 " <INPUT TYPE=SUBMIT VALUE=\"". _("Delete") . "\">&nbsp;\n".
524 " </TD>\n".
525 " </TR>\n".
526 "</TABLE>\n";
527 do_hook('mailbox_form_before');
528 echo '</TD></TR>'.
529
530 "<TR><TD BGCOLOR=\"$color[0]\">".
bd9bbfef 531 "<TABLE WIDTH=\"100%\" BORDER=0 CELLPADDING=2 CELLSPACING=";
bdfb67f8 532 if ($GLOBALS['alt_index_colors']) {
ac53fb56 533 echo "0";
bdfb67f8 534 } else {
ac53fb56 535 echo "1";
bdfb67f8 536 }
537 echo " BGCOLOR=\"$color[0]\">".
538 "<TR BGCOLOR=\"$color[5]\" ALIGN=\"center\">";
539
540 /* Print the headers. */
541 for ($i=1; $i <= count($index_order); $i++) {
542 switch ($index_order[$i]) {
543 case 1: /* checkbox */
544 case 5: /* flags */
545 echo ' <TD WIDTH="1%"><B>&nbsp;</B></TD>';
546 break;
547
548 case 2: /* from */
a3439b27 549 if (handleAsSent($mailbox)) {
bdfb67f8 550 echo ' <TD WIDTH="25%"><B>'. _("To") .'</B>';
551 } else {
552 echo ' <TD WIDTH="25%"><B>'. _("From") .'</B>';
553 }
554
555 ShowSortButton($sort, $mailbox, 2, 3);
556 echo "</TD>\n";
557 break;
558
559 case 3: /* date */
560 echo ' <TD NOWRAP WIDTH="5%"><B>'. _("Date") .'</B>';
561 ShowSortButton($sort, $mailbox, 0, 1);
562 echo "</TD>\n";
563 break;
564
565 case 4: /* subject */
566 echo ' <TD><B>'. _("Subject") .'</B> ';
567 ShowSortButton($sort, $mailbox, 4, 5);
568 echo "</TD>\n";
569 break;
570
571 case 6: /* size */
572 echo ' <TD WIDTH="5%"><b>' . _("Size")."</b></TD>\n";
573 break;
574 }
575 }
576 echo "</TR>\n";
577}
578
579/*
580 * This function shows the sort button. Isn't this a good comment?
581 */
582function ShowSortButton($sort, $mailbox, $Up, $Down) {
583 /* Figure out which image we want to use. */
584 if ($sort != $Up && $sort != $Down) {
001befaf 585 $img = 'sort_none.png';
bdfb67f8 586 $which = $Up;
587 } elseif ($sort == $Up) {
001befaf 588 $img = 'up_pointer.png';
bdfb67f8 589 $which = $Down;
590 } else {
001befaf 591 $img = 'down_pointer.png';
bdfb67f8 592 $which = 6;
593 }
594
595 /* Now that we have everything figured out, show the actual button. */
596 echo ' <a href="right_main.php?newsort=' . $which .
597 '&startMessage=1&mailbox=' . urlencode($mailbox) .
598 '"><IMG SRC="../images/' . $img .
599 '" BORDER=0 WIDTH=12 HEIGHT=10></a>';
600}
601
602function get_selectall_link($start_msg, $sort) {
f506bb2c 603 global $checkall, $what, $where, $mailbox, $javascript_on;
604 global $PHP_SELF, $PG_SHOWNUM;
bdfb67f8 605
606 if ($javascript_on) {
607 $result =
608 '<script language="JavaScript">' .
609 "\n<!-- \n" .
610 "function CheckAll() {\n" .
611 " for (var i = 0; i < document.messageList.elements.length; i++) {\n" .
612 " if( document.messageList.elements[i].type == 'checkbox' ) {\n" .
613 " document.messageList.elements[i].checked = !(document.messageList.elements[i].checked);\n".
614 " }\n" .
615 " }\n" .
616 "}\n" .
617 "//-->\n" .
7c0060c9 618 '</script><a href="#" onClick="CheckAll();">' . _("Toggle All") . "</a>\n";
bdfb67f8 619 } else {
620 $result .= "<a href=\"$PHP_SELF?mailbox=" . urlencode($mailbox)
c57b0888 621 . "&startMessage=$start_msg&sort=$sort&checkall=";
bdfb67f8 622 if (isset($checkall) && $checkall == '1') {
623 $result .= '0';
624 } else {
625 $result .= '1';
626 }
627
628 if (isset($where) && isset($what)) {
629 $result .= '&where=' . urlencode($where)
630 . '&what=' . urlencode($what);
631 }
632
f506bb2c 633 if ($PG_SHOWNUM == 999999) {
634 $result .= '&PG_SHOWNUM=999999';
635 }
636
bdfb67f8 637 $result .= "\">";
638
639 if (isset($checkall) && ($checkall == '1')) {
640 $result .= _("Unselect All");
23d6bd09 641 } else {
bdfb67f8 642 $result .= _("Select All");
23d6bd09 643 }
644
bdfb67f8 645 $result .= "</A>\n";
23d6bd09 646 }
647
bdfb67f8 648 /* Return our final result. */
649 return ($result);
650}
1a0e0983 651
bdfb67f8 652/**
653* This function computes the "Viewing Messages..." string.
654*/
655function get_msgcnt_str($start_msg, $end_msg, $num_msgs) {
656 /* Compute the $msg_cnt_str. */
657 $result = '';
658 if ($start_msg < $end_msg) {
659 $result = sprintf(_("Viewing Messages: <B>%s</B> to <B>%s</B> (%s total)"), $start_msg, $end_msg, $num_msgs);
660 } else if ($start_msg == $end_msg) {
661 $result = sprintf(_("Viewing Message: <B>%s</B> (1 total)"), $start_msg);
662 } else {
663 $result = '<br>';
664 }
23d6bd09 665
bdfb67f8 666 /* Return our result string. */
667 return ($result);
668}
669
670/**
7b294953 671 * Generate a paginator link.
672 */
673function get_paginator_link
674($box, $start_msg, $use, $text) {
675 $result = "<A HREF=\"right_main.php?use_mailbox_cache=$use"
676 . "&startMessage=$start_msg&mailbox=$box\" "
677 . "TARGET=\"right\">$text</A>";
678 return ($result);
679}
680
681/**
682 * This function computes the paginator string.
683 */
bdfb67f8 684function get_paginator_str
7b294953 685($box, $start_msg, $end_msg, $num_msgs, $show_num, $sort) {
f506bb2c 686 global $username, $data_dir, $use_mailbox_cache, $color, $PG_SHOWNUM;
bdfb67f8 687
7b294953 688 /* Initialize paginator string chunks. */
689 $prv_str = '';
690 $nxt_str = '';
691 $pg_str = '';
692 $all_str = '';
693 $tgl_str = '';
694
695 /* Create simple strings that will be creating the paginator. */
696 $spc = '&nbsp;'; /* This will be used as a space. */
697 $sep = '|'; /* This will be used as a seperator. */
bdfb67f8 698
7b294953 699 /* Get some paginator preference values. */
311339a0 700 $pg_sel = getPref($data_dir, $username, 'page_selector', SMPREF_ON);
7b294953 701 $pg_max = getPref($data_dir, $username, 'page_selector_max', PG_SEL_MAX);
702
703 /* Make sure that our start message number is not too big. */
704 $start_msg = min($start_msg, $num_msgs);
705
706 /* Decide whether or not we will use the mailbox cache. */
707 /* Not sure why $use_mailbox_cache is even passed in. */
bdfb67f8 708 if ($sort == 6) {
709 $use = 0;
710 } else {
711 $use = 1;
712 }
7b294953 713
714 /* Compute the starting message of the previous and next page group. */
715 $next_grp = $start_msg + $show_num;
716 $prev_grp = $start_msg - $show_num;
717
718 /* Compute the basic previous and next strings. */
719 if (($next_grp <= $num_msgs) && ($prev_grp >= 0)) {
720 $prv_str = get_paginator_link($box, $prev_grp, $use, _("Previous"));
721 $nxt_str = get_paginator_link($box, $next_grp, $use, _("Next"));
722 } else if (($next_grp > $num_msgs) && ($prev_grp >= 0)) {
723 $prv_str = get_paginator_link($box, $prev_grp, $use, _("Previous"));
724 $nxt_str = "<FONT COLOR=\"$color[9]\">"._("Next")."</FONT>\n";
725 } else if (($next_grp <= $num_msgs) && ($prev_grp < 0)) {
726 $prv_str = "<FONT COLOR=\"$color[9]\">"._("Previous") . '</FONT>';
727 $nxt_str = get_paginator_link($box, $next_grp, $use, _("Next"));
bdfb67f8 728 }
7b294953 729
bdfb67f8 730 /* Page selector block. Following code computes page links. */
7b294953 731 if ($pg_sel && ($num_msgs > $show_num)) {
732 /* Most importantly, what is the current page!!! */
733 $cur_pg = intval($start_msg / $show_num) + 1;
734
735 /* Compute total # of pages and # of paginator page links. */
736 $tot_pgs = ceil($num_msgs / $show_num); /* Total # of Pages */
737 $vis_pgs = min($pg_max, $tot_pgs - 1); /* Visible Pages */
738
739 /************************************************************/
740 /* Compute the size of the four quarters of the page links. */
741 /************************************************************/
742
743 /* If we can, just show all the pages. */
744 if (($tot_pgs - 1) <= $pg_max) {
745 $q1_pgs = $cur_pg - 1;
746 $q2_pgs = $q3_pgs = 0;
747 $q4_pgs = $tot_pgs - $cur_pg;
748
749 /* Otherwise, compute some magic to choose the four quarters. */
750 } else {
751 /* Compute the magic base values. Added together, */
752 /* these values will always equal to the $pag_pgs. */
753 /* NOTE: These are DEFAULT values and do not take */
754 /* the current page into account. That is below. */
755 $q1_pgs = floor($vis_pgs/4);
756 $q2_pgs = round($vis_pgs/4, 0);
757 $q3_pgs = ceil($vis_pgs/4);
758 $q4_pgs = round(($vis_pgs - $q2_pgs)/3, 0);
759
760 /* Adjust if the first quarter contains the current page. */
761 if (($cur_pg - $q1_pgs) < 1) {
762 $extra_pgs = ($q1_pgs - ($cur_pg - 1)) + $q2_pgs;
763 $q1_pgs = $cur_pg - 1;
764 $q2_pgs = 0;
765 $q3_pgs += ceil($extra_pgs / 2);
766 $q4_pgs += floor($extra_pgs / 2);
767
768 /* Adjust if the first and second quarters intersect. */
769 } else if (($cur_pg - $q2_pgs - ceil($q2_pgs/3)) <= $q1_pgs) {
770 $extra_pgs = $q2_pgs;
771 $extra_pgs -= ceil(($cur_pg - $q1_pgs - 1) * 0.75);
772 $q2_pgs = ceil(($cur_pg - $q1_pgs - 1) * 0.75);
773 $q3_pgs += ceil($extra_pgs / 2);
774 $q4_pgs += floor($extra_pgs / 2);
775
776 /* Adjust if the fourth quarter contains the current page. */
777 } else if (($cur_pg + $q4_pgs) >= $tot_pgs) {
778 $extra_pgs = ($q4_pgs - ($tot_pgs - $cur_pg)) + $q3_pgs;
779 $q3_pgs = 0;
780 $q4_pgs = $tot_pgs - $cur_pg;
781 $q1_pgs += floor($extra_pgs / 2);
782 $q2_pgs += ceil($extra_pgs / 2);
783
784 /* Adjust if the third and fourth quarter intersect. */
785 } else if (($cur_pg + $q3_pgs + 1) >= ($tot_pgs - $q4_pgs + 1)) {
786 $extra_pgs = $q3_pgs;
787 $extra_pgs -= ceil(($tot_pgs - $cur_pg - $q4_pgs) * 0.75);
788 $q3_pgs = ceil(($tot_pgs - $cur_pg - $q4_pgs) * 0.75);
789 $q1_pgs += floor($extra_pgs / 2);
790 $q2_pgs += ceil($extra_pgs / 2);
791 }
23d6bd09 792 }
7b294953 793
794 /* I am leaving this debug code here, commented out, because */
795 /* it is a really nice way to see what the above code is doing. */
796 /* echo "qts = $q1_pgs/$q2_pgs/$q3_pgs/$q4_pgs = " */
797 /* . ($q1_pgs + $q2_pgs + $q3_pgs + $q4_pgs) . '<br>'; */
798
799 /************************************************************/
800 /* Print out the page links from the compute page quarters. */
801 /************************************************************/
802
803 /* Start with the first quarter. */
804 if (($q1_pgs == 0) && ($cur_pg > 1)) {
805 $pg_str .= "...$spc";
806 } else {
807 for ($pg = 1; $pg <= $q1_pgs; ++$pg) {
808 $start = (($pg-1) * $show_num) + 1;
809 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
810 }
811 if ($cur_pg - $q2_pgs - $q1_pgs > 1) {
812 $pg_str .= "...$spc";
813 }
23d6bd09 814 }
7b294953 815
816 /* Continue with the second quarter. */
817 for ($pg = $cur_pg - $q2_pgs; $pg < $cur_pg; ++$pg) {
818 $start = (($pg-1) * $show_num) + 1;
819 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
23d6bd09 820 }
7b294953 821
822 /* Now print the current page. */
823 $pg_str .= $cur_pg . $spc;
824
825 /* Next comes the third quarter. */
826 for ($pg = $cur_pg + 1; $pg <= $cur_pg + $q3_pgs; ++$pg) {
827 $start = (($pg-1) * $show_num) + 1;
828 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
829 }
830
831 /* And last, print the forth quarter page links. */
832 if (($q4_pgs == 0) && ($cur_pg < $tot_pgs)) {
833 $pg_str .= "...$spc";
834 } else {
835 if (($tot_pgs - $q4_pgs) > ($cur_pg + $q3_pgs)) {
836 $pg_str .= "...$spc";
837 }
838 for ($pg = $tot_pgs - $q4_pgs + 1; $pg <= $tot_pgs; ++$pg) {
839 $start = (($pg-1) * $show_num) + 1;
840 $pg_str .= get_paginator_link($box, $start, $use, $pg) . $spc;
841 }
842 }
f506bb2c 843 } else if ($PG_SHOWNUM == 999999) {
844 $pg_str = "<A HREF=\"right_main.php?use_mailbox_cache=$use"
845 . "&startMessage=1&mailbox=$box\" TARGET=\"right\">"
d72204a2 846 . _("Paginate") . '</A>' . $spc;
7b294953 847 }
848
849 /* If necessary, compute the 'show all' string. */
850 if (($prv_str != '') || ($nxt_str != '')) {
f506bb2c 851 $all_str = "<A HREF=\"right_main.php?PG_SHOWNUM=999999"
7b294953 852 . "&use_mailbox_cache=$use&startMessage=1&mailbox=$box\" "
853 . "TARGET=\"right\">" . _("Show All") . '</A>';
bdfb67f8 854 }
23d6bd09 855
7b294953 856 /* Last but not least, get the value for the toggle all link. */
857 $tgl_str = get_selectall_link($start_msg, $sort);
858
859 /* Put all the pieces of the paginator string together. */
860 $result = '';
7b294953 861 $result .= ($prv_str != '' ? $prv_str . $spc . $sep . $spc : '');
dbf3883b 862 $result .= ($nxt_str != '' ? $nxt_str . $spc . $sep . $spc : '');
863 $result .= ($pg_str != '' ? $pg_str : '');
f506bb2c 864 $result .= ($all_str != '' ? $sep . $spc . $all_str . $spc : '');
dbf3883b 865 $result .= ($result != '' ? $sep . $spc . $tgl_str: $tgl_str);
7b294953 866
867 /* If the resulting string is blank, return a non-breaking space. */
868 if ($result == '') {
869 $result = '&nbsp;';
bdfb67f8 870 }
7b294953 871
872 /* Return our final magical paginator string. */
873 return ($result);
bdfb67f8 874}
875
876function processSubject($subject) {
877 // Shouldn't ever happen -- caught too many times in the IMAP functions
878 if ($subject == '')
879 return _("(no subject)");
880
881 if (strlen($subject) <= 55)
882 return $subject;
883
884 $ent_strlen=strlen($subject);
885 $trim_val=50;
886 $ent_offset=0;
887 // see if this is entities-encoded string
888 // If so, Iterate through the whole string, find out
889 // the real number of characters, and if more
890 // than 55, substr with an updated trim value.
891 while (($ent_loc = strpos($subject, '&', $ent_offset)) !== false &&
892 ($ent_loc_end = strpos($subject, ';', $ent_loc)) !== false)
893 {
894 $trim_val += ($ent_loc_end-$ent_loc)+1;
895 $ent_strlen -= $ent_loc_end-$ent_loc;
896 $ent_offset = $ent_loc_end+1;
897 }
23d6bd09 898
bdfb67f8 899 if ($ent_strlen <= 55)
900 return $subject;
901
902 return substr($subject, 0, $trim_val) . '...';
903}
f93c93b9 904
a3439b27 905function handleAsSent($mailbox) {
906 global $sent_folder, $draft_folder;
907 global $handleAsSent_result;
908
909 /* First check if this is the sent or draft folder. */
910 $handleAsSent_result = (($mailbox == $sent_folder)
911 || ($mailbox == $draft_folder));
912
913 /* Then check the result of the handleAsSent hook. */
914 do_hook('check_handleAsSent_result', $mailbox);
915
916 /* And return the result. */
917 return ($handleAsSent_result);
918}
919
a5ee5ac2 920?>