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 = processSubject($msg['SUBJECT']);
29 if (isset($msg['FLAG_FLAGGED']) && $msg['FLAG_FLAGGED'] == true)
31 $flag = "<font color=$color[2]>";
32 $flag_end = '</font>';
39 if (!isset($msg['FLAG_SEEN']) ||
$msg['FLAG_SEEN'] == false)
49 if ($mailbox == $sent_folder)
59 if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED'])
61 $fontstr = "<font color=\"$color[9]\">";
62 $fontstr_end = '</font>';
70 for ($i=0; $i < count($message_highlight_list); $i++
) {
71 if (trim($message_highlight_list[$i]['value']) != '') {
72 if ($message_highlight_list[$i]['match_type'] == 'to_cc') {
73 if (strpos('^^'.strtolower($msg['TO']), strtolower($message_highlight_list[$i]['value'])) ||
strpos('^^'.strtolower($msg['CC']), strtolower($message_highlight_list[$i]['value']))) {
74 $hlt_color = $message_highlight_list[$i]['color'];
77 } else if (strpos('^^'.strtolower($msg[strtoupper($message_highlight_list[$i]['match_type'])]),strtolower($message_highlight_list[$i]['value']))) {
78 $hlt_color = $message_highlight_list[$i]['color'];
84 if (!isset($hlt_color))
85 $hlt_color = $color[4];
87 if ($where && $what) {
88 $search_stuff = '&where='.urlencode($where).'&what='.urlencode($what);
92 $checked = ' checked';
96 for ($i=1; $i <= count($index_order); $i++
) {
97 switch ($index_order[$i]) {
99 echo " <td width=1% bgcolor=$hlt_color align=center><input type=checkbox name=\"msg[$t]\" value=".$msg["ID"]."$checked></TD>\n";
102 echo " <td width=30% bgcolor=$hlt_color>$italic$bold$flag$fontstr$senderName$fontstr_end$flag_end$bold_end$italic_end</td>\n";
105 echo " <td nowrap width=1% bgcolor=$hlt_color><center>$bold$flag$fontstr".$msg["DATE_STRING"]."$fontstr_end$flag_end$bold_end</center></td>\n";
108 echo " <td bgcolor=$hlt_color>$bold";
109 if (! isset($search_stuff)) { $search_stuff = ''; }
110 echo "<a href=\"read_body.php?mailbox=$urlMailbox&passed_id=".$msg["ID"]."&startMessage=$startMessage&show_more=0$search_stuff\"";
111 do_hook("subject_link");
112 echo ">$flag$subject$flag_end</a>$bold_end</td>\n";
116 echo " <td bgcolor=$hlt_color align=center width=1% nowrap><b><small>\n";
117 if (isset($msg['FLAG_ANSWERED']) &&
118 $msg['FLAG_ANSWERED'] == true) {
122 if ($msg['TYPE0'] == 'multipart') {
126 if (ereg('(1|2)',substr($msg['PRIORITY'],0,1))) {
127 echo "<font color=$color[1]>!</font>\n";
130 if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED']) {
131 echo "<font color=\"$color[1]\">D</font>\n";
135 if (!$stuff) echo " \n";
136 echo "</small></b></td>\n";
139 echo " <td bgcolor=$hlt_color width=1%>$bold$fontstr".show_readable_size($msg['SIZE'])."$fontstr_end$bold_end</td>\n";
149 ** This function loops through a group of messages in the mailbox and shows them
151 function showMessagesForMailbox($imapConnection, $mailbox, $numMessages, $startMessage, $sort, $color,$show_num, $use_cache) {
152 global $msgs, $msort;
154 global $message_highlight_list;
155 global $auto_expunge;
157 if ($auto_expunge == true) sqimap_mailbox_expunge($imapConnection, $mailbox, false);
158 sqimap_mailbox_select($imapConnection, $mailbox);
162 if ($numMessages >= 1) {
164 for ($q = 0; $q < $numMessages; $q++
) {
165 if($mailbox == $sent_folder)
166 $hdr = sqimap_get_small_header ($imapConnection, $q+
1, true);
168 $hdr = sqimap_get_small_header ($imapConnection, $q+
1, false);
170 $from[$q] = $hdr->from
;
171 $date[$q] = $hdr->date
;
172 $subject[$q] = $hdr->subject
;
174 $priority[$q] = $hdr->priority
;
176 $size[$q] = $hdr->size
;
177 $type[$q] = $hdr->type0
;
178 $flags[$q] = sqimap_get_flags ($imapConnection, $q+
1);
182 // if it's not sorted
183 if ($startMessage +
($show_num - 1) < $numMessages) {
184 $endMessage = $startMessage +
($show_num-1);
186 $endMessage = $numMessages;
189 if ($endMessage < $startMessage) {
190 $startMessage = $startMessage - $show_num;
191 if ($startMessage < 1)
196 $real_startMessage = $numMessages - $startMessage +
1;
197 $real_endMessage = $numMessages - $startMessage - $show_num;
198 if ($real_endMessage <= 0)
199 $real_endMessage = 1;
202 for ($q = $real_startMessage; $q >= $real_endMessage; $q--) {
203 if($mailbox == $sent_folder)
204 $hdr = sqimap_get_small_header ($imapConnection, $q, true);
206 $hdr = sqimap_get_small_header ($imapConnection, $q, false);
208 $from[$j] = $hdr->from
;
209 $date[$j] = $hdr->date
;
210 $subject[$j] = $hdr->subject
;
212 $priority[$j] = $hdr->priority
;
214 $size[$j] = $hdr->size
;
215 $type[$j] = $hdr->type0
;
216 $flags[$j] = sqimap_get_flags ($imapConnection, $q);
225 $end = $startMessage +
$show_num - 1;
226 if ($numMessages < $show_num)
227 $end_loop = $numMessages;
229 $end_loop = $show_num;
234 if ($end > $numMessages) $end = $numMessages;
235 while ($j < $end_loop) {
236 if (isset($date[$j])) {
237 $date[$j] = ereg_replace(' ', ' ', $date[$j]);
238 $tmpdate = explode(' ', trim($date[$j]));
240 $tmpdate = $date = array("","","","","","");
243 $messages[$j]['TIME_STAMP'] = getTimeStamp($tmpdate);
244 $messages[$j]['DATE_STRING'] = getDateString($messages[$j]['TIME_STAMP']);
245 $messages[$j]['ID'] = $id[$j];
246 $messages[$j]['FROM'] = decodeHeader($from[$j]);
247 $messages[$j]['FROM-SORT'] = strtolower(sqimap_find_displayable_name(decodeHeader($from[$j])));
248 $messages[$j]['SUBJECT'] = decodeHeader($subject[$j]);
249 $messages[$j]['SUBJECT-SORT'] = strtolower(decodeHeader($subject[$j]));
250 $messages[$j]['TO'] = decodeHeader($to[$j]);
251 $messages[$j]['PRIORITY'] = $priority[$j];
252 $messages[$j]['CC'] = $cc[$j];
253 $messages[$j]['SIZE'] = $size[$j];
254 $messages[$j]['TYPE0'] = $type[$j];
256 # fix SUBJECT-SORT to remove Re:
257 $re_abbr = # Add more here!
258 'vedr|sv|' . # Danish
260 if (eregi("^($re_abbr):[ ]*(.*)$", $messages[$j]['SUBJECT-SORT'], $regs))
261 $messages[$j]['SUBJECT-SORT'] = $regs[2];
264 while ($num < count($flags[$j])) {
265 if ($flags[$j][$num] == 'Deleted') {
266 $messages[$j]['FLAG_DELETED'] = true;
268 elseif ($flags[$j][$num] == 'Answered') {
269 $messages[$j]['FLAG_ANSWERED'] = true;
271 elseif ($flags[$j][$num] == 'Seen') {
272 $messages[$j]['FLAG_SEEN'] = true;
274 elseif ($flags[$j][$num] == 'Flagged') {
275 $messages[$j]['FLAG_FLAGGED'] = true;
282 /* Only ignore messages flagged as deleted if we are using a
283 * trash folder or auto_expunge */
284 if (((isset($move_to_trash) && $move_to_trash)
285 ||
(isset($auto_expunge) && $auto_expunge)) && $sort != 6)
287 /** Find and remove the ones that are deleted */
290 while ($j < $numMessages) {
291 if (isset($messages[$j]['FLAG_DELETED']) && $messages[$j]['FLAG_DELETED'] == true) {
295 $msgs[$i] = $messages[$j];
302 if (! isset($messages))
308 // There's gotta be messages in the array for it to sort them.
309 if ($numMessages > 0 && ! $use_cache) {
310 /** 0 = Date (up) 4 = Subject (up)
311 ** 1 = Date (dn) 5 = Subject (dn)
315 session_unregister("msgs");
316 if (($sort == 0) ||
($sort == 1))
317 $msort = array_cleave ($msgs, 'TIME_STAMP');
318 if (($sort == 2) ||
($sort == 3))
319 $msort = array_cleave ($msgs, 'FROM-SORT');
320 if (($sort == 4) ||
($sort == 5))
321 $msort = array_cleave ($msgs, 'SUBJECT-SORT');
332 session_register('msort');
334 displayMessageArray($imapConnection, $numMessages, $startMessage, $msgs, $msort, $mailbox, $sort, $color,$show_num);
335 session_register('msgs');
338 // generic function to convert the msgs array into an HTML table
339 function displayMessageArray($imapConnection, $numMessages, $startMessage, &$msgs, $msort, $mailbox, $sort, $color,$show_num) {
340 global $folder_prefix, $sent_folder;
341 global $imapServerAddress;
342 global $index_order, $real_endMessage, $real_startMessage, $checkall;
344 // if cache isn't already set, do it now
345 if (!session_is_registered('msgs'))
346 session_register('msgs');
347 if (!session_is_registered('msort'))
348 session_register('msort');
350 if ($startMessage +
($show_num - 1) < $numMessages) {
351 $endMessage = $startMessage +
($show_num-1);
353 $endMessage = $numMessages;
356 if ($endMessage < $startMessage) {
357 $startMessage = $startMessage - $show_num;
358 if ($startMessage < 1)
362 $nextGroup = $startMessage +
$show_num;
363 $prevGroup = $startMessage - $show_num;
364 $urlMailbox = urlencode($mailbox);
366 do_hook('mailbox_index_before');
369 if ($startMessage < $endMessage) {
370 $Message = _("Viewing messages") ." <B>$startMessage</B> ". _("to") ." <B>$endMessage</B> ($numMessages " . _("total") . ")\n";
371 } elseif ($startMessage == $endMessage) {
372 $Message = _("Viewing message") ." <B>$startMessage</B> ($numMessages " . _("total") . ")\n";
381 if (($nextGroup <= $numMessages) && ($prevGroup >= 0)) {
382 $More = "<A HREF=\"right_main.php?use_mailbox_cache=$use&startMessage=$prevGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Previous") ."</A> | \n";
383 $More .= "<A HREF=\"right_main.php?use_mailbox_cache=$use&&startMessage=$nextGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Next") ."</A>\n";
385 elseif (($nextGroup > $numMessages) && ($prevGroup >= 0)) {
386 $More = "<A HREF=\"right_main.php?use_mailbox_cache=$use&startMessage=$prevGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Previous") ."</A> | \n";
387 $More .= "<FONT COLOR=\"$color[9]\">"._("Next")."</FONT>\n";
389 elseif (($nextGroup <= $numMessages) && ($prevGroup < 0)) {
390 $More = "<FONT COLOR=\"$color[9]\">"._("Previous")."</FONT> | \n";
391 $More .= "<A HREF=\"right_main.php?use_mailbox_cache=$use&startMessage=$nextGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Next") ."</A>\n";
396 mail_message_listing_beginning($imapConnection,
397 "move_messages.php?msg=$msg&mailbox=$urlMailbox&startMessage=$startMessage",
398 $mailbox, $sort, $Message, $More, $startMessage);
400 $groupNum = $startMessage %
($show_num - 1);
401 $real_startMessage = $startMessage;
403 if ($endMessage - $startMessage < $show_num - 1) {
404 $endMessage = $endMessage - $startMessage +
1;
406 } else if ($startMessage > $show_num) {
407 $endMessage = $show_num;
412 $endVar = $endMessage +
1;
414 // loop through and display the info for each message.
415 $t = 0; // $t is used for the checkbox number
416 if ($numMessages == 0) { // if there's no messages in this folder
417 echo "<TR><TD BGCOLOR=\"$color[4]\" COLSPAN=" . count($index_order);
418 echo "><CENTER><BR><B>". _("THIS FOLDER IS EMPTY") ."</B><BR> </CENTER></TD></TR>";
419 } else if ($startMessage == $endMessage) { // if there's only one message in the box, handle it different.
430 } while (isset ($key) && ($k < $i));
431 printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $real_startMessage, 0, 0);
441 } while (isset ($key) && ($k < $i));
444 printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $real_startMessage, 0, 0);
449 } while ($i && $i < $endVar);
455 echo "<TR BGCOLOR=\"$color[4]\"><TD>";
456 echo '<table width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td>';
457 echo "$More</td><td align=right>\n";
458 if (!$startMessage) $startMessage=1;
459 ShowSelectAllLink($startMessage, $sort);
461 echo '</td></tr></table>';
463 echo '</table>'; /** End of message-list table */
465 do_hook('mailbox_index_after');
468 /* Displays the standard message list header.
469 * To finish the table, you need to do a "</table></table>";
470 * $moveURL is the URL to submit the delete/move form to
471 * $mailbox is the current mailbox
472 * $sort is the current sorting method (-1 for no sorting available [searches])
473 * $Message is a message that is centered on top of the list
474 * $More is a second line that is left aligned
476 function mail_message_listing_beginning($imapConnection, $moveURL,
477 $mailbox = '', $sort = -1, $Message = '', $More = '', $startMessage = 1)
479 global $color, $index_order, $auto_expunge, $move_to_trash;
480 global $checkall, $sent_folder;
481 $urlMailbox = urlencode($mailbox);
483 /** This is the beginning of the message list table. It wraps around all messages */
484 echo '<TABLE WIDTH="100%" BORDER="0" CELLPADDING="2" CELLSPACING="0">';
488 echo "<TR BGCOLOR=\"$color[4]\"><TD align=center>$Message</td></tr>\n";
491 echo "<TR BGCOLOR=\"$color[4]\"><TD>";
492 echo '<table width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td>';
493 echo "$More</td><td align=right>\n";
494 ShowSelectAllLink($startMessage, $sort);
496 echo '</td></tr></table>';
499 /** The delete and move options */
500 echo "<TR><TD BGCOLOR=\"$color[0]\">";
502 echo "\n\n\n<FORM name=messageList method=post action=\"$moveURL\">\n";
503 echo "<TABLE BGCOLOR=\"$color[0]\" COLS=2 BORDER=0 cellpadding=0 cellspacing=0 width=100%>\n";
505 echo " <TD WIDTH=60% ALIGN=LEFT VALIGN=CENTER>\n";
508 echo ' <NOBR><SMALL>'. _("Move selected to:") .'</SMALL>';
509 echo ' <TT><SMALL><SELECT NAME="targetMailbox">';
511 $boxes = sqimap_mailbox_list($imapConnection);
512 for ($i = 0; $i < count($boxes); $i++
) {
513 if (!in_array("noselect", $boxes[$i]['flags'])) {
514 $box = $boxes[$i]['unformatted'];
515 $box2 = str_replace(' ', ' ', $boxes[$i]['unformatted-disp']);
516 echo " <OPTION VALUE=\"$box\">$box2</option>\n";
519 echo ' </SELECT></SMALL></TT>';
520 echo ' <SMALL><INPUT TYPE=SUBMIT NAME="moveButton" VALUE="'. _("Move") ."\"></SMALL></NOBR>\n";
522 echo " <TD WIDTH=40% ALIGN=RIGHT>\n";
523 if (! $auto_expunge) {
524 echo ' <NOBR><SMALL><INPUT TYPE=SUBMIT NAME="expungeButton" VALUE="'. _("Expunge") .'"> '. _("mailbox") ."</SMALL></NOBR> \n";
526 echo " <NOBR><SMALL><INPUT TYPE=SUBMIT VALUE=\"". _("Delete") ."\"> ". _("checked messages") ."</SMALL></NOBR>\n";
531 do_hook('mailbox_form_before');
534 echo "<TR><TD BGCOLOR=\"$color[0]\">";
535 echo "<TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=1 BGCOLOR=\"$color[0]\">";
536 echo "<TR BGCOLOR=\"$color[5]\" ALIGN=\"center\">";
538 $urlMailbox=urlencode($mailbox);
541 for ($i=1; $i <= count($index_order); $i++
) {
542 switch ($index_order[$i]) {
545 echo ' <TD WIDTH="1%"><B> </B></TD>';
549 if ($mailbox == $sent_folder)
550 echo ' <TD WIDTH="30%"><B>'. _("To") .'</B>';
552 echo ' <TD WIDTH="30%"><B>'. _("From") .'</B>';
555 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";
557 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";
559 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";
564 echo ' <TD nowrap WIDTH="1%"><B>'. _("Date") .'</B>';
566 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";
568 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";
570 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";
572 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";
577 echo ' <TD WIDTH=%><B>'. _("Subject") ."</B>\n";
579 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";
581 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";
583 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";
588 echo ' <TD WIDTH="1%"><b>' . _("Size")."</b></TD>\n";
595 function ShowSelectAllLink($startMessage, $sort)
597 global $checkall, $PHP_SELF, $what, $where, $mailbox;
599 echo "\n<A HREF=\"$PHP_SELF?mailbox=" . urlencode($mailbox) .
600 "&startMessage=$startMessage&sort=$sort&";
601 if ( isset($checkall) && $checkall == '1')
605 if (isset($where) && isset($what))
606 echo "&where=" . urlencode($where) . "&what=" . urlencode($what);
608 if (isset($checkall) && $checkall == '1')
609 echo _("Unselect All");
611 echo _("Select All");
615 function processSubject($subject)
617 // Shouldn't ever happen -- caught too many times in the IMAP functions
619 return _("(no subject)");
621 if (strlen($subject) <= 55)
624 $ent_strlen=strlen($subject);
627 // see if this is entities-encoded string
628 // If so, Iterate through the whole string, find out
629 // the real number of characters, and if more
630 // than 55, substr with an updated trim value.
631 while (($ent_loc = strpos($subject, '&', $ent_offset)) !== false &&
632 ($ent_loc_end = strpos($subject, ';', $ent_loc)) !== false)
634 $trim_val +
= ($ent_loc_end-$ent_loc)+
1;
635 $ent_strlen -= $ent_loc_end-$ent_loc;
636 $ent_offset = $ent_loc_end+
1;
639 if ($ent_strlen <= 55)
642 return substr($subject, 0, $trim_val) . '...';