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