53ff3087a4b2aa1a8070d0f46272dec2b1bc64e0
[squirrelmail.git] / functions / mailbox_display.php
1 <?php
2
3 /**
4 ** mailbox_display.php
5 **
6 ** This contains functions that display mailbox information, such as the
7 ** table row that has sender, date, subject, etc...
8 **
9 ** $Id$
10 **/
11
12 if (defined('mailbox_display_php'))
13 return;
14 define('mailbox_display_php', true);
15
16 define('PG_SEL_MAX', 10); /* Default value for page_selector_max. */
17
18 function printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $startMessage, $where, $what) {
19 global $checkall;
20 global $color, $msgs, $msort;
21 global $sent_folder, $draft_folder;
22 global $message_highlight_list;
23 global $index_order;
24
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) {
32 if (!isset($color[12])) $color[12] = '#EAEAEA';
33 $color_string = $color[12];
34 }
35 }
36 $msg = $msgs[$key];
37
38 $senderName = sqimap_find_displayable_name($msg['FROM']);
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 );
45 }
46 $urlMailbox = urlencode($mailbox);
47 $subject = processSubject($msg['SUBJECT']);
48 echo "<TR>\n";
49
50 if (isset($msg['FLAG_FLAGGED']) && ($msg['FLAG_FLAGGED'] == true)) {
51 $flag = "<font color=$color[2]>";
52 $flag_end = '</font>';
53 } else {
54 $flag = '';
55 $flag_end = '';
56 }
57 if (!isset($msg['FLAG_SEEN']) || ($msg['FLAG_SEEN'] == false)) {
58 $bold = '<b>';
59 $bold_end = '</b>';
60 } else {
61 $bold = '';
62 $bold_end = '';
63 }
64
65 if (($mailbox == $sent_folder) || ($mailbox == $draft_folder)) {
66 $italic = '<i>';
67 $italic_end = '</i>';
68 } else {
69 $italic = '';
70 $italic_end = '';
71 }
72
73 if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED']) {
74 $fontstr = "<font color=\"$color[9]\">";
75 $fontstr_end = '</font>';
76 } else {
77 $fontstr = '';
78 $fontstr_end = '';
79 }
80
81 for ($i=0; $i < count($message_highlight_list); $i++) {
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'];
86 continue;
87 }
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'];
90 continue;
91 }
92 }
93 }
94
95 if (!isset($hlt_color)) {
96 $hlt_color = $color_string;
97 }
98
99 if ($where && $what) {
100 $search_stuff = '&where='.urlencode($where).'&what='.urlencode($what);
101 }
102
103 $checked = ($checkall == 1 ?' checked' : '');
104
105 for ($i=1; $i <= count($index_order); $i++) {
106 switch ($index_order[$i]) {
107 case 1: /* checkbox */
108 echo " <td bgcolor=$hlt_color align=center><input type=checkbox name=\"msg[$t]\" value=".$msg["ID"]."$checked></TD>\n";
109 break;
110 case 2: /* from */
111 echo " <td bgcolor=$hlt_color>$italic$bold$flag$fontstr$senderName$fontstr_end$flag_end$bold_end$italic_end</td>\n";
112 break;
113 case 3: /* date */
114 echo " <td nowrap bgcolor=$hlt_color><center>$bold$flag$fontstr".$msg["DATE_STRING"]."$fontstr_end$flag_end$bold_end</center></td>\n";
115 break;
116 case 4: /* subject */
117 echo " <td bgcolor=$hlt_color>$bold";
118 if (! isset($search_stuff)) { $search_stuff = ''; }
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");
121
122 if ($subject != $msg['SUBJECT']) {
123 $title = get_html_translation_table(HTML_SPECIALCHARS);
124 $title = array_flip($title);
125 $title = strtr($msg['SUBJECT'], $title);
126 $title = str_replace('"', "''", $title);
127 echo " title=\"$title\"";
128 }
129 echo ">$flag$subject$flag_end</a>$bold_end</td>\n";
130 break;
131 case 5: /* flags */
132 $stuff = false;
133 echo " <td bgcolor=$hlt_color align=center nowrap><b><small>\n";
134 if (isset($msg['FLAG_ANSWERED']) &&
135 $msg['FLAG_ANSWERED'] == true) {
136 echo "A\n";
137 $stuff = true;
138 }
139 if (ereg('(5)',substr($msg['PRIORITY'],0,1))) {
140 echo "<font color=$color[8]>v</font>\n";
141 $stuff = true;
142 }
143 if ($msg['TYPE0'] == 'multipart') {
144 echo "+\n";
145 $stuff = true;
146 }
147 if (ereg('(1|2)',substr($msg['PRIORITY'],0,1))) {
148 echo "<font color=$color[1]>!</font>\n";
149 $stuff = true;
150 }
151 if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED']) {
152 echo "<font color=\"$color[1]\">D</font>\n";
153 $stuff = true;
154 }
155
156 if (!$stuff) echo "&nbsp;\n";
157 echo "</small></b></td>\n";
158 break;
159 case 6: /* size */
160 echo " <td bgcolor=$hlt_color>$bold$fontstr".show_readable_size($msg['SIZE'])."$fontstr_end$bold_end</td>\n";
161 break;
162 }
163 }
164 echo "</tr>\n";
165 }
166
167 /**
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) {
174 global $msgs, $msort;
175 global $sent_folder, $draft_folder;
176 global $message_highlight_list;
177 global $auto_expunge;
178
179 /* If autoexpunge is turned on, then do it now. */
180 if ($auto_expunge == true) {
181 sqimap_mailbox_expunge($imapConnection, $mailbox, false);
182 }
183 sqimap_mailbox_select($imapConnection, $mailbox);
184
185 $issent = (($mailbox == $sent_folder) || ($mailbox == $draft_folder));
186 if (!$use_cache) {
187 /* If it is sorted... */
188 if ($numMessages >= 1) {
189 if ($sort < 6) {
190 $id = range(1, $numMessages);
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 }
198
199 if ($endMessage < $startMessage) {
200 $startMessage = $startMessage - $show_num;
201 if ($startMessage < 1) {
202 $startMessage = 1;
203 }
204 }
205
206 $real_startMessage = $numMessages - $startMessage + 1;
207 $real_endMessage = $numMessages - $startMessage - $show_num + 2;
208 if ($real_endMessage <= 0) {
209 $real_endMessage = 1;
210 }
211 $id = array_reverse(range($real_endMessage, $real_startMessage));
212 }
213
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;
225 }
226 }
227
228 $j = 0;
229 if ($sort == 6) {
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 }
238 } else {
239 $end = $numMessages;
240 $end_loop = $end;
241 }
242
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 }
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];
263
264 # fix SUBJECT-SORT to remove Re:
265 $re_abbr = # Add more here!
266 'vedr|sv|' . # Danish
267 're|aw'; # English
268
269 if (eregi( "^($re_abbr):[ ]*(.*)$", $messages[$j]['SUBJECT-SORT'], $regs))
270 $messages[$j]['SUBJECT-SORT'] = $regs[2];
271
272 $num = 0;
273 while ($num < count($flags[$j])) {
274 if ($flags[$j][$num] == 'Deleted') {
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;
282 }
283 $num++;
284 }
285 $j++;
286 }
287
288 /* Only ignore messages flagged as deleted if we are using a
289 * trash folder or auto_expunge */
290 if (((isset($move_to_trash) && $move_to_trash)
291 || (isset($auto_expunge) && $auto_expunge)) && $sort != 6) {
292
293 /** Find and remove the ones that are deleted */
294 $i = 0;
295 $j = 0;
296
297 while ($j < $numMessages) {
298 if (isset($messages[$j]['FLAG_DELETED']) && $messages[$j]['FLAG_DELETED'] == true) {
299 $j++;
300 continue;
301 }
302 $msgs[$i] = $messages[$j];
303
304 $i++;
305 $j++;
306 }
307 $numMessages = $i;
308 } else {
309 if (!isset($messages)) {
310 $messages = array();
311 }
312 $msgs = $messages;
313 }
314 }
315
316 // There's gotta be messages in the array for it to sort them.
317 if ($numMessages > 0 && ! $use_cache) {
318 /** 0 = Date (up) 4 = Subject (up)
319 ** 1 = Date (dn) 5 = Subject (dn)
320 ** 2 = Name (up)
321 ** 3 = Name (dn)
322 **/
323 session_unregister("msgs");
324 if (($sort == 0) || ($sort == 1))
325 $msort = array_cleave ($msgs, 'TIME_STAMP');
326 elseif (($sort == 2) || ($sort == 3))
327 $msort = array_cleave ($msgs, 'FROM-SORT');
328 elseif (($sort == 4) || ($sort == 5))
329 $msort = array_cleave ($msgs, 'SUBJECT-SORT');
330 else // ($sort == 6)
331 $msort = $msgs;
332
333 if ($sort < 6) {
334 if ($sort % 2) {
335 asort($msort);
336 } else {
337 arsort($msort);
338 }
339 }
340 session_register('msort');
341 }
342 displayMessageArray($imapConnection, $numMessages, $startMessage, $msgs, $msort, $mailbox, $sort, $color,$show_num);
343 session_register('msgs');
344 }
345
346 /******************************************************************/
347 /* Generic function to convert the msgs array into an HTML table. */
348 /******************************************************************/
349 function displayMessageArray($imapConnection, $numMessages, $startMessage, &$msgs, $msort, $mailbox, $sort, $color,$show_num) {
350 global $folder_prefix, $sent_folder;
351 global $imapServerAddress, $data_dir, $username, $use_mailbox_cache;
352 global $index_order, $real_endMessage, $real_startMessage, $checkall;
353
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'); }
357
358 if ($startMessage + ($show_num - 1) < $numMessages) {
359 $endMessage = $startMessage + ($show_num-1);
360 } else {
361 $endMessage = $numMessages;
362 }
363
364 if ($endMessage < $startMessage) {
365 $startMessage = $startMessage - $show_num;
366 if ($startMessage < 1) { $startMessage = 1; }
367 }
368
369 $nextGroup = $startMessage + $show_num;
370 $prevGroup = $startMessage - $show_num;
371 $urlMailbox = urlencode($mailbox);
372
373 do_hook('mailbox_index_before');
374
375 $Message = '';
376 if ($startMessage < $endMessage) {
377 $Message = _("Viewing messages") .":<B>$startMessage</B> ". _("to") ." <B>$endMessage</B> ($numMessages " . _("total") . ")\n";
378 } elseif ($startMessage == $endMessage) {
379 $Message = _("Viewing message") .":<B>$startMessage</B> ($numMessages " . _("total") . ")\n";
380 }
381
382 if ($sort == 6) {
383 $use = 0;
384 } else {
385 $use = 1;
386 }
387 $lMore = '';
388 $rMore = '';
389 if (($nextGroup <= $numMessages) && ($prevGroup >= 0)) {
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";
392 } else if (($nextGroup > $numMessages) && ($prevGroup >= 0)) {
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";
395 } else if (($nextGroup <= $numMessages) && ($prevGroup < 0)) {
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 }
399 if ($lMore <> '') {
400 $lMore .= ' | ';
401 }
402
403 /* Page selector block. Following code computes page links. */
404 $mMore = '';
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 ) {
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> ";
420 $i += $k;
421 }
422 $mMore .= "<b>$p</b> ";
423 $i += $k;
424 while( $i <= $j ) {
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;
430 }
431 $mMore .= ' | ';
432 }
433
434 if (! isset($msg))
435 $msg = '';
436 mail_message_listing_beginning($imapConnection,
437 "move_messages.php?msg=$msg&mailbox=$urlMailbox&startMessage=$startMessage",
438 $mailbox, $sort, $Message, $lMore . $mMore . $rMore, $startMessage);
439
440 $groupNum = $startMessage % ($show_num - 1);
441 $real_startMessage = $startMessage;
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 $endVar = $endMessage + 1;
452
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>";
458 } else if ($startMessage == $endMessage) { // if there's only one message in the box, handle it different.
459 if ($sort != 6)
460 $i = $startMessage;
461 else
462 $i = 1;
463 reset($msort);
464 $k = 0;
465 do {
466 $key = key($msort);
467 next($msort);
468 $k++;
469 } while (isset ($key) && ($k < $i));
470 printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $real_startMessage, 0, 0);
471 } else {
472 $i = $startMessage;
473
474 reset($msort);
475 $k = 0;
476 do {
477 $key = key($msort);
478 next($msort);
479 $k++;
480 } while (isset ($key) && ($k < $i));
481
482 do {
483 printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $real_startMessage, 0, 0);
484 $key = key($msort);
485 $t++;
486 $i++;
487 next($msort);
488 } while ($i && $i < $endVar);
489 }
490
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 */
493
494 do_hook('mailbox_index_after');
495 echo "</TABLE></FORM>\n";
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 */
506 function mail_message_listing_beginning
507 ($imapConnection, $moveURL, $mailbox = '', $sort = -1,
508 $Message = '', $More = '', $startMessage = 1) {
509 global $color, $index_order, $auto_expunge, $move_to_trash;
510 global $checkall, $sent_folder, $draft_folder;
511 $urlMailbox = urlencode($mailbox);
512
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">';
515
516 echo "<TR BGCOLOR=\"$color[4]\"><TD>";
517
518 /** The delete and move options */
519 echo "<TR><TD BGCOLOR=\"$color[0]\">";
520
521 echo "\n<FORM name=messageList method=post action=\"$moveURL\">\n";
522 echo "<TABLE BGCOLOR=\"$color[0]\" COLS=2 BORDER=0 cellpadding=0 cellspacing=0 width=100%>\n";
523
524
525 echo "<tr bgcolor=\"$color[4]\"><td colspan=3>\n" .
526 "<table bgcolor=\"$color[4]\" cellpadding=2".
527 ' width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td>' .
528 "$More</td><td align=right>";
529 ShowSelectAllLink($startMessage, $sort);
530 echo "</td></tr></table>\n</td></tr>";
531
532 echo " <TR>\n" .
533 " <TD ALIGN=LEFT VALIGN=CENTER NOWRAP>\n" .
534 ' <SMALL>&nbsp;' . _("Move selected to:") . "</SMALL>\n" .
535 " </TD>\n" .
536 " <TD ALIGN=RIGHT NOWRAP>\n" .
537 ' <SMALL>&nbsp;' . _("Transform Selected Messages") . ": &nbsp; </SMALL><BR>\n" .
538 " </TD>\n" .
539 " </TR>\n" .
540 " <TR>\n" .
541 " <TD ALIGN=LEFT VALIGN=CENTER NOWRAP>\n" .
542 ' <SMALL>&nbsp;<TT><SELECT NAME="targetMailbox">';
543
544 $boxes = sqimap_mailbox_list($imapConnection);
545 for ($i = 0; $i < count($boxes); $i++) {
546 if (!in_array("noselect", $boxes[$i]['flags'])) {
547 $box = $boxes[$i]['unformatted'];
548 $box2 = str_replace(' ', '&nbsp;', $boxes[$i]['unformatted-disp']);
549 echo " <OPTION VALUE=\"$box\">$box2</option>\n";
550 }
551 }
552 echo ' </SELECT></TT></SMALL>';
553 echo " <SMALL><INPUT TYPE=SUBMIT NAME=\"moveButton\" VALUE=\"" . _("Move") . "\"></SMALL>\n";
554 echo " </TD>\n";
555 echo " <TD ALIGN=RIGHT NOWRAP>&nbsp;&nbsp;&nbsp;\n";
556 if (!$auto_expunge) {
557 echo ' <INPUT TYPE=SUBMIT NAME="expungeButton" VALUE="'. _("Expunge") .'">&nbsp;'. _("mailbox") ."&nbsp;\n";
558 }
559 echo " <INPUT TYPE=SUBMIT NAME=\"markRead\" VALUE=\"". _("Read")."\">\n";
560 echo " <INPUT TYPE=SUBMIT NAME=\"markUnread\" VALUE=\"". _("Unread")."\">\n";
561 echo " <INPUT TYPE=SUBMIT VALUE=\"". _("Delete") . "\">&nbsp;\n";
562 echo " </TD>\n";
563 echo " </TR>\n";
564 echo "</TABLE>\n";
565 do_hook('mailbox_form_before');
566 echo '</TD></TR>';
567
568 echo "<TR><TD BGCOLOR=\"$color[0]\">";
569 echo "<TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=";
570 if ($GLOBALS['alt_index_colors']) {
571 echo "0";
572 } else {
573 echo "1";
574 }
575 echo " BGCOLOR=\"$color[0]\">";
576 echo "<TR BGCOLOR=\"$color[5]\" ALIGN=\"center\">";
577
578 /* Print the headers. */
579 for ($i=1; $i <= count($index_order); $i++) {
580 switch ($index_order[$i]) {
581 case 1: /* checkbox */
582 case 5: /* flags */
583 echo ' <TD WIDTH="1%"><B>&nbsp;</B></TD>';
584 break;
585
586 case 2: /* from */
587 if (($mailbox == $sent_folder)
588 || ($mailbox == $draft_folder)) {
589 echo ' <TD WIDTH="25%"><B>'. _("To") .'</B>';
590 } else {
591 echo ' <TD WIDTH="25%"><B>'. _("From") .'</B>';
592 }
593
594 ShowSortButton($sort, $mailbox, 2, 3);
595 echo "</TD>\n";
596 break;
597
598 case 3: /* date */
599 echo ' <TD NOWRAP WIDTH="5%"><B>'. _("Date") .'</B>';
600 ShowSortButton($sort, $mailbox, 0, 1);
601 echo "</TD>\n";
602 break;
603
604 case 4: /* subject */
605 echo ' <TD><B>'. _("Subject") .'</B> ';
606 ShowSortButton($sort, $mailbox, 4, 5);
607 echo "</TD>\n";
608 break;
609
610 case 6: /* size */
611 echo ' <TD WIDTH="5%"><b>' . _("Size")."</b></TD>\n";
612 break;
613 }
614 }
615 echo "</TR>\n";
616 }
617
618 /*******************************************************************/
619 /* This function shows the sort button. Isn't this a good comment? */
620 /*******************************************************************/
621 function ShowSortButton($sort, $mailbox, $Up, $Down) {
622 /* Figure out which image we want to use. */
623 if ($sort != $Up && $sort != $Down) {
624 $img = 'sort_none.gif';
625 $which = $Up;
626 } elseif ($sort == $Up) {
627 $img = 'up_pointer.gif';
628 $which = $Down;
629 } else {
630 $img = 'down_pointer.gif';
631 $which = 6;
632 }
633
634 /* Now that we have everything figured out, show the actual button. */
635 echo ' <a href="right_main.php?newsort=' . $which .
636 '&startMessage=1&mailbox=' . urlencode($mailbox) .
637 '"><IMG SRC="../images/' . $img .
638 '" BORDER=0 WIDTH=12 HEIGHT=10></a>';
639 }
640
641 function ShowSelectAllLink($startMessage, $sort) {
642 global $checkall, $PHP_SELF, $what, $where, $mailbox;
643
644 ?>&nbsp;
645 <script language="JavaScript">
646 <!--
647 function CheckAll() {
648 for (var i = 0; i < document.messageList.elements.length; i++) {
649 if( document.messageList.elements[i].type == 'checkbox' ) {
650 document.messageList.elements[i].checked =
651 !(document.messageList.elements[i].checked);
652 }
653 }
654 }
655 window.document.write('<input type=button onClick="CheckAll();" value="<?php echo
656 _("Toggle All") ?>">');
657 //-->
658 </script><noscript>
659 <?PHP
660
661 echo "<a href=\"$PHP_SELF?mailbox=" . urlencode($mailbox) .
662 "&startMessage=$startMessage&sort=$sort&checkall=";
663 if (isset($checkall) && $checkall == '1')
664 echo '0';
665 else
666 echo '1';
667 if (isset($where) && isset($what))
668 echo '&where=' . urlencode($where) . '&what=' . urlencode($what);
669 echo "\">";
670 if (isset($checkall) && $checkall == '1')
671 echo _("Unselect All");
672 else
673 echo _("Select All");
674
675 echo "</A>\n</noscript>\n";
676 }
677
678 function processSubject($subject)
679 {
680 // Shouldn't ever happen -- caught too many times in the IMAP functions
681 if ($subject == '')
682 return _("(no subject)");
683
684 if (strlen($subject) <= 55)
685 return $subject;
686
687 $ent_strlen=strlen($subject);
688 $trim_val=50;
689 $ent_offset=0;
690 // see if this is entities-encoded string
691 // If so, Iterate through the whole string, find out
692 // the real number of characters, and if more
693 // than 55, substr with an updated trim value.
694 while (($ent_loc = strpos($subject, '&', $ent_offset)) !== false &&
695 ($ent_loc_end = strpos($subject, ';', $ent_loc)) !== false)
696 {
697 $trim_val += ($ent_loc_end-$ent_loc)+1;
698 $ent_strlen -= $ent_loc_end-$ent_loc;
699 $ent_offset = $ent_loc_end+1;
700 }
701
702 if ($ent_strlen <= 55)
703 return $subject;
704
705 return substr($subject, 0, $trim_val) . '...';
706 }
707
708 ?>