Fixed typo.
[squirrelmail.git] / functions / mailbox_display.php
CommitLineData
59177427 1<?php
2ba13803 2
35586184 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 */
a4c2cd49 14
35586184 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/*****************************************************************/
f1e6f580 30
35586184 31define('PG_SEL_MAX', 10); /* Default value for page_selector_max. */
32
33function printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $start_msg, $where, $what) {
66289791 34 global $checkall;
af9404d7 35 global $color, $msgs, $msort;
f7b1b3b1 36 global $sent_folder, $draft_folder;
020abcf3 37 global $default_use_priority;
9d157cec 38 global $message_highlight_list;
8e265988 39 global $index_order;
cbdc5621 40
ac53fb56 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) {
f136c965 48 if (!isset($color[12])) $color[12] = '#EAEAEA';
ac53fb56 49 $color_string = $color[12];
50 }
b3b103cb 51 }
0d455368 52 $msg = $msgs[$key];
d92b6f31 53
3dd96399 54 $senderName = htmlspecialchars(sqimap_find_displayable_name($msg['FROM']));
2d367c68 55 if( $mailbox == 'None' ) {
f136c965 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 );
d6def997 61 }
05207a68 62 $urlMailbox = urlencode($mailbox);
f93c93b9 63 $subject = processSubject($msg['SUBJECT']);
926da13e 64 echo "<TR>\n";
b60b58f9 65
f7b1b3b1 66 if (isset($msg['FLAG_FLAGGED']) && ($msg['FLAG_FLAGGED'] == true)) {
d6def997 67 $flag = "<font color=$color[2]>";
68 $flag_end = '</font>';
f7b1b3b1 69 } else {
90bc0b93 70 $flag = '';
6edca885 71 $flag_end = '';
245a6892 72 }
f7b1b3b1 73 if (!isset($msg['FLAG_SEEN']) || ($msg['FLAG_SEEN'] == false)) {
d6def997 74 $bold = '<b>';
75 $bold_end = '</b>';
f7b1b3b1 76 } else {
90bc0b93 77 $bold = '';
6edca885 78 $bold_end = '';
245a6892 79 }
f7b1b3b1 80
81 if (($mailbox == $sent_folder) || ($mailbox == $draft_folder)) {
d6def997 82 $italic = '<i>';
83 $italic_end = '</i>';
f7b1b3b1 84 } else {
90bc0b93 85 $italic = '';
6edca885 86 $italic_end = '';
245a6892 87 }
f7b1b3b1 88
89 if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED']) {
d6def997 90 $fontstr = "<font color=\"$color[9]\">";
91 $fontstr_end = '</font>';
f7b1b3b1 92 } else {
90bc0b93 93 $fontstr = '';
6edca885 94 $fontstr_end = '';
245a6892 95 }
b60b58f9 96
9d157cec 97 for ($i=0; $i < count($message_highlight_list); $i++) {
90bc0b93 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'];
d059be8f 102 continue;
103 }
90bc0b93 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'];
1195c340 106 continue;
b60b58f9 107 }
d059be8f 108 }
b60b58f9 109 }
110
f7b1b3b1 111 if (!isset($hlt_color)) {
112 $hlt_color = $color_string;
113 }
1809bad8 114
115 if ($where && $what) {
90bc0b93 116 $search_stuff = '&where='.urlencode($where).'&what='.urlencode($what);
1809bad8 117 }
66289791 118
f7b1b3b1 119 $checked = ($checkall == 1 ?' checked' : '');
d6def997 120
8e265988 121 for ($i=1; $i <= count($index_order); $i++) {
122 switch ($index_order[$i]) {
f7b1b3b1 123 case 1: /* checkbox */
20cd8abb 124 echo " <td bgcolor=$hlt_color align=center><input type=checkbox name=\"msg[$t]\" value=".$msg["ID"]."$checked></TD>\n";
8e265988 125 break;
f7b1b3b1 126 case 2: /* from */
20cd8abb 127 echo " <td bgcolor=$hlt_color>$italic$bold$flag$fontstr$senderName$fontstr_end$flag_end$bold_end$italic_end</td>\n";
8e265988 128 break;
f7b1b3b1 129 case 3: /* date */
20cd8abb 130 echo " <td nowrap bgcolor=$hlt_color><center>$bold$flag$fontstr".$msg["DATE_STRING"]."$fontstr_end$flag_end$bold_end</center></td>\n";
8e265988 131 break;
f7b1b3b1 132 case 4: /* subject */
7e73c6be 133 echo " <td bgcolor=$hlt_color>$bold";
6edca885 134 if (! isset($search_stuff)) { $search_stuff = ''; }
23d6bd09 135 echo "<a href=\"read_body.php?mailbox=$urlMailbox&passed_id=".$msg["ID"]."&startMessage=$start_msg&show_more=0$search_stuff\"";
23fd3c8e 136 do_hook("subject_link");
77f70304 137
8c16ad63 138 if ($subject != $msg['SUBJECT']) {
feb563a6 139 $title = get_html_translation_table(HTML_SPECIALCHARS);
140 $title = array_flip($title);
141 $title = strtr($msg['SUBJECT'], $title);
142 $title = str_replace('"', "''", $title);
8c16ad63 143 echo " title=\"$title\"";
feb563a6 144 }
145 echo ">$flag$subject$flag_end</a>$bold_end</td>\n";
8e265988 146 break;
f7b1b3b1 147 case 5: /* flags */
9db5f5fc 148 $stuff = false;
20cd8abb 149 echo " <td bgcolor=$hlt_color align=center nowrap><b><small>\n";
d6def997 150 if (isset($msg['FLAG_ANSWERED']) &&
6edca885 151 $msg['FLAG_ANSWERED'] == true) {
9db5f5fc 152 echo "A\n";
153 $stuff = true;
8ae331c2 154 }
90bc0b93 155 if ($msg['TYPE0'] == 'multipart') {
9db5f5fc 156 echo "+\n";
157 $stuff = true;
8ae331c2 158 }
dfec863e 159 if ($default_use_priority) {
020abcf3 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 }
9db5f5fc 168 }
90bc0b93 169 if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED']) {
f9b3e5d9 170 echo "<font color=\"$color[1]\">D</font>\n";
171 $stuff = true;
172 }
8ae331c2 173
9db5f5fc 174 if (!$stuff) echo "&nbsp;\n";
175 echo "</small></b></td>\n";
8e265988 176 break;
f7b1b3b1 177 case 6: /* size */
20cd8abb 178 echo " <td bgcolor=$hlt_color>$bold$fontstr".show_readable_size($msg['SIZE'])."$fontstr_end$bold_end</td>\n";
8e265988 179 break;
180 }
181 }
7151188f 182 echo "</tr>\n";
926da13e 183 }
184
185 /**
f7b1b3b1 186 * This function loops through a group of messages in the mailbox
187 * and shows them to the user.
188 */
189 function showMessagesForMailbox
23d6bd09 190 ($imapConnection, $mailbox, $num_msgs, $start_msg,
f7b1b3b1 191 $sort, $color,$show_num, $use_cache) {
5b6ae78a 192 global $msgs, $msort;
f7b1b3b1 193 global $sent_folder, $draft_folder;
9d157cec 194 global $message_highlight_list;
a3432f47 195 global $auto_expunge;
196
f7b1b3b1 197 /* If autoexpunge is turned on, then do it now. */
198 if ($auto_expunge == true) {
199 sqimap_mailbox_expunge($imapConnection, $mailbox, false);
200 }
0d455368 201 sqimap_mailbox_select($imapConnection, $mailbox);
61a4ac35 202
f7b1b3b1 203 $issent = (($mailbox == $sent_folder) || ($mailbox == $draft_folder));
5b6ae78a 204 if (!$use_cache) {
f7b1b3b1 205 /* If it is sorted... */
23d6bd09 206 if ($num_msgs >= 1) {
0d455368 207 if ($sort < 6) {
23d6bd09 208 $id = range(1, $num_msgs);
0d455368 209 } else {
210 // if it's not sorted
23d6bd09 211 if ($start_msg + ($show_num - 1) < $num_msgs) {
212 $end_msg = $start_msg + ($show_num-1);
0d455368 213 } else {
23d6bd09 214 $end_msg = $num_msgs;
0d455368 215 }
b60b58f9 216
23d6bd09 217 if ($end_msg < $start_msg) {
218 $start_msg = $start_msg - $show_num;
219 if ($start_msg < 1) {
220 $start_msg = 1;
f7b1b3b1 221 }
0d455368 222 }
223
23d6bd09 224 $real_startMessage = $num_msgs - $start_msg + 1;
225 $real_endMessage = $num_msgs - $start_msg - $show_num + 2;
f7b1b3b1 226 if ($real_endMessage <= 0) {
227 $real_endMessage = 1;
228 }
91f68e94 229 $id = array_reverse(range($real_endMessage, $real_startMessage));
230 }
b60b58f9 231
91f68e94 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;
b60b58f9 243 }
5b6ae78a 244 }
b60b58f9 245
5b6ae78a 246 $j = 0;
0d455368 247 if ($sort == 6) {
23d6bd09 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;
f7b1b3b1 253 } else {
254 $end_loop = $show_num;
255 }
0d455368 256 } else {
23d6bd09 257 $end = $num_msgs;
cd928157 258 $end_loop = $end;
0d455368 259 }
f7b1b3b1 260
cd928157 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 }
90bc0b93 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];
e9f8ea4e 281
282 # fix SUBJECT-SORT to remove Re:
0d455368 283 $re_abbr = # Add more here!
90bc0b93 284 'vedr|sv|' . # Danish
285 're|aw'; # English
f1e6f580 286
287 if (eregi( "^($re_abbr):[ ]*(.*)$", $messages[$j]['SUBJECT-SORT'], $regs))
0d455368 288 $messages[$j]['SUBJECT-SORT'] = $regs[2];
b60b58f9 289
5b6ae78a 290 $num = 0;
291 while ($num < count($flags[$j])) {
90bc0b93 292 if ($flags[$j][$num] == 'Deleted') {
f7b1b3b1 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;
5b6ae78a 300 }
301 $num++;
7151188f 302 }
5b6ae78a 303 $j++;
3302d0d4 304 }
f9b3e5d9 305
306 /* Only ignore messages flagged as deleted if we are using a
307 * trash folder or auto_expunge */
d6def997 308 if (((isset($move_to_trash) && $move_to_trash)
f7b1b3b1 309 || (isset($auto_expunge) && $auto_expunge)) && $sort != 6) {
310
f9b3e5d9 311 /** Find and remove the ones that are deleted */
312 $i = 0;
313 $j = 0;
f7b1b3b1 314
23d6bd09 315 while ($j < $num_msgs) {
cd928157 316 if (isset($messages[$j]['FLAG_DELETED']) && $messages[$j]['FLAG_DELETED'] == true) {
f9b3e5d9 317 $j++;
318 continue;
319 }
320 $msgs[$i] = $messages[$j];
b60b58f9 321
f9b3e5d9 322 $i++;
5b6ae78a 323 $j++;
5b6ae78a 324 }
23d6bd09 325 $num_msgs = $i;
0d455368 326 } else {
f7b1b3b1 327 if (!isset($messages)) {
328 $messages = array();
329 }
330 $msgs = $messages;
5b10f02a 331 }
d6def997 332 }
926da13e 333
4c2d69ac 334 // There's gotta be messages in the array for it to sort them.
23d6bd09 335 if ($num_msgs > 0 && ! $use_cache) {
0e919368 336 /** 0 = Date (up) 4 = Subject (up)
337 ** 1 = Date (dn) 5 = Subject (dn)
338 ** 2 = Name (up)
339 ** 3 = Name (dn)
340 **/
09856735 341 session_unregister("msgs");
1c292c82 342 if (($sort == 0) || ($sort == 1))
90bc0b93 343 $msort = array_cleave ($msgs, 'TIME_STAMP');
9b0f85eb 344 elseif (($sort == 2) || ($sort == 3))
90bc0b93 345 $msort = array_cleave ($msgs, 'FROM-SORT');
9b0f85eb 346 elseif (($sort == 4) || ($sort == 5))
90bc0b93 347 $msort = array_cleave ($msgs, 'SUBJECT-SORT');
9b0f85eb 348 else // ($sort == 6)
0d455368 349 $msort = $msgs;
350
351 if ($sort < 6) {
9b0f85eb 352 if ($sort % 2) {
0d455368 353 asort($msort);
354 } else {
355 arsort($msort);
356 }
0e919368 357 }
90bc0b93 358 session_register('msort');
4c2d69ac 359 }
23d6bd09 360 displayMessageArray($imapConnection, $num_msgs, $start_msg, $msgs, $msort, $mailbox, $sort, $color,$show_num);
f7b1b3b1 361 session_register('msgs');
9f2215a1 362 }
363
f7b1b3b1 364 /******************************************************************/
365 /* Generic function to convert the msgs array into an HTML table. */
366 /******************************************************************/
23d6bd09 367 function displayMessageArray($imapConnection, $num_msgs, $start_msg, &$msgs, $msort, $mailbox, $sort, $color, $show_num) {
cbdc5621 368 global $folder_prefix, $sent_folder;
4aaea201 369 global $imapServerAddress, $data_dir, $username, $use_mailbox_cache;
21fafac8 370 global $index_order, $real_endMessage, $real_startMessage, $checkall;
feb563a6 371
f7b1b3b1 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'); }
90033b64 375
23d6bd09 376 if ($start_msg + ($show_num - 1) < $num_msgs) {
377 $end_msg = $start_msg + ($show_num-1);
926da13e 378 } else {
23d6bd09 379 $end_msg = $num_msgs;
926da13e 380 }
b60b58f9 381
23d6bd09 382 if ($end_msg < $start_msg) {
383 $start_msg = $start_msg - $show_num;
384 if ($start_msg < 1) { $start_msg = 1; }
8442ac08 385 }
b60b58f9 386
20db5033 387 $urlMailbox = urlencode($mailbox);
926da13e 388
90bc0b93 389 do_hook('mailbox_index_before');
926da13e 390
23d6bd09 391 $msg_cnt_str = get_msgcnt_str($start_msg, $end_msg, $num_msgs);
1a0e0983 392 $paginator_str = get_paginator_str($urlMailbox, $start_msg, $end_msg, $num_msgs, $show_num, $sort);
26b6c99c 393
23d6bd09 394 if (! isset($msg)) {
395 $msg = '';
14eb705c 396 }
397
23d6bd09 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);
14eb705c 402
23d6bd09 403 $groupNum = $start_msg % ($show_num - 1);
404 $real_startMessage = $start_msg;
b60b58f9 405 if ($sort == 6) {
23d6bd09 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;
b60b58f9 412 }
413 }
23d6bd09 414 $endVar = $end_msg + 1;
b60b58f9 415
23d6bd09 416 /* Loop through and display the info for each message. */
14eb705c 417 $t = 0; // $t is used for the checkbox number
23d6bd09 418 if ($num_msgs == 0) { // if there's no messages in this folder
2ba13803 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>";
23d6bd09 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);
14eb705c 438 } else {
23d6bd09 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);
14eb705c 456 }
14eb705c 457
2ba13803 458 echo '</table>'.
459 "<table bgcolor=\"$color[9]\" width=100% border=0 cellpadding=1 cellspacing=1>" .
e72fb4f7 460 "<tr BGCOLOR=\"$color[4]\">" .
23d6bd09 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>".
e72fb4f7 463 "</tr>".
464 "</table>";
a2ae47f7 465 /** End of message-list table */
14eb705c 466
90bc0b93 467 do_hook('mailbox_index_after');
a2ae47f7 468 echo "</TABLE></FORM>\n";
14eb705c 469 }
470
23d6bd09 471 /**
472 * Displays the standard message list header. To finish the table,
473 * you need to do a "</table></table>";
474 *
14eb705c 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 */
f7b1b3b1 481 function mail_message_listing_beginning
482 ($imapConnection, $moveURL, $mailbox = '', $sort = -1,
dfec863e 483 $msg_cnt_str = '', $paginator = '&nbsp;', $start_msg = 1) {
f9b3e5d9 484 global $color, $index_order, $auto_expunge, $move_to_trash;
f7b1b3b1 485 global $checkall, $sent_folder, $draft_folder;
eca500d0 486 $urlMailbox = urlencode($mailbox);
8ae331c2 487
23d6bd09 488 /****************************************************
489 * This is the beginning of the message list table. *
490 * It wraps around all messages *
491 ****************************************************/
2ba13803 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".
6dc0e464 502 "<TABLE BGCOLOR=\"$color[0]\" COLS=2 BORDER=0 cellpadding=0 cellspacing=0 width=\"100%\">\n".
2ba13803 503 " <TR>\n" .
f1e6f580 504 " <TD ALIGN=LEFT VALIGN=CENTER NOWRAP>\n" .
505 ' <SMALL>&nbsp;' . _("Move selected to:") . "</SMALL>\n" .
506 " </TD>\n" .
f1e6f580 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">';
7ce342dc 514
9f2215a1 515 $boxes = sqimap_mailbox_list($imapConnection);
7ce342dc 516 for ($i = 0; $i < count($boxes); $i++) {
cbbdef2a 517 if (!in_array("noselect", $boxes[$i]['flags'])) {
90bc0b93 518 $box = $boxes[$i]['unformatted'];
3b7e638f 519 $box2 = str_replace(' ', '&nbsp;', $boxes[$i]['unformatted-disp']);
14eb705c 520 echo " <OPTION VALUE=\"$box\">$box2</option>\n";
6edca885 521 }
dd88d31f 522 }
2ba13803 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";
f7b1b3b1 527 if (!$auto_expunge) {
6332704d 528 echo ' <INPUT TYPE=SUBMIT NAME="expungeButton" VALUE="'. _("Expunge") .'">&nbsp;'. _("mailbox") ."&nbsp;\n";
f9b3e5d9 529 }
2ba13803 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";
90bc0b93 536 do_hook('mailbox_form_before');
2ba13803 537 echo '</TD></TR>'.
aa4c3749 538
2ba13803 539 "<TR><TD BGCOLOR=\"$color[0]\">".
540 "<TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=";
ac53fb56 541 if ($GLOBALS['alt_index_colors']) {
542 echo "0";
543 } else {
544 echo "1";
545 }
2ba13803 546 echo " BGCOLOR=\"$color[0]\">".
547 "<TR BGCOLOR=\"$color[5]\" ALIGN=\"center\">";
be8e07f8 548
f7b1b3b1 549 /* Print the headers. */
8e265988 550 for ($i=1; $i <= count($index_order); $i++) {
551 switch ($index_order[$i]) {
f7b1b3b1 552 case 1: /* checkbox */
553 case 5: /* flags */
90bc0b93 554 echo ' <TD WIDTH="1%"><B>&nbsp;</B></TD>';
8e265988 555 break;
d6def997 556
f7b1b3b1 557 case 2: /* from */
558 if (($mailbox == $sent_folder)
559 || ($mailbox == $draft_folder)) {
20cd8abb 560 echo ' <TD WIDTH="25%"><B>'. _("To") .'</B>';
f7b1b3b1 561 } else {
562 echo ' <TD WIDTH="25%"><B>'. _("From") .'</B>';
563 }
564
2ba13803 565 ShowSortButton($sort, $mailbox, 2, 3);
9b0f85eb 566 echo "</TD>\n";
8e265988 567 break;
d6def997 568
f7b1b3b1 569 case 3: /* date */
20cd8abb 570 echo ' <TD NOWRAP WIDTH="5%"><B>'. _("Date") .'</B>';
d6def997 571 ShowSortButton($sort, $mailbox, 0, 1);
9b0f85eb 572 echo "</TD>\n";
8e265988 573 break;
d6def997 574
f7b1b3b1 575 case 4: /* subject */
9b0f85eb 576 echo ' <TD><B>'. _("Subject") .'</B> ';
d6def997 577 ShowSortButton($sort, $mailbox, 4, 5);
9b0f85eb 578 echo "</TD>\n";
8e265988 579 break;
d6def997 580
f7b1b3b1 581 case 6: /* size */
20cd8abb 582 echo ' <TD WIDTH="5%"><b>' . _("Size")."</b></TD>\n";
8e265988 583 break;
584 }
585 }
14eb705c 586 echo "</TR>\n";
3302d0d4 587 }
d6def997 588
f7b1b3b1 589 /*******************************************************************/
590 /* This function shows the sort button. Isn't this a good comment? */
591 /*******************************************************************/
9b0f85eb 592 function ShowSortButton($sort, $mailbox, $Up, $Down) {
f7b1b3b1 593 /* Figure out which image we want to use. */
9b0f85eb 594 if ($sort != $Up && $sort != $Down) {
595 $img = 'sort_none.gif';
596 $which = $Up;
597 } elseif ($sort == $Up) {
598 $img = 'up_pointer.gif';
d6def997 599 $which = $Down;
9b0f85eb 600 } else {
601 $img = 'down_pointer.gif';
d6def997 602 $which = 6;
9b0f85eb 603 }
f7b1b3b1 604
605 /* Now that we have everything figured out, show the actual button. */
d6def997 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>';
9b0f85eb 610 }
d6def997 611
23d6bd09 612 function get_selectall_link($start_msg, $sort) {
c57b0888 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";
23d6bd09 628 } else {
c57b0888 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";
23d6bd09 651 }
652
23d6bd09 653 /* Return our final result. */
654 return ($result);
323218d7 655 }
f93c93b9 656
23d6bd09 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
1a0e0983 679 ($urlMailbox, $start_msg, $end_msg, $num_msgs, $show_num, $sort) {
1fa67a32 680 global $username, $data_dir, $use_mailbox_cache, $color;
1a0e0983 681
23d6bd09 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 <> '') {
743c5f56 703 $lMore .= '&nbsp;|&nbsp;';
23d6bd09 704 }
705
706 /* Page selector block. Following code computes page links. */
707 $mMore = '';
c5a9e036 708 if (getPref($data_dir, $username, 'page_selector')
23d6bd09 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 }
1fa67a32 715 $start_msg = min( $start_msg, $num_msgs );
1a0e0983 716 $p = intval( $start_msg / $show_num ) + 1;
23d6bd09 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" .
1a0e0983 722 "&mailbox=$urlMailbox\" TARGET=\"right\">$pg</a>&nbsp;";
23d6bd09 723 $i += $k;
724 }
1a0e0983 725 $mMore .= "<B>$p</B>&nbsp;";
23d6bd09 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"
1a0e0983 731 . "&mailbox=$urlMailbox\" TARGET=\"right\">$pg</a>&nbsp;";
23d6bd09 732 $i+=$k;
733 }
1a0e0983 734 $mMore .= '&nbsp;|&nbsp;';
23d6bd09 735 }
736
737 /* Return the resulting string. */
dfec863e 738 if( $lMore . $mMore . $rMore == '' ) {
739 $lMore = '&nbsp;';
740 }
23d6bd09 741 return ($lMore . $mMore . $rMore);
742 }
743
744 function processSubject($subject) {
f93c93b9 745 // Shouldn't ever happen -- caught too many times in the IMAP functions
746 if ($subject == '')
747 return _("(no subject)");
d6def997 748
f93c93b9 749 if (strlen($subject) <= 55)
750 return $subject;
d6def997 751
f93c93b9 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 {
d6def997 762 $trim_val += ($ent_loc_end-$ent_loc)+1;
763 $ent_strlen -= $ent_loc_end-$ent_loc;
764 $ent_offset = $ent_loc_end+1;
f93c93b9 765 }
d6def997 766
f93c93b9 767 if ($ent_strlen <= 55)
768 return $subject;
769
770 return substr($subject, 0, $trim_val) . '...';
771 }
772
c57b0888 773?>