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