6 ** This contains functions that display mailbox information, such as the
7 ** table row that has sender, date, subject, etc...
12 $mailbox_display_php = true;
14 function printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $startMessage, $where, $what) {
16 global $color, $msgs, $msort;
18 global $message_highlight_list;
23 $senderName = sqimap_find_displayable_name($msg['FROM']);
24 $urlMailbox = urlencode($mailbox);
25 $subject = trim($msg['SUBJECT']);
27 $subject = _("(no subject)");
31 if (isset($msg['FLAG_FLAGGED']) && $msg['FLAG_FLAGGED'] == true)
33 $flag = "<font color=$color[2]>";
34 $flag_end = '</font>';
41 if (!isset($msg['FLAG_SEEN']) ||
$msg['FLAG_SEEN'] == false)
51 if ($mailbox == $sent_folder)
61 if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED'])
63 $fontstr = "<font color=\"$color[9]\">";
64 $fontstr_end = '</font>';
72 for ($i=0; $i < count($message_highlight_list); $i++
) {
73 if (trim($message_highlight_list[$i]['value']) != '') {
74 if ($message_highlight_list[$i]['match_type'] == 'to_cc') {
75 if (strpos('^^'.strtolower($msg['TO']), strtolower($message_highlight_list[$i]['value'])) ||
strpos('^^'.strtolower($msg['CC']), strtolower($message_highlight_list[$i]['value']))) {
76 $hlt_color = $message_highlight_list[$i]['color'];
79 } else if (strpos('^^'.strtolower($msg[strtoupper($message_highlight_list[$i]['match_type'])]),strtolower($message_highlight_list[$i]['value']))) {
80 $hlt_color = $message_highlight_list[$i]['color'];
86 if (!isset($hlt_color))
87 $hlt_color = $color[4];
89 if ($where && $what) {
90 $search_stuff = '&where='.urlencode($where).'&what='.urlencode($what);
94 $checked = ' checked';
98 for ($i=1; $i <= count($index_order); $i++
) {
99 switch ($index_order[$i]) {
101 echo " <td width=1% bgcolor=$hlt_color align=center><input type=checkbox name=\"msg[$t]\" value=".$msg["ID"]."$checked></TD>\n";
104 echo " <td width=30% bgcolor=$hlt_color>$italic$bold$flag$fontstr$senderName$fontstr_end$flag_end$bold_end$italic_end</td>\n";
107 echo " <td nowrap width=1% bgcolor=$hlt_color><center>$bold$flag$fontstr".$msg["DATE_STRING"]."$fontstr_end$flag_end$bold_end</center></td>\n";
110 echo " <td bgcolor=$hlt_color>$bold";
111 if (! isset($search_stuff)) { $search_stuff = ''; }
112 echo "<a href=\"read_body.php?mailbox=$urlMailbox&passed_id=".$msg["ID"]."&startMessage=$startMessage&show_more=0$search_stuff\"";
113 do_hook("subject_link");
115 if (strlen($subject) > 55){
116 $ent_strlen=strlen($subject);
118 // see if this is entities-encoded string
119 if (is_int(strpos($subject, "&#"))){
120 // Yes. Iterate through the whole string, find out
121 // the real number of characters, and if more
122 // than 55, substr with an updated trim value.
126 $ent_loc = strpos($subject, "&#", $ent_offset);
127 $ent_loc_end = strpos($subject, ";", $ent_offset);
129 $trim_val +
= ($ent_loc_end-$ent_loc)+
1;
130 $ent_strlen -= $ent_loc_end-$ent_loc;
131 $ent_offset = $ent_loc_end+
1;
133 } else $ent_loc=false;
134 } while (is_int($ent_loc));
136 if ($ent_strlen>55) echo substr($subject, 0, $trim_val) . '...';
138 } else echo $subject;
140 echo "$flag_end</a>$bold_end</td>\n";
144 echo " <td bgcolor=$hlt_color align=center width=1% nowrap><b><small>\n";
145 if (isset($msg['FLAG_ANSWERED']) &&
146 $msg['FLAG_ANSWERED'] == true) {
150 if ($msg['TYPE0'] == 'multipart') {
154 if (ereg('(1|2)',substr($msg['PRIORITY'],0,1))) {
155 echo "<font color=$color[1]>!</font>\n";
158 if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED']) {
159 echo "<font color=\"$color[1]\">D</font>\n";
163 if (!$stuff) echo " \n";
164 echo "</small></b></td>\n";
167 echo " <td bgcolor=$hlt_color width=1%>$bold$fontstr".show_readable_size($msg['SIZE'])."$fontstr_end$bold_end</td>\n";
177 ** This function loops through a group of messages in the mailbox and shows them
179 function showMessagesForMailbox($imapConnection, $mailbox, $numMessages, $startMessage, $sort, $color,$show_num, $use_cache) {
180 global $msgs, $msort;
182 global $message_highlight_list;
183 global $auto_expunge;
185 if ($auto_expunge == true) sqimap_mailbox_expunge($imapConnection, $mailbox, false);
186 sqimap_mailbox_select($imapConnection, $mailbox);
190 if ($numMessages >= 1) {
192 for ($q = 0; $q < $numMessages; $q++
) {
193 if($mailbox == $sent_folder)
194 $hdr = sqimap_get_small_header ($imapConnection, $q+
1, true);
196 $hdr = sqimap_get_small_header ($imapConnection, $q+
1, false);
198 $from[$q] = $hdr->from
;
199 $date[$q] = $hdr->date
;
200 $subject[$q] = $hdr->subject
;
202 $priority[$q] = $hdr->priority
;
204 $size[$q] = $hdr->size
;
205 $type[$q] = $hdr->type0
;
206 $flags[$q] = sqimap_get_flags ($imapConnection, $q+
1);
210 // if it's not sorted
211 if ($startMessage +
($show_num - 1) < $numMessages) {
212 $endMessage = $startMessage +
($show_num-1);
214 $endMessage = $numMessages;
217 if ($endMessage < $startMessage) {
218 $startMessage = $startMessage - $show_num;
219 if ($startMessage < 1)
224 $real_startMessage = $numMessages - $startMessage +
1;
225 $real_endMessage = $numMessages - $startMessage - $show_num;
226 if ($real_endMessage <= 0)
227 $real_endMessage = 1;
230 for ($q = $real_startMessage; $q >= $real_endMessage; $q--) {
231 if($mailbox == $sent_folder)
232 $hdr = sqimap_get_small_header ($imapConnection, $q, true);
234 $hdr = sqimap_get_small_header ($imapConnection, $q, false);
236 $from[$j] = $hdr->from
;
237 $date[$j] = $hdr->date
;
238 $subject[$j] = $hdr->subject
;
240 $priority[$j] = $hdr->priority
;
242 $size[$j] = $hdr->size
;
243 $type[$j] = $hdr->type0
;
244 $flags[$j] = sqimap_get_flags ($imapConnection, $q);
253 $end = $startMessage +
$show_num - 1;
254 if ($numMessages < $show_num)
255 $end_loop = $numMessages;
257 $end_loop = $show_num;
262 if ($end > $numMessages) $end = $numMessages;
263 while ($j < $end_loop) {
264 if (isset($date[$j])) {
265 $date[$j] = ereg_replace(' ', ' ', $date[$j]);
266 $tmpdate = explode(' ', trim($date[$j]));
268 $tmpdate = $date = array("","","","","","");
271 $messages[$j]['TIME_STAMP'] = getTimeStamp($tmpdate);
272 $messages[$j]['DATE_STRING'] = getDateString($messages[$j]['TIME_STAMP']);
273 $messages[$j]['ID'] = $id[$j];
274 $messages[$j]['FROM'] = decodeHeader($from[$j]);
275 $messages[$j]['FROM-SORT'] = strtolower(sqimap_find_displayable_name(decodeHeader($from[$j])));
276 $messages[$j]['SUBJECT'] = decodeHeader($subject[$j]);
277 $messages[$j]['SUBJECT-SORT'] = strtolower(decodeHeader($subject[$j]));
278 $messages[$j]['TO'] = decodeHeader($to[$j]);
279 $messages[$j]['PRIORITY'] = $priority[$j];
280 $messages[$j]['CC'] = $cc[$j];
281 $messages[$j]['SIZE'] = $size[$j];
282 $messages[$j]['TYPE0'] = $type[$j];
284 # fix SUBJECT-SORT to remove Re:
285 $re_abbr = # Add more here!
286 'vedr|sv|' . # Danish
288 if (eregi("^($re_abbr):[ ]*(.*)$", $messages[$j]['SUBJECT-SORT'], $regs))
289 $messages[$j]['SUBJECT-SORT'] = $regs[2];
292 while ($num < count($flags[$j])) {
293 if ($flags[$j][$num] == 'Deleted') {
294 $messages[$j]['FLAG_DELETED'] = true;
296 elseif ($flags[$j][$num] == 'Answered') {
297 $messages[$j]['FLAG_ANSWERED'] = true;
299 elseif ($flags[$j][$num] == 'Seen') {
300 $messages[$j]['FLAG_SEEN'] = true;
302 elseif ($flags[$j][$num] == 'Flagged') {
303 $messages[$j]['FLAG_FLAGGED'] = true;
310 /* Only ignore messages flagged as deleted if we are using a
311 * trash folder or auto_expunge */
312 if (((isset($move_to_trash) && $move_to_trash)
313 ||
(isset($auto_expunge) && $auto_expunge)) && $sort != 6)
315 /** Find and remove the ones that are deleted */
318 while ($j < $numMessages) {
319 if (isset($messages[$j]['FLAG_DELETED']) && $messages[$j]['FLAG_DELETED'] == true) {
323 $msgs[$i] = $messages[$j];
330 if (! isset($messages))
336 // There's gotta be messages in the array for it to sort them.
337 if ($numMessages > 0 && ! $use_cache) {
338 /** 0 = Date (up) 4 = Subject (up)
339 ** 1 = Date (dn) 5 = Subject (dn)
343 session_unregister("msgs");
344 if (($sort == 0) ||
($sort == 1))
345 $msort = array_cleave ($msgs, 'TIME_STAMP');
346 if (($sort == 2) ||
($sort == 3))
347 $msort = array_cleave ($msgs, 'FROM-SORT');
348 if (($sort == 4) ||
($sort == 5))
349 $msort = array_cleave ($msgs, 'SUBJECT-SORT');
360 session_register('msort');
362 displayMessageArray($imapConnection, $numMessages, $startMessage, $msgs, $msort, $mailbox, $sort, $color,$show_num);
363 session_register('msgs');
366 // generic function to convert the msgs array into an HTML table
367 function displayMessageArray($imapConnection, $numMessages, $startMessage, &$msgs, $msort, $mailbox, $sort, $color,$show_num) {
368 global $folder_prefix, $sent_folder;
369 global $imapServerAddress;
370 global $index_order, $real_endMessage, $real_startMessage, $checkall;
372 // if cache isn't already set, do it now
373 if (!session_is_registered('msgs'))
374 session_register('msgs');
375 if (!session_is_registered('msort'))
376 session_register('msort');
378 if ($startMessage +
($show_num - 1) < $numMessages) {
379 $endMessage = $startMessage +
($show_num-1);
381 $endMessage = $numMessages;
384 if ($endMessage < $startMessage) {
385 $startMessage = $startMessage - $show_num;
386 if ($startMessage < 1)
390 $nextGroup = $startMessage +
$show_num;
391 $prevGroup = $startMessage - $show_num;
392 $urlMailbox = urlencode($mailbox);
394 do_hook('mailbox_index_before');
397 if ($startMessage < $endMessage) {
398 $Message = _("Viewing messages") ." <B>$startMessage</B> ". _("to") ." <B>$endMessage</B> ($numMessages " . _("total") . ")\n";
399 } elseif ($startMessage == $endMessage) {
400 $Message = _("Viewing message") ." <B>$startMessage</B> ($numMessages " . _("total") . ")\n";
409 if (($nextGroup <= $numMessages) && ($prevGroup >= 0)) {
410 $More = "<A HREF=\"right_main.php?use_mailbox_cache=$use&startMessage=$prevGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Previous") ."</A> | \n";
411 $More .= "<A HREF=\"right_main.php?use_mailbox_cache=$use&&startMessage=$nextGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Next") ."</A>\n";
413 elseif (($nextGroup > $numMessages) && ($prevGroup >= 0)) {
414 $More = "<A HREF=\"right_main.php?use_mailbox_cache=$use&startMessage=$prevGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Previous") ."</A> | \n";
415 $More .= "<FONT COLOR=\"$color[9]\">"._("Next")."</FONT>\n";
417 elseif (($nextGroup <= $numMessages) && ($prevGroup < 0)) {
418 $More = "<FONT COLOR=\"$color[9]\">"._("Previous")."</FONT> | \n";
419 $More .= "<A HREF=\"right_main.php?use_mailbox_cache=$use&startMessage=$nextGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Next") ."</A>\n";
424 mail_message_listing_beginning($imapConnection,
425 "move_messages.php?msg=$msg&mailbox=$urlMailbox&startMessage=$startMessage",
426 $mailbox, $sort, $Message, $More, $startMessage);
428 $groupNum = $startMessage %
($show_num - 1);
429 $real_startMessage = $startMessage;
431 if ($endMessage - $startMessage < $show_num - 1) {
432 $endMessage = $endMessage - $startMessage +
1;
434 } else if ($startMessage > $show_num) {
435 $endMessage = $show_num;
440 $endVar = $endMessage +
1;
442 // loop through and display the info for each message.
443 $t = 0; // $t is used for the checkbox number
444 if ($numMessages == 0) { // if there's no messages in this folder
445 echo "<TR><TD BGCOLOR=\"$color[4]\" COLSPAN=" . count($index_order);
446 echo "><CENTER><BR><B>". _("THIS FOLDER IS EMPTY") ."</B><BR> </CENTER></TD></TR>";
447 } else if ($startMessage == $endMessage) { // if there's only one message in the box, handle it different.
458 } while (isset ($key) && ($k < $i));
459 printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $real_startMessage, 0, 0);
469 } while (isset ($key) && ($k < $i));
472 printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $real_startMessage, 0, 0);
477 } while ($i && $i < $endVar);
483 echo "<TR BGCOLOR=\"$color[4]\"><TD>";
484 echo '<table width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td>';
485 echo "$More</td><td align=right>\n";
486 if (!$startMessage) $startMessage=1;
487 ShowSelectAllLink($startMessage, $sort);
489 echo '</td></tr></table>';
491 echo '</table>'; /** End of message-list table */
493 do_hook('mailbox_index_after');
496 /* Displays the standard message list header.
497 * To finish the table, you need to do a "</table></table>";
498 * $moveURL is the URL to submit the delete/move form to
499 * $mailbox is the current mailbox
500 * $sort is the current sorting method (-1 for no sorting available [searches])
501 * $Message is a message that is centered on top of the list
502 * $More is a second line that is left aligned
504 function mail_message_listing_beginning($imapConnection, $moveURL,
505 $mailbox = '', $sort = -1, $Message = '', $More = '', $startMessage = 1)
507 global $color, $index_order, $auto_expunge, $move_to_trash;
508 global $checkall, $sent_folder;
509 $urlMailbox = urlencode($mailbox);
511 /** This is the beginning of the message list table. It wraps around all messages */
512 echo '<TABLE WIDTH="100%" BORDER="0" CELLPADDING="2" CELLSPACING="0">';
516 echo "<TR BGCOLOR=\"$color[4]\"><TD align=center>$Message</td></tr>\n";
519 echo "<TR BGCOLOR=\"$color[4]\"><TD>";
520 echo '<table width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td>';
521 echo "$More</td><td align=right>\n";
522 ShowSelectAllLink($startMessage, $sort);
524 echo '</td></tr></table>';
527 /** The delete and move options */
528 echo "<TR><TD BGCOLOR=\"$color[0]\">";
530 echo "\n\n\n<FORM name=messageList method=post action=\"$moveURL\">\n";
531 echo "<TABLE BGCOLOR=\"$color[0]\" COLS=2 BORDER=0 cellpadding=0 cellspacing=0 width=100%>\n";
533 echo " <TD WIDTH=60% ALIGN=LEFT VALIGN=CENTER>\n";
536 echo ' <NOBR><SMALL>'. _("Move selected to:") .'</SMALL>';
537 echo ' <TT><SMALL><SELECT NAME="targetMailbox">';
539 $boxes = sqimap_mailbox_list($imapConnection);
540 for ($i = 0; $i < count($boxes); $i++
) {
541 if (!in_array("noselect", $boxes[$i]['flags'])) {
542 $box = $boxes[$i]['unformatted'];
543 $box2 = replace_spaces($boxes[$i]['unformatted-disp']);
544 echo " <OPTION VALUE=\"$box\">$box2</option>\n";
547 echo ' </SELECT></SMALL></TT>';
548 echo ' <SMALL><INPUT TYPE=SUBMIT NAME="moveButton" VALUE="'. _("Move") ."\"></SMALL></NOBR>\n";
550 echo " <TD WIDTH=40% ALIGN=RIGHT>\n";
551 if (! $auto_expunge) {
552 echo ' <NOBR><SMALL><INPUT TYPE=SUBMIT NAME="expungeButton" VALUE="'. _("Expunge") .'"> '. _("mailbox") ."</SMALL></NOBR> \n";
554 echo " <NOBR><SMALL><INPUT TYPE=SUBMIT VALUE=\"". _("Delete") ."\"> ". _("checked messages") ."</SMALL></NOBR>\n";
559 do_hook('mailbox_form_before');
562 echo "<TR><TD BGCOLOR=\"$color[0]\">";
563 echo "<TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=1 BGCOLOR=\"$color[0]\">";
564 echo "<TR BGCOLOR=\"$color[5]\" ALIGN=\"center\">";
566 $urlMailbox=urlencode($mailbox);
569 for ($i=1; $i <= count($index_order); $i++
) {
570 switch ($index_order[$i]) {
573 echo ' <TD WIDTH="1%"><B> </B></TD>';
577 if ($mailbox == $sent_folder)
578 echo ' <TD WIDTH="30%"><B>'. _("To") .'</B>';
580 echo ' <TD WIDTH="30%"><B>'. _("From") .'</B>';
583 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";
585 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";
587 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";
592 echo ' <TD nowrap WIDTH="1%"><B>'. _("Date") .'</B>';
594 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";
596 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";
598 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";
600 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";
605 echo ' <TD WIDTH=%><B>'. _("Subject") ."</B>\n";
607 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";
609 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";
611 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";
616 echo ' <TD WIDTH="1%"><b>' . _("Size")."</b></TD>\n";
623 function ShowSelectAllLink($startMessage, $sort)
625 global $checkall, $PHP_SELF, $what, $where, $mailbox;
627 echo "\n<A HREF=\"$PHP_SELF?mailbox=" . urlencode($mailbox) .
628 "&startMessage=$startMessage&sort=$sort&";
629 if ( isset($checkall) && $checkall == '1')
633 if (isset($where) && isset($what))
634 echo "&where=" . urlencode($where) . "&what=" . urlencode($what);
636 if (isset($checkall) && $checkall == '1')
637 echo _("Unselect All");
639 echo _("Select All");