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