UI organizing
[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) {
e72fb4f7 377 $Message = sprintf( _("Viewing Messages: <B>%s</B> to <B>%s</B> (%s total)"), $startMessage, $endMessage, $numMessages );
f9b3e5d9 378 } elseif ($startMessage == $endMessage) {
e72fb4f7 379 $Message = sprintf( _("Viewing Message: <B>%s</B> to <B>%s</B> (%s total)"), $startMessage, $endMessage, $numMessages );
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
1125b3de 491 echo '</table>';
e72fb4f7 492 echo "<table bgcolor=\"$color[9]\" width=100% border=0 cellpadding=1 cellspacing=1>" .
493 "<tr BGCOLOR=\"$color[4]\">" .
494 "<table width=100% BGCOLOR=\"$color[4]\" border=0 cellpadding=1 cellspacing=0><tr><td>$lMore$mMore$rMore</td>".
495 "<td align=right>$Message</td></tr></table>".
496 "</tr>".
497 "</table>";
a2ae47f7 498 /** End of message-list table */
14eb705c 499
90bc0b93 500 do_hook('mailbox_index_after');
a2ae47f7 501 echo "</TABLE></FORM>\n";
14eb705c 502 }
503
504 /* Displays the standard message list header.
505 * To finish the table, you need to do a "</table></table>";
506 * $moveURL is the URL to submit the delete/move form to
507 * $mailbox is the current mailbox
508 * $sort is the current sorting method (-1 for no sorting available [searches])
509 * $Message is a message that is centered on top of the list
510 * $More is a second line that is left aligned
511 */
f7b1b3b1 512 function mail_message_listing_beginning
513 ($imapConnection, $moveURL, $mailbox = '', $sort = -1,
514 $Message = '', $More = '', $startMessage = 1) {
f9b3e5d9 515 global $color, $index_order, $auto_expunge, $move_to_trash;
f7b1b3b1 516 global $checkall, $sent_folder, $draft_folder;
eca500d0 517 $urlMailbox = urlencode($mailbox);
8ae331c2 518
6332704d 519 /** This is the beginning of the message list table. It wraps around all messages */
e72fb4f7 520 echo "<center>$Message</center>" .
521 '<TABLE WIDTH="100%" BORDER="0" CELLPADDING="1" CELLSPACING="0">';
8ae331c2 522
e72fb4f7 523 echo "<TR BGCOLOR=\"$color[9]\"><TD>";
926da13e 524
81caa0f3 525 echo "<table bgcolor=\"$color[4]\" cellpadding=2".
526 ' width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td>' .
527 "$More</td><td align=right>";
528 ShowSelectAllLink($startMessage, $sort);
529 echo "</td></tr></table>\n</td></tr>";
530
68347a84 531 /** The delete and move options */
e72fb4f7 532 echo "<TD BGCOLOR=\"$color[0]\">";
ed4332d1 533
feb563a6 534 echo "\n<FORM name=messageList method=post action=\"$moveURL\">\n";
4f313fcf 535 echo "<TABLE BGCOLOR=\"$color[0]\" COLS=2 BORDER=0 cellpadding=0 cellspacing=0 width=100%>\n";
66289791 536
f1e6f580 537 echo " <TR>\n" .
538 " <TD ALIGN=LEFT VALIGN=CENTER NOWRAP>\n" .
539 ' <SMALL>&nbsp;' . _("Move selected to:") . "</SMALL>\n" .
540 " </TD>\n" .
f1e6f580 541 " <TD ALIGN=RIGHT NOWRAP>\n" .
542 ' <SMALL>&nbsp;' . _("Transform Selected Messages") . ": &nbsp; </SMALL><BR>\n" .
543 " </TD>\n" .
544 " </TR>\n" .
545 " <TR>\n" .
546 " <TD ALIGN=LEFT VALIGN=CENTER NOWRAP>\n" .
547 ' <SMALL>&nbsp;<TT><SELECT NAME="targetMailbox">';
7ce342dc 548
9f2215a1 549 $boxes = sqimap_mailbox_list($imapConnection);
7ce342dc 550 for ($i = 0; $i < count($boxes); $i++) {
cbbdef2a 551 if (!in_array("noselect", $boxes[$i]['flags'])) {
90bc0b93 552 $box = $boxes[$i]['unformatted'];
e78e7f48 553 $box2 = str_replace(' ', '&nbsp;', $boxes[$i]['formatted']);
14eb705c 554 echo " <OPTION VALUE=\"$box\">$box2</option>\n";
6edca885 555 }
dd88d31f 556 }
0c6d50f1 557 echo ' </SELECT></TT></SMALL>';
6332704d 558 echo " <SMALL><INPUT TYPE=SUBMIT NAME=\"moveButton\" VALUE=\"" . _("Move") . "\"></SMALL>\n";
ed4332d1 559 echo " </TD>\n";
6332704d 560 echo " <TD ALIGN=RIGHT NOWRAP>&nbsp;&nbsp;&nbsp;\n";
f7b1b3b1 561 if (!$auto_expunge) {
6332704d 562 echo ' <INPUT TYPE=SUBMIT NAME="expungeButton" VALUE="'. _("Expunge") .'">&nbsp;'. _("mailbox") ."&nbsp;\n";
f9b3e5d9 563 }
6332704d 564 echo " <INPUT TYPE=SUBMIT NAME=\"markRead\" VALUE=\"". _("Read")."\">\n";
565 echo " <INPUT TYPE=SUBMIT NAME=\"markUnread\" VALUE=\"". _("Unread")."\">\n";
566 echo " <INPUT TYPE=SUBMIT VALUE=\"". _("Delete") . "\">&nbsp;\n";
14eb705c 567 echo " </TD>\n";
ed4332d1 568 echo " </TR>\n";
70b455e0 569 echo "</TABLE>\n";
90bc0b93 570 do_hook('mailbox_form_before');
571 echo '</TD></TR>';
aa4c3749 572
f8f9bed9 573 echo "<TR><TD BGCOLOR=\"$color[0]\">";
ac53fb56 574 echo "<TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=";
575 if ($GLOBALS['alt_index_colors']) {
576 echo "0";
577 } else {
578 echo "1";
579 }
580 echo " BGCOLOR=\"$color[0]\">";
f8f9bed9 581 echo "<TR BGCOLOR=\"$color[5]\" ALIGN=\"center\">";
be8e07f8 582
f7b1b3b1 583 /* Print the headers. */
8e265988 584 for ($i=1; $i <= count($index_order); $i++) {
585 switch ($index_order[$i]) {
f7b1b3b1 586 case 1: /* checkbox */
587 case 5: /* flags */
90bc0b93 588 echo ' <TD WIDTH="1%"><B>&nbsp;</B></TD>';
8e265988 589 break;
d6def997 590
f7b1b3b1 591 case 2: /* from */
592 if (($mailbox == $sent_folder)
593 || ($mailbox == $draft_folder)) {
20cd8abb 594 echo ' <TD WIDTH="25%"><B>'. _("To") .'</B>';
f7b1b3b1 595 } else {
596 echo ' <TD WIDTH="25%"><B>'. _("From") .'</B>';
597 }
598
d6def997 599 ShowSortButton($sort, $mailbox, 2, 3);
9b0f85eb 600 echo "</TD>\n";
8e265988 601 break;
d6def997 602
f7b1b3b1 603 case 3: /* date */
20cd8abb 604 echo ' <TD NOWRAP WIDTH="5%"><B>'. _("Date") .'</B>';
d6def997 605 ShowSortButton($sort, $mailbox, 0, 1);
9b0f85eb 606 echo "</TD>\n";
8e265988 607 break;
d6def997 608
f7b1b3b1 609 case 4: /* subject */
9b0f85eb 610 echo ' <TD><B>'. _("Subject") .'</B> ';
d6def997 611 ShowSortButton($sort, $mailbox, 4, 5);
9b0f85eb 612 echo "</TD>\n";
8e265988 613 break;
d6def997 614
f7b1b3b1 615 case 6: /* size */
20cd8abb 616 echo ' <TD WIDTH="5%"><b>' . _("Size")."</b></TD>\n";
8e265988 617 break;
618 }
619 }
14eb705c 620 echo "</TR>\n";
3302d0d4 621 }
d6def997 622
f7b1b3b1 623 /*******************************************************************/
624 /* This function shows the sort button. Isn't this a good comment? */
625 /*******************************************************************/
9b0f85eb 626 function ShowSortButton($sort, $mailbox, $Up, $Down) {
f7b1b3b1 627 /* Figure out which image we want to use. */
9b0f85eb 628 if ($sort != $Up && $sort != $Down) {
629 $img = 'sort_none.gif';
630 $which = $Up;
631 } elseif ($sort == $Up) {
632 $img = 'up_pointer.gif';
d6def997 633 $which = $Down;
9b0f85eb 634 } else {
635 $img = 'down_pointer.gif';
d6def997 636 $which = 6;
9b0f85eb 637 }
f7b1b3b1 638
639 /* Now that we have everything figured out, show the actual button. */
d6def997 640 echo ' <a href="right_main.php?newsort=' . $which .
641 '&startMessage=1&mailbox=' . urlencode($mailbox) .
642 '"><IMG SRC="../images/' . $img .
643 '" BORDER=0 WIDTH=12 HEIGHT=10></a>';
9b0f85eb 644 }
d6def997 645
f7b1b3b1 646 function ShowSelectAllLink($startMessage, $sort) {
323218d7 647 global $checkall, $PHP_SELF, $what, $where, $mailbox;
5de4de79 648
2016e645 649 echo '&nbsp;<script language="JavaScript">' .
650 "\n<!-- \n" .
651 "function CheckAll() {\n" .
652 " for (var i = 0; i < document.messageList.elements.length; i++) {\n" .
653 " if( document.messageList.elements[i].type == 'checkbox' ) {\n" .
654 " document.messageList.elements[i].checked = !(document.messageList.elements[i].checked);\n".
655 " }\n" .
656 " }\n" .
657 "}\n" .
658 'window.document.write(\'<a href=# onClick="CheckAll();">' . _("Toggle All") . "</a>');\n" .
659 "//-->\n" .
660 "</script>\n<noscript>\n";
0700d853 661
662 echo "<a href=\"$PHP_SELF?mailbox=" . urlencode($mailbox) .
663 "&startMessage=$startMessage&sort=$sort&checkall=";
7b0485a6 664 if (isset($checkall) && $checkall == '1')
665 echo '0';
323218d7 666 else
7b0485a6 667 echo '1';
323218d7 668 if (isset($where) && isset($what))
7b0485a6 669 echo '&where=' . urlencode($where) . '&what=' . urlencode($what);
323218d7 670 echo "\">";
671 if (isset($checkall) && $checkall == '1')
672 echo _("Unselect All");
673 else
674 echo _("Select All");
d6def997 675
5de4de79 676 echo "</A>\n</noscript>\n";
323218d7 677 }
f93c93b9 678
679 function processSubject($subject)
680 {
681 // Shouldn't ever happen -- caught too many times in the IMAP functions
682 if ($subject == '')
683 return _("(no subject)");
d6def997 684
f93c93b9 685 if (strlen($subject) <= 55)
686 return $subject;
d6def997 687
f93c93b9 688 $ent_strlen=strlen($subject);
689 $trim_val=50;
690 $ent_offset=0;
691 // see if this is entities-encoded string
692 // If so, Iterate through the whole string, find out
693 // the real number of characters, and if more
694 // than 55, substr with an updated trim value.
695 while (($ent_loc = strpos($subject, '&', $ent_offset)) !== false &&
696 ($ent_loc_end = strpos($subject, ';', $ent_loc)) !== false)
697 {
d6def997 698 $trim_val += ($ent_loc_end-$ent_loc)+1;
699 $ent_strlen -= $ent_loc_end-$ent_loc;
700 $ent_offset = $ent_loc_end+1;
f93c93b9 701 }
d6def997 702
f93c93b9 703 if ($ent_strlen <= 55)
704 return $subject;
705
706 return substr($subject, 0, $trim_val) . '...';
707 }
708
e78e7f48 709?>