* Subject column width should now take up whatever's available.
[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 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 if (($sort == 2) || ($sort == 3))
331 $msort = array_cleave ($msgs, 'FROM-SORT');
332 if (($sort == 4) || ($sort == 5))
333 $msort = array_cleave ($msgs, 'SUBJECT-SORT');
334 if ($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 $More = '';
388 if ($sort == 6) {
389 $use = 0;
390 } else {
391 $use = 1;
392 }
393 if (($nextGroup <= $numMessages) && ($prevGroup >= 0)) {
394 $More = "<A HREF=\"right_main.php?use_mailbox_cache=$use&startMessage=$prevGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Previous") ."</A> | \n";
395 $More .= "<A HREF=\"right_main.php?use_mailbox_cache=$use&&startMessage=$nextGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Next") ."</A>\n";
396 }
397 elseif (($nextGroup > $numMessages) && ($prevGroup >= 0)) {
398 $More = "<A HREF=\"right_main.php?use_mailbox_cache=$use&startMessage=$prevGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Previous") ."</A> | \n";
399 $More .= "<FONT COLOR=\"$color[9]\">"._("Next")."</FONT>\n";
400 }
401 elseif (($nextGroup <= $numMessages) && ($prevGroup < 0)) {
402 $More = "<FONT COLOR=\"$color[9]\">"._("Previous")."</FONT> | \n";
403 $More .= "<A HREF=\"right_main.php?use_mailbox_cache=$use&startMessage=$nextGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Next") ."</A>\n";
404 }
405
406 if (! isset($msg))
407 $msg = "";
408 mail_message_listing_beginning($imapConnection,
409 "move_messages.php?msg=$msg&mailbox=$urlMailbox&startMessage=$startMessage",
410 $mailbox, $sort, $Message, $More, $startMessage);
411
412 $groupNum = $startMessage % ($show_num - 1);
413 $real_startMessage = $startMessage;
414 if ($sort == 6) {
415 if ($endMessage - $startMessage < $show_num - 1) {
416 $endMessage = $endMessage - $startMessage + 1;
417 $startMessage = 1;
418 } else if ($startMessage > $show_num) {
419 $endMessage = $show_num;
420 $startMessage = 1;
421 }
422 }
423
424 $endVar = $endMessage + 1;
425
426 // loop through and display the info for each message.
427 $t = 0; // $t is used for the checkbox number
428 if ($numMessages == 0) { // if there's no messages in this folder
429 echo "<TR><TD BGCOLOR=\"$color[4]\" COLSPAN=" . count($index_order);
430 echo "><CENTER><BR><B>". _("THIS FOLDER IS EMPTY") ."</B><BR>&nbsp;</CENTER></TD></TR>";
431 } else if ($startMessage == $endMessage) { // if there's only one message in the box, handle it different.
432 if ($sort != 6)
433 $i = $startMessage;
434 else
435 $i = 1;
436 reset($msort);
437 $k = 0;
438 do {
439 $key = key($msort);
440 next($msort);
441 $k++;
442 } while (isset ($key) && ($k < $i));
443 printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $real_startMessage, 0, 0);
444 } else {
445 $i = $startMessage;
446
447 reset($msort);
448 $k = 0;
449 do {
450 $key = key($msort);
451 next($msort);
452 $k++;
453 } while (isset ($key) && ($k < $i));
454
455 do {
456 printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $real_startMessage, 0, 0);
457 $key = key($msort);
458 $t++;
459 $i++;
460 next($msort);
461 } while ($i && $i < $endVar);
462 }
463 echo '</TABLE>';
464
465 echo "</td></tr>\n";
466
467 echo "<TR BGCOLOR=\"$color[4]\"><TD>";
468 echo '<table width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td>';
469 echo "$More</td><td align=right>\n";
470 if (!$startMessage) $startMessage=1;
471 ShowSelectAllLink($startMessage, $sort);
472
473 echo '</td></tr></table>';
474 echo '</td></tr>';
475 echo '</table>'; /** End of message-list table */
476
477 do_hook('mailbox_index_after');
478 }
479
480 /* Displays the standard message list header.
481 * To finish the table, you need to do a "</table></table>";
482 * $moveURL is the URL to submit the delete/move form to
483 * $mailbox is the current mailbox
484 * $sort is the current sorting method (-1 for no sorting available [searches])
485 * $Message is a message that is centered on top of the list
486 * $More is a second line that is left aligned
487 */
488 function mail_message_listing_beginning($imapConnection, $moveURL,
489 $mailbox = '', $sort = -1, $Message = '', $More = '', $startMessage = 1)
490 {
491 global $color, $index_order, $auto_expunge, $move_to_trash;
492 global $checkall, $sent_folder;
493 $urlMailbox = urlencode($mailbox);
494 /** This is the beginning of the message list table. It wraps around all messages */
495 echo '<TABLE WIDTH="100%" BORDER="0" CELLPADDING="2" CELLSPACING="0">';
496
497 if ($Message)
498 {
499 echo "<TR BGCOLOR=\"$color[4]\"><TD align=center>$Message</td></tr>\n";
500 }
501
502 echo "<TR BGCOLOR=\"$color[4]\"><TD>";
503 echo '<table width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td>';
504 echo "$More</td><td align=right>\n";
505 ShowSelectAllLink($startMessage, $sort);
506
507 echo '</td></tr></table>';
508 echo '</td></tr>';
509
510 /** The delete and move options */
511 echo "<TR><TD BGCOLOR=\"$color[0]\">";
512
513 echo "\n\n\n<FORM name=messageList method=post action=\"$moveURL\">\n";
514 echo "<TABLE BGCOLOR=\"$color[0]\" COLS=2 BORDER=0 cellpadding=0 cellspacing=0 width=100%>\n";
515 echo " <TR>\n";
516 echo " <TD WIDTH=60% ALIGN=LEFT VALIGN=CENTER>\n";
517
518
519 echo ' <NOBR><SMALL>'. _("Move selected to:") .'</SMALL>';
520 echo ' <TT><SMALL><SELECT NAME="targetMailbox">';
521
522 $boxes = sqimap_mailbox_list($imapConnection);
523 for ($i = 0; $i < count($boxes); $i++) {
524 if (!in_array("noselect", $boxes[$i]['flags'])) {
525 $box = $boxes[$i]['unformatted'];
526 $box2 = str_replace(' ', '&nbsp;', $boxes[$i]['unformatted-disp']);
527 echo " <OPTION VALUE=\"$box\">$box2</option>\n";
528 }
529 }
530 echo ' </SELECT></SMALL></TT>';
531 echo ' <SMALL><INPUT TYPE=SUBMIT NAME="moveButton" VALUE="'. _("Move") ."\"></SMALL></NOBR>\n";
532 echo " </TD>\n";
533 echo " <TD WIDTH=40% ALIGN=RIGHT>\n";
534 if (! $auto_expunge) {
535 echo ' <NOBR><SMALL><INPUT TYPE=SUBMIT NAME="expungeButton" VALUE="'. _("Expunge") .'">&nbsp;'. _("mailbox") ."</SMALL></NOBR>&nbsp;&nbsp;\n";
536 }
537 echo " <NOBR><SMALL><INPUT TYPE=SUBMIT VALUE=\"". _("Delete") ."\">&nbsp;". _("checked messages") ."</SMALL></NOBR>\n";
538 echo " </TD>\n";
539 echo " </TR>\n";
540
541 echo "</TABLE>\n";
542 do_hook('mailbox_form_before');
543 echo '</TD></TR>';
544
545 echo "<TR><TD BGCOLOR=\"$color[0]\">";
546 echo "<TABLE WIDTH=100% BORDER=0 CELLPADDING=1 CELLSPACING=0 BGCOLOR=\"$color[0]\">";
547 echo "<TR BGCOLOR=\"$color[5]\" ALIGN=\"center\">";
548
549 $urlMailbox=urlencode($mailbox);
550
551 // Print the headers
552 for ($i=1; $i <= count($index_order); $i++) {
553 switch ($index_order[$i]) {
554 case 1: # checkbox
555 case 5: # flags
556 echo ' <TD WIDTH="1%"><B>&nbsp;</B></TD>';
557 break;
558
559 case 2: # from
560 if ($mailbox == $sent_folder)
561 echo ' <TD WIDTH="30%"><B>'. _("To") .'</B>';
562 else
563 echo ' <TD WIDTH="30%"><B>'. _("From") .'</B>';
564
565 if ($sort == 2)
566 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";
567 elseif ($sort == 3)
568 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";
569 elseif ($sort != -1)
570 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";
571 echo "</TD>";
572 break;
573
574 case 3: # date
575 echo ' <TD nowrap WIDTH="1%"><B>'. _("Date") .'</B>';
576 if ($sort == 0)
577 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";
578 elseif ($sort == 1)
579 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";
580 elseif ($sort == 6)
581 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";
582 elseif ($sort != -1)
583 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";
584 echo '</TD>';
585 break;
586
587 case 4: # subject
588 echo ' <TD><B>'. _("Subject") ."</B>\n";
589 if ($sort == 4)
590 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";
591 elseif ($sort == 5)
592 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";
593 elseif ($sort != -1)
594 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";
595 echo "</TD>";
596 break;
597
598 case 6: # size
599 echo ' <TD WIDTH="1%"><b>' . _("Size")."</b></TD>\n";
600 break;
601 }
602 }
603 echo "</TR>\n";
604 }
605
606 function ShowSelectAllLink($startMessage, $sort)
607 {
608 global $checkall, $PHP_SELF, $what, $where, $mailbox;
609
610 echo "\n<A HREF=\"$PHP_SELF?mailbox=" . urlencode($mailbox) .
611 "&startMessage=$startMessage&sort=$sort&";
612 if ( isset($checkall) && $checkall == '1')
613 echo "checkall=0";
614 else
615 echo "checkall=1";
616 if (isset($where) && isset($what))
617 echo "&where=" . urlencode($where) . "&what=" . urlencode($what);
618 echo "\">";
619 if (isset($checkall) && $checkall == '1')
620 echo _("Unselect All");
621 else
622 echo _("Select All");
623 echo "</A>\n";
624 }
625
626 function processSubject($subject)
627 {
628 // Shouldn't ever happen -- caught too many times in the IMAP functions
629 if ($subject == '')
630 return _("(no subject)");
631
632 if (strlen($subject) <= 55)
633 return $subject;
634
635 $ent_strlen=strlen($subject);
636 $trim_val=50;
637 $ent_offset=0;
638 // see if this is entities-encoded string
639 // If so, Iterate through the whole string, find out
640 // the real number of characters, and if more
641 // than 55, substr with an updated trim value.
642 while (($ent_loc = strpos($subject, '&', $ent_offset)) !== false &&
643 ($ent_loc_end = strpos($subject, ';', $ent_loc)) !== false)
644 {
645 $trim_val += ($ent_loc_end-$ent_loc)+1;
646 $ent_strlen -= $ent_loc_end-$ent_loc;
647 $ent_offset = $ent_loc_end+1;
648 }
649
650 if ($ent_strlen <= 55)
651 return $subject;
652
653 return substr($subject, 0, $trim_val) . '...';
654 }
655
656 ?>