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