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;
21 if (!isset($GLOBALS["row_count"])) {
22 $GLOBALS["row_count"] = 0;
24 $GLOBALS["row_count"]++
;
25 if ($GLOBALS["row_count"] %
2) {
26 if (!isset($color[12])) $color[12] = "#EAEAEA";
27 $color_string = $color[12];
29 $color_string = $color[4];
34 $senderName = sqimap_find_displayable_name($msg['FROM']);
35 $urlMailbox = urlencode($mailbox);
36 $subject = processSubject($msg['SUBJECT']);
40 if (isset($msg['FLAG_FLAGGED']) && $msg['FLAG_FLAGGED'] == true)
42 $flag = "<font color=$color[2]>";
43 $flag_end = '</font>';
50 if (!isset($msg['FLAG_SEEN']) ||
$msg['FLAG_SEEN'] == false)
60 if ($mailbox == $sent_folder)
70 if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED'])
72 $fontstr = "<font color=\"$color[9]\">";
73 $fontstr_end = '</font>';
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'];
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'];
95 if (!isset($hlt_color))
96 $hlt_color = $color_string;
98 if ($where && $what) {
99 $search_stuff = '&where='.urlencode($where).'&what='.urlencode($what);
103 $checked = ' checked';
107 for ($i=1; $i <= count($index_order); $i++
) {
108 switch ($index_order[$i]) {
110 echo " <td width=1% bgcolor=$hlt_color align=center><input type=checkbox name=\"msg[$t]\" value=".$msg["ID"]."$checked></TD>\n";
113 echo " <td width=30% bgcolor=$hlt_color>$italic$bold$flag$fontstr$senderName$fontstr_end$flag_end$bold_end$italic_end</td>\n";
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";
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";
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) {
133 if ($msg['TYPE0'] == 'multipart') {
137 if (ereg('(1|2)',substr($msg['PRIORITY'],0,1))) {
138 echo "<font color=$color[1]>!</font>\n";
141 if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED']) {
142 echo "<font color=\"$color[1]\">D</font>\n";
146 if (!$stuff) echo " \n";
147 echo "</small></b></td>\n";
150 echo " <td bgcolor=$hlt_color width=1%>$bold$fontstr".show_readable_size($msg['SIZE'])."$fontstr_end$bold_end</td>\n";
160 ** This function loops through a group of messages in the mailbox and shows them
162 function showMessagesForMailbox($imapConnection, $mailbox, $numMessages, $startMessage, $sort, $color,$show_num, $use_cache) {
163 global $msgs, $msort;
165 global $message_highlight_list;
166 global $auto_expunge;
168 if ($auto_expunge == true) sqimap_mailbox_expunge($imapConnection, $mailbox, false);
169 sqimap_mailbox_select($imapConnection, $mailbox);
173 if ($numMessages >= 1) {
175 for ($q = 0; $q < $numMessages; $q++
) {
176 if($mailbox == $sent_folder)
177 $hdr = sqimap_get_small_header ($imapConnection, $q+
1, true);
179 $hdr = sqimap_get_small_header ($imapConnection, $q+
1, false);
181 $from[$q] = $hdr->from
;
182 $date[$q] = $hdr->date
;
183 $subject[$q] = $hdr->subject
;
185 $priority[$q] = $hdr->priority
;
187 $size[$q] = $hdr->size
;
188 $type[$q] = $hdr->type0
;
189 $flags[$q] = sqimap_get_flags ($imapConnection, $q+
1);
193 // if it's not sorted
194 if ($startMessage +
($show_num - 1) < $numMessages) {
195 $endMessage = $startMessage +
($show_num-1);
197 $endMessage = $numMessages;
200 if ($endMessage < $startMessage) {
201 $startMessage = $startMessage - $show_num;
202 if ($startMessage < 1)
207 $real_startMessage = $numMessages - $startMessage +
1;
208 $real_endMessage = $numMessages - $startMessage - $show_num;
209 if ($real_endMessage <= 0)
210 $real_endMessage = 1;
213 for ($q = $real_startMessage; $q >= $real_endMessage; $q--) {
214 if($mailbox == $sent_folder)
215 $hdr = sqimap_get_small_header ($imapConnection, $q, true);
217 $hdr = sqimap_get_small_header ($imapConnection, $q, false);
219 $from[$j] = $hdr->from
;
220 $date[$j] = $hdr->date
;
221 $subject[$j] = $hdr->subject
;
223 $priority[$j] = $hdr->priority
;
225 $size[$j] = $hdr->size
;
226 $type[$j] = $hdr->type0
;
227 $flags[$j] = sqimap_get_flags ($imapConnection, $q);
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;
242 $end_loop = $show_num;
247 while ($j < $end_loop) {
248 if (isset($date[$j])) {
249 $date[$j] = ereg_replace(' ', ' ', $date[$j]);
250 $tmpdate = explode(' ', trim($date[$j]));
252 $tmpdate = $date = array("","","","","","");
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];
268 # fix SUBJECT-SORT to remove Re:
269 $re_abbr = # Add more here!
270 'vedr|sv|' . # Danish
272 if (eregi("^($re_abbr):[ ]*(.*)$", $messages[$j]['SUBJECT-SORT'], $regs))
273 $messages[$j]['SUBJECT-SORT'] = $regs[2];
276 while ($num < count($flags[$j])) {
277 if ($flags[$j][$num] == 'Deleted') {
278 $messages[$j]['FLAG_DELETED'] = true;
280 elseif ($flags[$j][$num] == 'Answered') {
281 $messages[$j]['FLAG_ANSWERED'] = true;
283 elseif ($flags[$j][$num] == 'Seen') {
284 $messages[$j]['FLAG_SEEN'] = true;
286 elseif ($flags[$j][$num] == 'Flagged') {
287 $messages[$j]['FLAG_FLAGGED'] = true;
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)
299 /** Find and remove the ones that are deleted */
302 while ($j < $numMessages) {
303 if (isset($messages[$j]['FLAG_DELETED']) && $messages[$j]['FLAG_DELETED'] == true) {
307 $msgs[$i] = $messages[$j];
314 if (! isset($messages))
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)
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');
344 session_register('msort');
346 displayMessageArray($imapConnection, $numMessages, $startMessage, $msgs, $msort, $mailbox, $sort, $color,$show_num);
347 session_register('msgs');
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;
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');
362 if ($startMessage +
($show_num - 1) < $numMessages) {
363 $endMessage = $startMessage +
($show_num-1);
365 $endMessage = $numMessages;
368 if ($endMessage < $startMessage) {
369 $startMessage = $startMessage - $show_num;
370 if ($startMessage < 1)
374 $nextGroup = $startMessage +
$show_num;
375 $prevGroup = $startMessage - $show_num;
376 $urlMailbox = urlencode($mailbox);
378 do_hook('mailbox_index_before');
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";
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";
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";
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";
408 mail_message_listing_beginning($imapConnection,
409 "move_messages.php?msg=$msg&mailbox=$urlMailbox&startMessage=$startMessage",
410 $mailbox, $sort, $Message, $More, $startMessage);
412 $groupNum = $startMessage %
($show_num - 1);
413 $real_startMessage = $startMessage;
415 if ($endMessage - $startMessage < $show_num - 1) {
416 $endMessage = $endMessage - $startMessage +
1;
418 } else if ($startMessage > $show_num) {
419 $endMessage = $show_num;
424 $endVar = $endMessage +
1;
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> </CENTER></TD></TR>";
431 } else if ($startMessage == $endMessage) { // if there's only one message in the box, handle it different.
442 } while (isset ($key) && ($k < $i));
443 printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $real_startMessage, 0, 0);
453 } while (isset ($key) && ($k < $i));
456 printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $real_startMessage, 0, 0);
461 } while ($i && $i < $endVar);
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);
473 echo '</td></tr></table>';
475 echo '</table>'; /** End of message-list table */
477 do_hook('mailbox_index_after');
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
488 function mail_message_listing_beginning($imapConnection, $moveURL,
489 $mailbox = '', $sort = -1, $Message = '', $More = '', $startMessage = 1)
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">';
499 echo "<TR BGCOLOR=\"$color[4]\"><TD align=center>$Message</td></tr>\n";
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);
507 echo '</td></tr></table>';
510 /** The delete and move options */
511 echo "<TR><TD BGCOLOR=\"$color[0]\">";
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";
516 echo " <TD WIDTH=60% ALIGN=LEFT VALIGN=CENTER>\n";
519 echo ' <NOBR><SMALL>'. _("Move selected to:") .'</SMALL>';
520 echo ' <TT><SMALL><SELECT NAME="targetMailbox">';
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(' ', ' ', $boxes[$i]['unformatted-disp']);
527 echo " <OPTION VALUE=\"$box\">$box2</option>\n";
530 echo ' </SELECT></SMALL></TT>';
531 echo ' <SMALL><INPUT TYPE=SUBMIT NAME="moveButton" VALUE="'. _("Move") ."\"></SMALL></NOBR>\n";
533 echo " <TD WIDTH=40% ALIGN=RIGHT>\n";
534 if (! $auto_expunge) {
535 echo ' <NOBR><SMALL><INPUT TYPE=SUBMIT NAME="expungeButton" VALUE="'. _("Expunge") .'"> '. _("mailbox") ."</SMALL></NOBR> \n";
537 echo " <NOBR><SMALL><INPUT TYPE=SUBMIT VALUE=\"". _("Delete") ."\"> ". _("checked messages") ."</SMALL></NOBR>\n";
542 do_hook('mailbox_form_before');
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\">";
549 $urlMailbox=urlencode($mailbox);
552 for ($i=1; $i <= count($index_order); $i++
) {
553 switch ($index_order[$i]) {
556 echo ' <TD WIDTH="1%"><B> </B></TD>';
560 if ($mailbox == $sent_folder)
561 echo ' <TD WIDTH="30%"><B>'. _("To") .'</B>';
563 echo ' <TD WIDTH="30%"><B>'. _("From") .'</B>';
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";
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";
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";
575 echo ' <TD nowrap WIDTH="1%"><B>'. _("Date") .'</B>';
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";
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";
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";
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";
588 echo ' <TD><B>'. _("Subject") ."</B>\n";
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";
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";
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";
599 echo ' <TD WIDTH="1%"><b>' . _("Size")."</b></TD>\n";
606 function ShowSelectAllLink($startMessage, $sort)
608 global $checkall, $PHP_SELF, $what, $where, $mailbox;
610 echo "\n<A HREF=\"$PHP_SELF?mailbox=" . urlencode($mailbox) .
611 "&startMessage=$startMessage&sort=$sort&";
612 if ( isset($checkall) && $checkall == '1')
616 if (isset($where) && isset($what))
617 echo "&where=" . urlencode($where) . "&what=" . urlencode($what);
619 if (isset($checkall) && $checkall == '1')
620 echo _("Unselect All");
622 echo _("Select All");
626 function processSubject($subject)
628 // Shouldn't ever happen -- caught too many times in the IMAP functions
630 return _("(no subject)");
632 if (strlen($subject) <= 55)
635 $ent_strlen=strlen($subject);
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)
645 $trim_val +
= ($ent_loc_end-$ent_loc)+
1;
646 $ent_strlen -= $ent_loc_end-$ent_loc;
647 $ent_offset = $ent_loc_end+
1;
650 if ($ent_strlen <= 55)
653 return substr($subject, 0, $trim_val) . '...';