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 echo substr($subject, 0, 50) . '...';
119 echo "$flag_end</a>$bold_end</td>\n";
123 echo " <td bgcolor=$hlt_color align=center width=1% nowrap><b><small>\n";
124 if (isset($msg['FLAG_ANSWERED']) &&
125 $msg['FLAG_ANSWERED'] == true) {
129 if ($msg['TYPE0'] == 'multipart') {
133 if (ereg('(1|2)',substr($msg['PRIORITY'],0,1))) {
134 echo "<font color=$color[1]>!</font>\n";
137 if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED']) {
138 echo "<font color=\"$color[1]\">D</font>\n";
142 if (!$stuff) echo " \n";
143 echo "</small></b></td>\n";
146 echo " <td bgcolor=$hlt_color width=1%>$bold$fontstr".show_readable_size($msg['SIZE'])."$fontstr_end$bold_end</td>\n";
156 ** This function loops through a group of messages in the mailbox and shows them
158 function showMessagesForMailbox($imapConnection, $mailbox, $numMessages, $startMessage, $sort, $color,$show_num, $use_cache) {
159 global $msgs, $msort;
161 global $message_highlight_list;
162 global $auto_expunge;
164 if ($auto_expunge == true) sqimap_mailbox_expunge($imapConnection, $mailbox, false);
165 sqimap_mailbox_select($imapConnection, $mailbox);
169 if ($numMessages >= 1) {
171 for ($q = 0; $q < $numMessages; $q++
) {
172 if($mailbox == $sent_folder)
173 $hdr = sqimap_get_small_header ($imapConnection, $q+
1, true);
175 $hdr = sqimap_get_small_header ($imapConnection, $q+
1, false);
177 $from[$q] = $hdr->from
;
178 $date[$q] = $hdr->date
;
179 $subject[$q] = $hdr->subject
;
181 $priority[$q] = $hdr->priority
;
183 $size[$q] = $hdr->size
;
184 $type[$q] = $hdr->type0
;
185 $flags[$q] = sqimap_get_flags ($imapConnection, $q+
1);
189 // if it's not sorted
190 if ($startMessage +
($show_num - 1) < $numMessages) {
191 $endMessage = $startMessage +
($show_num-1);
193 $endMessage = $numMessages;
196 if ($endMessage < $startMessage) {
197 $startMessage = $startMessage - $show_num;
198 if ($startMessage < 1)
203 $real_startMessage = $numMessages - $startMessage +
1;
204 $real_endMessage = $numMessages - $startMessage - $show_num;
205 if ($real_endMessage <= 0)
206 $real_endMessage = 1;
209 for ($q = $real_startMessage; $q >= $real_endMessage; $q--) {
210 if($mailbox == $sent_folder)
211 $hdr = sqimap_get_small_header ($imapConnection, $q, true);
213 $hdr = sqimap_get_small_header ($imapConnection, $q, false);
215 $from[$j] = $hdr->from
;
216 $date[$j] = $hdr->date
;
217 $subject[$j] = $hdr->subject
;
219 $priority[$j] = $hdr->priority
;
221 $size[$j] = $hdr->size
;
222 $type[$j] = $hdr->type0
;
223 $flags[$j] = sqimap_get_flags ($imapConnection, $q);
232 $end = $startMessage +
$show_num - 1;
236 if ($end > $numMessages) $end = $numMessages;
238 $date[$j] = ereg_replace(' ', ' ', $date[$j]);
239 $tmpdate = explode(' ', trim($date[$j]));
241 $messages[$j]['TIME_STAMP'] = getTimeStamp($tmpdate);
242 $messages[$j]['DATE_STRING'] = getDateString($messages[$j]['TIME_STAMP']);
243 $messages[$j]['ID'] = $id[$j];
244 $messages[$j]['FROM'] = decodeHeader($from[$j]);
245 $messages[$j]['FROM-SORT'] = strtolower(sqimap_find_displayable_name(decodeHeader($from[$j])));
246 $messages[$j]['SUBJECT'] = decodeHeader($subject[$j]);
247 $messages[$j]['SUBJECT-SORT'] = strtolower(decodeHeader($subject[$j]));
248 $messages[$j]['TO'] = decodeHeader($to[$j]);
249 $messages[$j]['PRIORITY'] = $priority[$j];
250 $messages[$j]['CC'] = $cc[$j];
251 $messages[$j]['SIZE'] = $size[$j];
252 $messages[$j]['TYPE0'] = $type[$j];
254 # fix SUBJECT-SORT to remove Re:
255 $re_abbr = # Add more here!
256 'vedr|sv|' . # Danish
258 if (eregi("^($re_abbr):[ ]*(.*)$", $messages[$j]['SUBJECT-SORT'], $regs))
259 $messages[$j]['SUBJECT-SORT'] = $regs[2];
262 while ($num < count($flags[$j])) {
263 if ($flags[$j][$num] == 'Deleted') {
264 $messages[$j]['FLAG_DELETED'] = true;
266 elseif ($flags[$j][$num] == 'Answered') {
267 $messages[$j]['FLAG_ANSWERED'] = true;
269 elseif ($flags[$j][$num] == 'Seen') {
270 $messages[$j]['FLAG_SEEN'] = true;
272 elseif ($flags[$j][$num] == 'Flagged') {
273 $messages[$j]['FLAG_FLAGGED'] = true;
280 /* Only ignore messages flagged as deleted if we are using a
281 * trash folder or auto_expunge */
282 if (((isset($move_to_trash) && $move_to_trash)
283 ||
(isset($auto_expunge) && $auto_expunge)) && $sort != 6)
285 /** Find and remove the ones that are deleted */
288 while ($j < $numMessages) {
289 if ($messages[$j]['FLAG_DELETED'] == true) {
293 $msgs[$i] = $messages[$j];
300 if (! isset($messages))
306 // There's gotta be messages in the array for it to sort them.
307 if ($numMessages > 0 && ! $use_cache) {
308 /** 0 = Date (up) 4 = Subject (up)
309 ** 1 = Date (dn) 5 = Subject (dn)
313 session_unregister("msgs");
314 if (($sort == 0) ||
($sort == 1))
315 $msort = array_cleave ($msgs, 'TIME_STAMP');
316 if (($sort == 2) ||
($sort == 3))
317 $msort = array_cleave ($msgs, 'FROM-SORT');
318 if (($sort == 4) ||
($sort == 5))
319 $msort = array_cleave ($msgs, 'SUBJECT-SORT');
330 session_register('msort');
332 displayMessageArray($imapConnection, $numMessages, $startMessage, $msgs, $msort, $mailbox, $sort, $color,$show_num);
333 session_register('msgs');
336 // generic function to convert the msgs array into an HTML table
337 function displayMessageArray($imapConnection, $numMessages, $startMessage, &$msgs, $msort, $mailbox, $sort, $color,$show_num) {
338 global $folder_prefix, $sent_folder;
339 global $imapServerAddress;
340 global $index_order, $real_endMessage, $real_startMessage, $checkall;
342 // if cache isn't already set, do it now
343 if (!session_is_registered('msgs'))
344 session_register('msgs');
345 if (!session_is_registered('msort'))
346 session_register('msort');
348 if ($startMessage +
($show_num - 1) < $numMessages) {
349 $endMessage = $startMessage +
($show_num-1);
351 $endMessage = $numMessages;
354 if ($endMessage < $startMessage) {
355 $startMessage = $startMessage - $show_num;
356 if ($startMessage < 1)
360 $nextGroup = $startMessage +
$show_num;
361 $prevGroup = $startMessage - $show_num;
362 $urlMailbox = urlencode($mailbox);
364 do_hook('mailbox_index_before');
367 if ($startMessage < $endMessage) {
368 $Message = _("Viewing messages") ." <B>$startMessage</B> ". _("to") ." <B>$endMessage</B> ($numMessages " . _("total") . ")\n";
369 } elseif ($startMessage == $endMessage) {
370 $Message = _("Viewing message") ." <B>$startMessage</B> ($numMessages " . _("total") . ")\n";
379 if (($nextGroup <= $numMessages) && ($prevGroup >= 0)) {
380 $More = "<A HREF=\"right_main.php?use_mailbox_cache=$use&startMessage=$prevGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Previous") ."</A> | \n";
381 $More .= "<A HREF=\"right_main.php?use_mailbox_cache=$use&&startMessage=$nextGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Next") ."</A>\n";
383 elseif (($nextGroup > $numMessages) && ($prevGroup >= 0)) {
384 $More = "<A HREF=\"right_main.php?use_mailbox_cache=$use&startMessage=$prevGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Previous") ."</A> | \n";
385 $More .= "<FONT COLOR=\"$color[9]\">"._("Next")."</FONT>\n";
387 elseif (($nextGroup <= $numMessages) && ($prevGroup < 0)) {
388 $More = "<FONT COLOR=\"$color[9]\">"._("Previous")."</FONT> | \n";
389 $More .= "<A HREF=\"right_main.php?use_mailbox_cache=$use&startMessage=$nextGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Next") ."</A>\n";
394 mail_message_listing_beginning($imapConnection,
395 "move_messages.php?msg=$msg&mailbox=$urlMailbox&startMessage=$startMessage",
396 $mailbox, $sort, $Message, $More, $startMessage);
398 $groupNum = $startMessage %
($show_num - 1);
399 $real_startMessage = $startMessage;
401 if ($endMessage - $startMessage < $show_num - 1) {
402 $endMessage = $endMessage - $startMessage +
1;
404 } else if ($startMessage > $show_num) {
405 $endMessage = $show_num;
410 $endVar = $endMessage +
1;
412 // loop through and display the info for each message.
413 $t = 0; // $t is used for the checkbox number
414 if ($numMessages == 0) { // if there's no messages in this folder
415 echo "<TR><TD BGCOLOR=\"$color[4]\" COLSPAN=" . count($index_order);
416 echo "><CENTER><BR><B>". _("THIS FOLDER IS EMPTY") ."</B><BR> </CENTER></TD></TR>";
417 } else if ($startMessage == $endMessage) { // if there's only one message in the box, handle it different.
428 } while (isset ($key) && ($k < $i));
429 printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $real_startMessage, 0, 0);
439 } while (isset ($key) && ($k < $i));
442 printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $real_startMessage, 0, 0);
447 } while ($i && $i < $endVar);
453 echo "<TR BGCOLOR=\"$color[4]\"><TD>";
454 echo '<table width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td>';
455 echo "$More</td><td align=right>\n";
456 if (!$startMessage) $startMessage=1;
457 if ( $checkall == '1')
458 echo "\n<A HREF=\"right_main.php?mailbox=$urlMailbox&startMessage=$real_startMessage&sort=$sort\">" . _("Unselect All") . "</A>\n";
460 echo "\n<A HREF=\"right_main.php?mailbox=$urlMailbox&startMessage=$real_startMessage&sort=$sort&checkall=1\">" . _("Select All") . "</A>\n";
462 echo '</td></tr></table>';
464 echo '</table>'; /** End of message-list table */
466 do_hook('mailbox_index_after');
469 /* Displays the standard message list header.
470 * To finish the table, you need to do a "</table></table>";
471 * $moveURL is the URL to submit the delete/move form to
472 * $mailbox is the current mailbox
473 * $sort is the current sorting method (-1 for no sorting available [searches])
474 * $Message is a message that is centered on top of the list
475 * $More is a second line that is left aligned
477 function mail_message_listing_beginning($imapConnection, $moveURL,
478 $mailbox = '', $sort = -1, $Message = '', $More = '', $startMessage = 1)
480 global $color, $index_order, $auto_expunge, $move_to_trash;
481 global $checkall, $sent_folder;
482 $urlMailbox = urlencode($mailbox);
484 /** This is the beginning of the message list table. It wraps around all messages */
485 echo '<TABLE WIDTH="100%" BORDER="0" CELLPADDING="2" CELLSPACING="0">';
489 echo "<TR BGCOLOR=\"$color[4]\"><TD align=center>$Message</td></tr>\n";
492 echo "<TR BGCOLOR=\"$color[4]\"><TD>";
493 echo '<table width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td>';
494 echo "$More</td><td align=right>\n";
495 if ( $checkall == '1')
496 echo "\n<A HREF=\"right_main.php?mailbox=$urlMailbox&startMessage=$startMessage&sort=$sort\">" . _("Unselect All") . "</A>\n";
498 echo "\n<A HREF=\"right_main.php?mailbox=$urlMailbox&startMessage=$startMessage&sort=$sort&checkall=1\">" . _("Select All") . "</A>\n";
500 echo '</td></tr></table>';
503 /** The delete and move options */
504 echo "<TR><TD BGCOLOR=\"$color[0]\">";
506 echo "\n\n\n<FORM name=messageList method=post action=\"$moveURL\">\n";
507 echo "<TABLE BGCOLOR=\"$color[0]\" COLS=2 BORDER=0 cellpadding=0 cellspacing=0 width=100%>\n";
509 echo " <TD WIDTH=60% ALIGN=LEFT VALIGN=CENTER>\n";
512 echo ' <NOBR><SMALL>'. _("Move selected to:") .'</SMALL>';
513 echo ' <TT><SMALL><SELECT NAME="targetMailbox">';
515 $boxes = sqimap_mailbox_list($imapConnection);
516 for ($i = 0; $i < count($boxes); $i++
) {
517 if ($boxes[$i]['flags'][0] != 'noselect' &&
518 $boxes[$i]['flags'][1] != 'noselect' &&
519 $boxes[$i]['flags'][2] != 'noselect') {
520 $box = $boxes[$i]['unformatted'];
521 $box2 = replace_spaces($boxes[$i]['unformatted-disp']);
522 echo " <OPTION VALUE=\"$box\">$box2</option>\n";
525 echo ' </SELECT></SMALL></TT>';
526 echo ' <SMALL><INPUT TYPE=SUBMIT NAME="moveButton" VALUE="'. _("Move") ."\"></SMALL></NOBR>\n";
528 echo " <TD WIDTH=40% ALIGN=RIGHT>\n";
529 if (! $auto_expunge) {
530 echo ' <NOBR><SMALL><INPUT TYPE=SUBMIT NAME="expungeButton" VALUE="'. _("Expunge") .'"> '. _("mailbox") ."</SMALL></NOBR> \n";
532 echo " <NOBR><SMALL><INPUT TYPE=SUBMIT VALUE=\"". _("Delete") ."\"> ". _("checked messages") ."</SMALL></NOBR>\n";
537 do_hook('mailbox_form_before');
540 echo "<TR><TD BGCOLOR=\"$color[0]\">";
541 echo "<TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=1 BGCOLOR=\"$color[0]\">";
542 echo "<TR BGCOLOR=\"$color[5]\" ALIGN=\"center\">";
544 $urlMailbox=urlencode($mailbox);
547 for ($i=1; $i <= count($index_order); $i++
) {
548 switch ($index_order[$i]) {
551 echo ' <TD WIDTH="1%"><B> </B></TD>';
555 if ($mailbox == $sent_folder)
556 echo ' <TD WIDTH="30%"><B>'. _("To") .'</B>';
558 echo ' <TD WIDTH="30%"><B>'. _("From") .'</B>';
561 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";
563 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";
565 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 nowrap WIDTH="1%"><B>'. _("Date") .'</B>';
572 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";
574 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";
576 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";
578 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 WIDTH=%><B>'. _("Subject") ."</B>\n";
585 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";
587 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";
589 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 WIDTH="1%"><b>' . _("Size")."</b></TD>\n";