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