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