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