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