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