fix bug #481886 with anonymous hint from sourceforge trackers :-)
[squirrelmail.git] / functions / mailbox_display.php
CommitLineData
59177427 1<?php
3302d0d4 2 /**
23d6bd09 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 */
a4c2cd49 13
f7b1b3b1 14 define('PG_SEL_MAX', 10); /* Default value for page_selector_max. */
f1e6f580 15
23d6bd09 16 function printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $start_msg, $where, $what) {
66289791 17 global $checkall;
af9404d7 18 global $color, $msgs, $msort;
f7b1b3b1 19 global $sent_folder, $draft_folder;
020abcf3 20 global $default_use_priority;
9d157cec 21 global $message_highlight_list;
8e265988 22 global $index_order;
cbdc5621 23
ac53fb56 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) {
f136c965 31 if (!isset($color[12])) $color[12] = '#EAEAEA';
ac53fb56 32 $color_string = $color[12];
33 }
b3b103cb 34 }
0d455368 35 $msg = $msgs[$key];
d92b6f31 36
3dd96399 37 $senderName = htmlspecialchars(sqimap_find_displayable_name($msg['FROM']));
2d367c68 38 if( $mailbox == 'None' ) {
f136c965 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 );
d6def997 44 }
05207a68 45 $urlMailbox = urlencode($mailbox);
f93c93b9 46 $subject = processSubject($msg['SUBJECT']);
926da13e 47 echo "<TR>\n";
b60b58f9 48
f7b1b3b1 49 if (isset($msg['FLAG_FLAGGED']) && ($msg['FLAG_FLAGGED'] == true)) {
d6def997 50 $flag = "<font color=$color[2]>";
51 $flag_end = '</font>';
f7b1b3b1 52 } else {
90bc0b93 53 $flag = '';
6edca885 54 $flag_end = '';
245a6892 55 }
f7b1b3b1 56 if (!isset($msg['FLAG_SEEN']) || ($msg['FLAG_SEEN'] == false)) {
d6def997 57 $bold = '<b>';
58 $bold_end = '</b>';
f7b1b3b1 59 } else {
90bc0b93 60 $bold = '';
6edca885 61 $bold_end = '';
245a6892 62 }
f7b1b3b1 63
64 if (($mailbox == $sent_folder) || ($mailbox == $draft_folder)) {
d6def997 65 $italic = '<i>';
66 $italic_end = '</i>';
f7b1b3b1 67 } else {
90bc0b93 68 $italic = '';
6edca885 69 $italic_end = '';
245a6892 70 }
f7b1b3b1 71
72 if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED']) {
d6def997 73 $fontstr = "<font color=\"$color[9]\">";
74 $fontstr_end = '</font>';
f7b1b3b1 75 } else {
90bc0b93 76 $fontstr = '';
6edca885 77 $fontstr_end = '';
245a6892 78 }
b60b58f9 79
9d157cec 80 for ($i=0; $i < count($message_highlight_list); $i++) {
90bc0b93 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'];
d059be8f 85 continue;
86 }
90bc0b93 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'];
1195c340 89 continue;
b60b58f9 90 }
d059be8f 91 }
b60b58f9 92 }
93
f7b1b3b1 94 if (!isset($hlt_color)) {
95 $hlt_color = $color_string;
96 }
1809bad8 97
98 if ($where && $what) {
90bc0b93 99 $search_stuff = '&where='.urlencode($where).'&what='.urlencode($what);
1809bad8 100 }
66289791 101
f7b1b3b1 102 $checked = ($checkall == 1 ?' checked' : '');
d6def997 103
8e265988 104 for ($i=1; $i <= count($index_order); $i++) {
105 switch ($index_order[$i]) {
f7b1b3b1 106 case 1: /* checkbox */
20cd8abb 107 echo " <td bgcolor=$hlt_color align=center><input type=checkbox name=\"msg[$t]\" value=".$msg["ID"]."$checked></TD>\n";
8e265988 108 break;
f7b1b3b1 109 case 2: /* from */
20cd8abb 110 echo " <td bgcolor=$hlt_color>$italic$bold$flag$fontstr$senderName$fontstr_end$flag_end$bold_end$italic_end</td>\n";
8e265988 111 break;
f7b1b3b1 112 case 3: /* date */
20cd8abb 113 echo " <td nowrap bgcolor=$hlt_color><center>$bold$flag$fontstr".$msg["DATE_STRING"]."$fontstr_end$flag_end$bold_end</center></td>\n";
8e265988 114 break;
f7b1b3b1 115 case 4: /* subject */
7e73c6be 116 echo " <td bgcolor=$hlt_color>$bold";
6edca885 117 if (! isset($search_stuff)) { $search_stuff = ''; }
23d6bd09 118 echo "<a href=\"read_body.php?mailbox=$urlMailbox&passed_id=".$msg["ID"]."&startMessage=$start_msg&show_more=0$search_stuff\"";
23fd3c8e 119 do_hook("subject_link");
77f70304 120
8c16ad63 121 if ($subject != $msg['SUBJECT']) {
feb563a6 122 $title = get_html_translation_table(HTML_SPECIALCHARS);
123 $title = array_flip($title);
124 $title = strtr($msg['SUBJECT'], $title);
125 $title = str_replace('"', "''", $title);
8c16ad63 126 echo " title=\"$title\"";
feb563a6 127 }
128 echo ">$flag$subject$flag_end</a>$bold_end</td>\n";
8e265988 129 break;
f7b1b3b1 130 case 5: /* flags */
9db5f5fc 131 $stuff = false;
20cd8abb 132 echo " <td bgcolor=$hlt_color align=center nowrap><b><small>\n";
d6def997 133 if (isset($msg['FLAG_ANSWERED']) &&
6edca885 134 $msg['FLAG_ANSWERED'] == true) {
9db5f5fc 135 echo "A\n";
136 $stuff = true;
8ae331c2 137 }
90bc0b93 138 if ($msg['TYPE0'] == 'multipart') {
9db5f5fc 139 echo "+\n";
140 $stuff = true;
8ae331c2 141 }
dfec863e 142 if ($default_use_priority) {
020abcf3 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 }
9db5f5fc 151 }
90bc0b93 152 if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED']) {
f9b3e5d9 153 echo "<font color=\"$color[1]\">D</font>\n";
154 $stuff = true;
155 }
8ae331c2 156
9db5f5fc 157 if (!$stuff) echo "&nbsp;\n";
158 echo "</small></b></td>\n";
8e265988 159 break;
f7b1b3b1 160 case 6: /* size */
20cd8abb 161 echo " <td bgcolor=$hlt_color>$bold$fontstr".show_readable_size($msg['SIZE'])."$fontstr_end$bold_end</td>\n";
8e265988 162 break;
163 }
164 }
7151188f 165 echo "</tr>\n";
926da13e 166 }
167
168 /**
f7b1b3b1 169 * This function loops through a group of messages in the mailbox
170 * and shows them to the user.
171 */
172 function showMessagesForMailbox
23d6bd09 173 ($imapConnection, $mailbox, $num_msgs, $start_msg,
f7b1b3b1 174 $sort, $color,$show_num, $use_cache) {
5b6ae78a 175 global $msgs, $msort;
f7b1b3b1 176 global $sent_folder, $draft_folder;
9d157cec 177 global $message_highlight_list;
a3432f47 178 global $auto_expunge;
179
f7b1b3b1 180 /* If autoexpunge is turned on, then do it now. */
181 if ($auto_expunge == true) {
182 sqimap_mailbox_expunge($imapConnection, $mailbox, false);
183 }
0d455368 184 sqimap_mailbox_select($imapConnection, $mailbox);
61a4ac35 185
f7b1b3b1 186 $issent = (($mailbox == $sent_folder) || ($mailbox == $draft_folder));
5b6ae78a 187 if (!$use_cache) {
f7b1b3b1 188 /* If it is sorted... */
23d6bd09 189 if ($num_msgs >= 1) {
0d455368 190 if ($sort < 6) {
23d6bd09 191 $id = range(1, $num_msgs);
0d455368 192 } else {
193 // if it's not sorted
23d6bd09 194 if ($start_msg + ($show_num - 1) < $num_msgs) {
195 $end_msg = $start_msg + ($show_num-1);
0d455368 196 } else {
23d6bd09 197 $end_msg = $num_msgs;
0d455368 198 }
b60b58f9 199
23d6bd09 200 if ($end_msg < $start_msg) {
201 $start_msg = $start_msg - $show_num;
202 if ($start_msg < 1) {
203 $start_msg = 1;
f7b1b3b1 204 }
0d455368 205 }
206
23d6bd09 207 $real_startMessage = $num_msgs - $start_msg + 1;
208 $real_endMessage = $num_msgs - $start_msg - $show_num + 2;
f7b1b3b1 209 if ($real_endMessage <= 0) {
210 $real_endMessage = 1;
211 }
91f68e94 212 $id = array_reverse(range($real_endMessage, $real_startMessage));
213 }
b60b58f9 214
91f68e94 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;
b60b58f9 226 }
5b6ae78a 227 }
b60b58f9 228
5b6ae78a 229 $j = 0;
0d455368 230 if ($sort == 6) {
23d6bd09 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;
f7b1b3b1 236 } else {
237 $end_loop = $show_num;
238 }
0d455368 239 } else {
23d6bd09 240 $end = $num_msgs;
cd928157 241 $end_loop = $end;
0d455368 242 }
f7b1b3b1 243
cd928157 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 }
90bc0b93 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];
e9f8ea4e 264
265 # fix SUBJECT-SORT to remove Re:
0d455368 266 $re_abbr = # Add more here!
90bc0b93 267 'vedr|sv|' . # Danish
268 're|aw'; # English
f1e6f580 269
270 if (eregi( "^($re_abbr):[ ]*(.*)$", $messages[$j]['SUBJECT-SORT'], $regs))
0d455368 271 $messages[$j]['SUBJECT-SORT'] = $regs[2];
b60b58f9 272
5b6ae78a 273 $num = 0;
274 while ($num < count($flags[$j])) {
90bc0b93 275 if ($flags[$j][$num] == 'Deleted') {
f7b1b3b1 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;
5b6ae78a 283 }
284 $num++;
7151188f 285 }
5b6ae78a 286 $j++;
3302d0d4 287 }
f9b3e5d9 288
289 /* Only ignore messages flagged as deleted if we are using a
290 * trash folder or auto_expunge */
d6def997 291 if (((isset($move_to_trash) && $move_to_trash)
f7b1b3b1 292 || (isset($auto_expunge) && $auto_expunge)) && $sort != 6) {
293
f9b3e5d9 294 /** Find and remove the ones that are deleted */
295 $i = 0;
296 $j = 0;
f7b1b3b1 297
23d6bd09 298 while ($j < $num_msgs) {
cd928157 299 if (isset($messages[$j]['FLAG_DELETED']) && $messages[$j]['FLAG_DELETED'] == true) {
f9b3e5d9 300 $j++;
301 continue;
302 }
303 $msgs[$i] = $messages[$j];
b60b58f9 304
f9b3e5d9 305 $i++;
5b6ae78a 306 $j++;
5b6ae78a 307 }
23d6bd09 308 $num_msgs = $i;
0d455368 309 } else {
f7b1b3b1 310 if (!isset($messages)) {
311 $messages = array();
312 }
313 $msgs = $messages;
5b10f02a 314 }
d6def997 315 }
926da13e 316
4c2d69ac 317 // There's gotta be messages in the array for it to sort them.
23d6bd09 318 if ($num_msgs > 0 && ! $use_cache) {
0e919368 319 /** 0 = Date (up) 4 = Subject (up)
320 ** 1 = Date (dn) 5 = Subject (dn)
321 ** 2 = Name (up)
322 ** 3 = Name (dn)
323 **/
09856735 324 session_unregister("msgs");
1c292c82 325 if (($sort == 0) || ($sort == 1))
90bc0b93 326 $msort = array_cleave ($msgs, 'TIME_STAMP');
9b0f85eb 327 elseif (($sort == 2) || ($sort == 3))
90bc0b93 328 $msort = array_cleave ($msgs, 'FROM-SORT');
9b0f85eb 329 elseif (($sort == 4) || ($sort == 5))
90bc0b93 330 $msort = array_cleave ($msgs, 'SUBJECT-SORT');
9b0f85eb 331 else // ($sort == 6)
0d455368 332 $msort = $msgs;
333
334 if ($sort < 6) {
9b0f85eb 335 if ($sort % 2) {
0d455368 336 asort($msort);
337 } else {
338 arsort($msort);
339 }
0e919368 340 }
90bc0b93 341 session_register('msort');
4c2d69ac 342 }
23d6bd09 343 displayMessageArray($imapConnection, $num_msgs, $start_msg, $msgs, $msort, $mailbox, $sort, $color,$show_num);
f7b1b3b1 344 session_register('msgs');
9f2215a1 345 }
346
f7b1b3b1 347 /******************************************************************/
348 /* Generic function to convert the msgs array into an HTML table. */
349 /******************************************************************/
23d6bd09 350 function displayMessageArray($imapConnection, $num_msgs, $start_msg, &$msgs, $msort, $mailbox, $sort, $color, $show_num) {
cbdc5621 351 global $folder_prefix, $sent_folder;
4aaea201 352 global $imapServerAddress, $data_dir, $username, $use_mailbox_cache;
21fafac8 353 global $index_order, $real_endMessage, $real_startMessage, $checkall;
feb563a6 354
f7b1b3b1 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'); }
90033b64 358
23d6bd09 359 if ($start_msg + ($show_num - 1) < $num_msgs) {
360 $end_msg = $start_msg + ($show_num-1);
926da13e 361 } else {
23d6bd09 362 $end_msg = $num_msgs;
926da13e 363 }
b60b58f9 364
23d6bd09 365 if ($end_msg < $start_msg) {
366 $start_msg = $start_msg - $show_num;
367 if ($start_msg < 1) { $start_msg = 1; }
8442ac08 368 }
b60b58f9 369
20db5033 370 $urlMailbox = urlencode($mailbox);
926da13e 371
90bc0b93 372 do_hook('mailbox_index_before');
926da13e 373
23d6bd09 374 $msg_cnt_str = get_msgcnt_str($start_msg, $end_msg, $num_msgs);
1a0e0983 375 $paginator_str = get_paginator_str($urlMailbox, $start_msg, $end_msg, $num_msgs, $show_num, $sort);
26b6c99c 376
23d6bd09 377 if (! isset($msg)) {
378 $msg = '';
14eb705c 379 }
380
23d6bd09 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);
14eb705c 385
23d6bd09 386 $groupNum = $start_msg % ($show_num - 1);
387 $real_startMessage = $start_msg;
b60b58f9 388 if ($sort == 6) {
23d6bd09 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;
b60b58f9 395 }
396 }
23d6bd09 397 $endVar = $end_msg + 1;
b60b58f9 398
23d6bd09 399 /* Loop through and display the info for each message. */
14eb705c 400 $t = 0; // $t is used for the checkbox number
23d6bd09 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);
14eb705c 421 } else {
23d6bd09 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);
14eb705c 439 }
14eb705c 440
1125b3de 441 echo '</table>';
e72fb4f7 442 echo "<table bgcolor=\"$color[9]\" width=100% border=0 cellpadding=1 cellspacing=1>" .
443 "<tr BGCOLOR=\"$color[4]\">" .
23d6bd09 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>".
e72fb4f7 446 "</tr>".
447 "</table>";
a2ae47f7 448 /** End of message-list table */
14eb705c 449
90bc0b93 450 do_hook('mailbox_index_after');
a2ae47f7 451 echo "</TABLE></FORM>\n";
14eb705c 452 }
453
23d6bd09 454 /**
455 * Displays the standard message list header. To finish the table,
456 * you need to do a "</table></table>";
457 *
14eb705c 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 */
f7b1b3b1 464 function mail_message_listing_beginning
465 ($imapConnection, $moveURL, $mailbox = '', $sort = -1,
dfec863e 466 $msg_cnt_str = '', $paginator = '&nbsp;', $start_msg = 1) {
f9b3e5d9 467 global $color, $index_order, $auto_expunge, $move_to_trash;
f7b1b3b1 468 global $checkall, $sent_folder, $draft_folder;
eca500d0 469 $urlMailbox = urlencode($mailbox);
8ae331c2 470
23d6bd09 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";
8ae331c2 476
23d6bd09 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>";
81caa0f3 484
68347a84 485 /** The delete and move options */
23d6bd09 486 echo "<TR><TD BGCOLOR=\"$color[0]\">";
ed4332d1 487
feb563a6 488 echo "\n<FORM name=messageList method=post action=\"$moveURL\">\n";
4f313fcf 489 echo "<TABLE BGCOLOR=\"$color[0]\" COLS=2 BORDER=0 cellpadding=0 cellspacing=0 width=100%>\n";
66289791 490
f1e6f580 491 echo " <TR>\n" .
492 " <TD ALIGN=LEFT VALIGN=CENTER NOWRAP>\n" .
493 ' <SMALL>&nbsp;' . _("Move selected to:") . "</SMALL>\n" .
494 " </TD>\n" .
f1e6f580 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">';
7ce342dc 502
9f2215a1 503 $boxes = sqimap_mailbox_list($imapConnection);
7ce342dc 504 for ($i = 0; $i < count($boxes); $i++) {
cbbdef2a 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";
6edca885 509 }
dd88d31f 510 }
0c6d50f1 511 echo ' </SELECT></TT></SMALL>';
6332704d 512 echo " <SMALL><INPUT TYPE=SUBMIT NAME=\"moveButton\" VALUE=\"" . _("Move") . "\"></SMALL>\n";
ed4332d1 513 echo " </TD>\n";
6332704d 514 echo " <TD ALIGN=RIGHT NOWRAP>&nbsp;&nbsp;&nbsp;\n";
f7b1b3b1 515 if (!$auto_expunge) {
6332704d 516 echo ' <INPUT TYPE=SUBMIT NAME="expungeButton" VALUE="'. _("Expunge") .'">&nbsp;'. _("mailbox") ."&nbsp;\n";
f9b3e5d9 517 }
6332704d 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";
14eb705c 521 echo " </TD>\n";
ed4332d1 522 echo " </TR>\n";
70b455e0 523 echo "</TABLE>\n";
90bc0b93 524 do_hook('mailbox_form_before');
525 echo '</TD></TR>';
aa4c3749 526
f8f9bed9 527 echo "<TR><TD BGCOLOR=\"$color[0]\">";
ac53fb56 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]\">";
f8f9bed9 535 echo "<TR BGCOLOR=\"$color[5]\" ALIGN=\"center\">";
be8e07f8 536
f7b1b3b1 537 /* Print the headers. */
8e265988 538 for ($i=1; $i <= count($index_order); $i++) {
539 switch ($index_order[$i]) {
f7b1b3b1 540 case 1: /* checkbox */
541 case 5: /* flags */
90bc0b93 542 echo ' <TD WIDTH="1%"><B>&nbsp;</B></TD>';
8e265988 543 break;
d6def997 544
f7b1b3b1 545 case 2: /* from */
546 if (($mailbox == $sent_folder)
547 || ($mailbox == $draft_folder)) {
20cd8abb 548 echo ' <TD WIDTH="25%"><B>'. _("To") .'</B>';
f7b1b3b1 549 } else {
550 echo ' <TD WIDTH="25%"><B>'. _("From") .'</B>';
551 }
552
d6def997 553 ShowSortButton($sort, $mailbox, 2, 3);
9b0f85eb 554 echo "</TD>\n";
8e265988 555 break;
d6def997 556
f7b1b3b1 557 case 3: /* date */
20cd8abb 558 echo ' <TD NOWRAP WIDTH="5%"><B>'. _("Date") .'</B>';
d6def997 559 ShowSortButton($sort, $mailbox, 0, 1);
9b0f85eb 560 echo "</TD>\n";
8e265988 561 break;
d6def997 562
f7b1b3b1 563 case 4: /* subject */
9b0f85eb 564 echo ' <TD><B>'. _("Subject") .'</B> ';
d6def997 565 ShowSortButton($sort, $mailbox, 4, 5);
9b0f85eb 566 echo "</TD>\n";
8e265988 567 break;
d6def997 568
f7b1b3b1 569 case 6: /* size */
20cd8abb 570 echo ' <TD WIDTH="5%"><b>' . _("Size")."</b></TD>\n";
8e265988 571 break;
572 }
573 }
14eb705c 574 echo "</TR>\n";
3302d0d4 575 }
d6def997 576
f7b1b3b1 577 /*******************************************************************/
578 /* This function shows the sort button. Isn't this a good comment? */
579 /*******************************************************************/
9b0f85eb 580 function ShowSortButton($sort, $mailbox, $Up, $Down) {
f7b1b3b1 581 /* Figure out which image we want to use. */
9b0f85eb 582 if ($sort != $Up && $sort != $Down) {
583 $img = 'sort_none.gif';
584 $which = $Up;
585 } elseif ($sort == $Up) {
586 $img = 'up_pointer.gif';
d6def997 587 $which = $Down;
9b0f85eb 588 } else {
589 $img = 'down_pointer.gif';
d6def997 590 $which = 6;
9b0f85eb 591 }
f7b1b3b1 592
593 /* Now that we have everything figured out, show the actual button. */
d6def997 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>';
9b0f85eb 598 }
d6def997 599
23d6bd09 600 function get_selectall_link($start_msg, $sort) {
323218d7 601 global $checkall, $PHP_SELF, $what, $where, $mailbox;
5de4de79 602
23d6bd09 603 $result =
604 '&nbsp;<script language="JavaScript">' .
2016e645 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";
0700d853 616
23d6bd09 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);
323218d7 641 }
f93c93b9 642
23d6bd09 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
1a0e0983 665 ($urlMailbox, $start_msg, $end_msg, $num_msgs, $show_num, $sort) {
1fa67a32 666 global $username, $data_dir, $use_mailbox_cache, $color;
1a0e0983 667
23d6bd09 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 <> '') {
743c5f56 689 $lMore .= '&nbsp;|&nbsp;';
23d6bd09 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 }
1fa67a32 701 $start_msg = min( $start_msg, $num_msgs );
1a0e0983 702 $p = intval( $start_msg / $show_num ) + 1;
23d6bd09 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" .
1a0e0983 708 "&mailbox=$urlMailbox\" TARGET=\"right\">$pg</a>&nbsp;";
23d6bd09 709 $i += $k;
710 }
1a0e0983 711 $mMore .= "<B>$p</B>&nbsp;";
23d6bd09 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"
1a0e0983 717 . "&mailbox=$urlMailbox\" TARGET=\"right\">$pg</a>&nbsp;";
23d6bd09 718 $i+=$k;
719 }
1a0e0983 720 $mMore .= '&nbsp;|&nbsp;';
23d6bd09 721 }
722
723 /* Return the resulting string. */
dfec863e 724 if( $lMore . $mMore . $rMore == '' ) {
725 $lMore = '&nbsp;';
726 }
23d6bd09 727 return ($lMore . $mMore . $rMore);
728 }
729
730 function processSubject($subject) {
f93c93b9 731 // Shouldn't ever happen -- caught too many times in the IMAP functions
732 if ($subject == '')
733 return _("(no subject)");
d6def997 734
f93c93b9 735 if (strlen($subject) <= 55)
736 return $subject;
d6def997 737
f93c93b9 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 {
d6def997 748 $trim_val += ($ent_loc_end-$ent_loc)+1;
749 $ent_strlen -= $ent_loc_end-$ent_loc;
750 $ent_offset = $ent_loc_end+1;
f93c93b9 751 }
d6def997 752
f93c93b9 753 if ($ent_strlen <= 55)
754 return $subject;
755
756 return substr($subject, 0, $trim_val) . '...';
757 }
758
e78e7f48 759?>