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