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