Intl. "a la Konstantin"
[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 = sprintf( _("Viewing Messages: <B>%s</B> to <B>%s</B> (%s total)"), $startMessage, $endMessage, $numMessages );
378 } elseif ($startMessage == $endMessage) {
379 $Message = _("Viewing Message: <b>1</b> (1 total)");
380 } else {
381 $Message = '<br>';
382 }
383
384 if ($sort == 6) {
385 $use = 0;
386 } else {
387 $use = 1;
388 }
389 $lMore = '';
390 $rMore = '';
391 if (($nextGroup <= $numMessages) && ($prevGroup >= 0)) {
392 $lMore = "<A HREF=\"right_main.php?use_mailbox_cache=$use&startMessage=$prevGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Previous") . '</A>';
393 $rMore = "<A HREF=\"right_main.php?use_mailbox_cache=$use&&startMessage=$nextGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Next") ."</A>\n";
394 } else if (($nextGroup > $numMessages) && ($prevGroup >= 0)) {
395 $lMore = "<A HREF=\"right_main.php?use_mailbox_cache=$use&startMessage=$prevGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Previous") . '</A>';
396 $rMore = "<FONT COLOR=\"$color[9]\">"._("Next")."</FONT>\n";
397 } else if (($nextGroup <= $numMessages) && ($prevGroup < 0)) {
398 $lMore = "<FONT COLOR=\"$color[9]\">"._("Previous") . '</FONT>';
399 $rMore = "<A HREF=\"right_main.php?use_mailbox_cache=$use&startMessage=$nextGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Next") ."</A>\n";
400 }
401 if ($lMore <> '') {
402 $lMore .= ' | ';
403 }
404
405 /* Page selector block. Following code computes page links. */
406 $mMore = '';
407 if (!getPref($data_dir, $username, 'page_selector')
408 && ($numMessages > $show_num)) {
409 $j = intval( $numMessages / $show_num ); // Max pages
410 $k = max( 1, $j / getPref($data_dir, $username, 'page_selector_max', PG_SEL_MAX ) );
411 if ($numMessages % $show_num <> 0 ) {
412 $j++;
413 }
414 $startMessage = min( $startMessage, $numMessages );
415 $p = intval( $startMessage / $show_num ) + 1;
416 $i = 1;
417 while( $i < $p ) {
418 $pg = intval( $i );
419 $start = ( ($pg-1) * $show_num ) + 1;
420 $mMore .= "<a href=\"right_main.php?use_mailbox_cache=$use_mailbox_cache&startMessage=$start" .
421 "&mailbox=$urlMailbox\" TARGET=\"right\">$pg</a> ";
422 $i += $k;
423 }
424 $mMore .= "<b>$p</b> ";
425 $i += $k;
426 while( $i <= $j ) {
427 $pg = intval( $i );
428 $start = ( ($pg-1) * $show_num ) + 1;
429 $mMore .= "<a href=\"right_main.php?use_mailbox_cache=$use_mailbox_cache&startMessage=$start" .
430 "&mailbox=$urlMailbox\" TARGET=\"right\">$pg</a> ";
431 $i+=$k;
432 }
433 $mMore .= ' | ';
434 }
435
436 if (! isset($msg))
437 $msg = '';
438 mail_message_listing_beginning($imapConnection,
439 "move_messages.php?msg=$msg&mailbox=$urlMailbox&startMessage=$startMessage",
440 $mailbox, $sort, $Message, $lMore . $mMore . $rMore, $startMessage);
441
442 $groupNum = $startMessage % ($show_num - 1);
443 $real_startMessage = $startMessage;
444 if ($sort == 6) {
445 if ($endMessage - $startMessage < $show_num - 1) {
446 $endMessage = $endMessage - $startMessage + 1;
447 $startMessage = 1;
448 } else if ($startMessage > $show_num) {
449 $endMessage = $show_num;
450 $startMessage = 1;
451 }
452 }
453 $endVar = $endMessage + 1;
454
455 // loop through and display the info for each message.
456 $t = 0; // $t is used for the checkbox number
457 if ($numMessages == 0) { // if there's no messages in this folder
458 echo "<TR><TD BGCOLOR=\"$color[4]\" COLSPAN=" . count($index_order);
459 echo "><CENTER><BR><B>". _("THIS FOLDER IS EMPTY") ."</B><BR>&nbsp;</CENTER></TD></TR>";
460 } else if ($startMessage == $endMessage) { // if there's only one message in the box, handle it different.
461 if ($sort != 6)
462 $i = $startMessage;
463 else
464 $i = 1;
465 reset($msort);
466 $k = 0;
467 do {
468 $key = key($msort);
469 next($msort);
470 $k++;
471 } while (isset ($key) && ($k < $i));
472 printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $real_startMessage, 0, 0);
473 } else {
474 $i = $startMessage;
475
476 reset($msort);
477 $k = 0;
478 do {
479 $key = key($msort);
480 next($msort);
481 $k++;
482 } while (isset ($key) && ($k < $i));
483
484 do {
485 printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $real_startMessage, 0, 0);
486 $key = key($msort);
487 $t++;
488 $i++;
489 next($msort);
490 } while ($i && $i < $endVar);
491 }
492
493 echo '</table>';
494 echo "<table bgcolor=\"$color[9]\" width=100% border=0 cellpadding=1 cellspacing=1>" .
495 "<tr BGCOLOR=\"$color[4]\">" .
496 "<table width=100% BGCOLOR=\"$color[4]\" border=0 cellpadding=1 cellspacing=0><tr><td>$lMore$mMore$rMore</td>".
497 "<td align=right>$Message</td></tr></table>".
498 "</tr>".
499 "</table>";
500 /** End of message-list table */
501
502 do_hook('mailbox_index_after');
503 echo "</TABLE></FORM>\n";
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 */
514 function mail_message_listing_beginning
515 ($imapConnection, $moveURL, $mailbox = '', $sort = -1,
516 $Message = '', $More = '', $startMessage = 1) {
517 global $color, $index_order, $auto_expunge, $move_to_trash;
518 global $checkall, $sent_folder, $draft_folder;
519 $urlMailbox = urlencode($mailbox);
520
521 /** This is the beginning of the message list table. It wraps around all messages */
522 echo "<center>$Message</center>" .
523 '<TABLE WIDTH="100%" BORDER="0" CELLPADDING="1" CELLSPACING="0">';
524
525 echo "<TR BGCOLOR=\"$color[9]\"><TD>";
526
527 echo "<table bgcolor=\"$color[4]\" cellpadding=2".
528 ' width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td>' .
529 "$More</td><td align=right>";
530 ShowSelectAllLink($startMessage, $sort);
531 echo "</td></tr></table>\n</td></tr>";
532
533 /** The delete and move options */
534 echo "<TD BGCOLOR=\"$color[0]\">";
535
536 echo "\n<FORM name=messageList method=post action=\"$moveURL\">\n";
537 echo "<TABLE BGCOLOR=\"$color[0]\" COLS=2 BORDER=0 cellpadding=0 cellspacing=0 width=100%>\n";
538
539 echo " <TR>\n" .
540 " <TD ALIGN=LEFT VALIGN=CENTER NOWRAP>\n" .
541 ' <SMALL>&nbsp;' . _("Move selected to:") . "</SMALL>\n" .
542 " </TD>\n" .
543 " <TD ALIGN=RIGHT NOWRAP>\n" .
544 ' <SMALL>&nbsp;' . _("Transform Selected Messages") . ": &nbsp; </SMALL><BR>\n" .
545 " </TD>\n" .
546 " </TR>\n" .
547 " <TR>\n" .
548 " <TD ALIGN=LEFT VALIGN=CENTER NOWRAP>\n" .
549 ' <SMALL>&nbsp;<TT><SELECT NAME="targetMailbox">';
550
551 $boxes = sqimap_mailbox_list($imapConnection);
552 for ($i = 0; $i < count($boxes); $i++) {
553 if (!in_array("noselect", $boxes[$i]['flags'])) {
554 $box = $boxes[$i]['unformatted'];
555 $box2 = str_replace(' ', '&nbsp;', $boxes[$i]['formatted']);
556 echo " <OPTION VALUE=\"$box\">$box2</option>\n";
557 }
558 }
559 echo ' </SELECT></TT></SMALL>';
560 echo " <SMALL><INPUT TYPE=SUBMIT NAME=\"moveButton\" VALUE=\"" . _("Move") . "\"></SMALL>\n";
561 echo " </TD>\n";
562 echo " <TD ALIGN=RIGHT NOWRAP>&nbsp;&nbsp;&nbsp;\n";
563 if (!$auto_expunge) {
564 echo ' <INPUT TYPE=SUBMIT NAME="expungeButton" VALUE="'. _("Expunge") .'">&nbsp;'. _("mailbox") ."&nbsp;\n";
565 }
566 echo " <INPUT TYPE=SUBMIT NAME=\"markRead\" VALUE=\"". _("Read")."\">\n";
567 echo " <INPUT TYPE=SUBMIT NAME=\"markUnread\" VALUE=\"". _("Unread")."\">\n";
568 echo " <INPUT TYPE=SUBMIT VALUE=\"". _("Delete") . "\">&nbsp;\n";
569 echo " </TD>\n";
570 echo " </TR>\n";
571 echo "</TABLE>\n";
572 do_hook('mailbox_form_before');
573 echo '</TD></TR>';
574
575 echo "<TR><TD BGCOLOR=\"$color[0]\">";
576 echo "<TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=";
577 if ($GLOBALS['alt_index_colors']) {
578 echo "0";
579 } else {
580 echo "1";
581 }
582 echo " BGCOLOR=\"$color[0]\">";
583 echo "<TR BGCOLOR=\"$color[5]\" ALIGN=\"center\">";
584
585 /* Print the headers. */
586 for ($i=1; $i <= count($index_order); $i++) {
587 switch ($index_order[$i]) {
588 case 1: /* checkbox */
589 case 5: /* flags */
590 echo ' <TD WIDTH="1%"><B>&nbsp;</B></TD>';
591 break;
592
593 case 2: /* from */
594 if (($mailbox == $sent_folder)
595 || ($mailbox == $draft_folder)) {
596 echo ' <TD WIDTH="25%"><B>'. _("To") .'</B>';
597 } else {
598 echo ' <TD WIDTH="25%"><B>'. _("From") .'</B>';
599 }
600
601 ShowSortButton($sort, $mailbox, 2, 3);
602 echo "</TD>\n";
603 break;
604
605 case 3: /* date */
606 echo ' <TD NOWRAP WIDTH="5%"><B>'. _("Date") .'</B>';
607 ShowSortButton($sort, $mailbox, 0, 1);
608 echo "</TD>\n";
609 break;
610
611 case 4: /* subject */
612 echo ' <TD><B>'. _("Subject") .'</B> ';
613 ShowSortButton($sort, $mailbox, 4, 5);
614 echo "</TD>\n";
615 break;
616
617 case 6: /* size */
618 echo ' <TD WIDTH="5%"><b>' . _("Size")."</b></TD>\n";
619 break;
620 }
621 }
622 echo "</TR>\n";
623 }
624
625 /*******************************************************************/
626 /* This function shows the sort button. Isn't this a good comment? */
627 /*******************************************************************/
628 function ShowSortButton($sort, $mailbox, $Up, $Down) {
629 /* Figure out which image we want to use. */
630 if ($sort != $Up && $sort != $Down) {
631 $img = 'sort_none.gif';
632 $which = $Up;
633 } elseif ($sort == $Up) {
634 $img = 'up_pointer.gif';
635 $which = $Down;
636 } else {
637 $img = 'down_pointer.gif';
638 $which = 6;
639 }
640
641 /* Now that we have everything figured out, show the actual button. */
642 echo ' <a href="right_main.php?newsort=' . $which .
643 '&startMessage=1&mailbox=' . urlencode($mailbox) .
644 '"><IMG SRC="../images/' . $img .
645 '" BORDER=0 WIDTH=12 HEIGHT=10></a>';
646 }
647
648 function ShowSelectAllLink($startMessage, $sort) {
649 global $checkall, $PHP_SELF, $what, $where, $mailbox;
650
651 echo '&nbsp;<script language="JavaScript">' .
652 "\n<!-- \n" .
653 "function CheckAll() {\n" .
654 " for (var i = 0; i < document.messageList.elements.length; i++) {\n" .
655 " if( document.messageList.elements[i].type == 'checkbox' ) {\n" .
656 " document.messageList.elements[i].checked = !(document.messageList.elements[i].checked);\n".
657 " }\n" .
658 " }\n" .
659 "}\n" .
660 'window.document.write(\'<a href=# onClick="CheckAll();">' . _("Toggle All") . "</a>');\n" .
661 "//-->\n" .
662 "</script>\n<noscript>\n";
663
664 echo "<a href=\"$PHP_SELF?mailbox=" . urlencode($mailbox) .
665 "&startMessage=$startMessage&sort=$sort&checkall=";
666 if (isset($checkall) && $checkall == '1')
667 echo '0';
668 else
669 echo '1';
670 if (isset($where) && isset($what))
671 echo '&where=' . urlencode($where) . '&what=' . urlencode($what);
672 echo "\">";
673 if (isset($checkall) && $checkall == '1')
674 echo _("Unselect All");
675 else
676 echo _("Select All");
677
678 echo "</A>\n</noscript>\n";
679 }
680
681 function processSubject($subject)
682 {
683 // Shouldn't ever happen -- caught too many times in the IMAP functions
684 if ($subject == '')
685 return _("(no subject)");
686
687 if (strlen($subject) <= 55)
688 return $subject;
689
690 $ent_strlen=strlen($subject);
691 $trim_val=50;
692 $ent_offset=0;
693 // see if this is entities-encoded string
694 // If so, Iterate through the whole string, find out
695 // the real number of characters, and if more
696 // than 55, substr with an updated trim value.
697 while (($ent_loc = strpos($subject, '&', $ent_offset)) !== false &&
698 ($ent_loc_end = strpos($subject, ';', $ent_loc)) !== false)
699 {
700 $trim_val += ($ent_loc_end-$ent_loc)+1;
701 $ent_strlen -= $ent_loc_end-$ent_loc;
702 $ent_offset = $ent_loc_end+1;
703 }
704
705 if ($ent_strlen <= 55)
706 return $subject;
707
708 return substr($subject, 0, $trim_val) . '...';
709 }
710
711 ?>