6 ** This contains functions that display mailbox information, such as the
7 ** table row that has sender, date, subject, etc...
12 if (defined('mailbox_display_php'))
14 define('mailbox_display_php', true);
16 function printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $startMessage, $where, $what) {
18 global $color, $msgs, $msort;
20 global $message_highlight_list;
23 if (!isset($GLOBALS["row_count"])) {
24 $GLOBALS["row_count"] = 0;
26 $GLOBALS["row_count"]++
;
27 if ($GLOBALS["row_count"] %
2) {
28 if (!isset($color[12])) $color[12] = "#EAEAEA";
29 $color_string = $color[12];
31 $color_string = $color[4];
36 $senderName = sqimap_find_displayable_name($msg['FROM']);
37 $urlMailbox = urlencode($mailbox);
38 $subject = processSubject($msg['SUBJECT']);
42 if (isset($msg['FLAG_FLAGGED']) && $msg['FLAG_FLAGGED'] == true)
44 $flag = "<font color=$color[2]>";
45 $flag_end = '</font>';
52 if (!isset($msg['FLAG_SEEN']) ||
$msg['FLAG_SEEN'] == false)
62 if ($mailbox == $sent_folder)
72 if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED'])
74 $fontstr = "<font color=\"$color[9]\">";
75 $fontstr_end = '</font>';
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'];
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'];
97 if (!isset($hlt_color))
98 $hlt_color = $color_string;
100 if ($where && $what) {
101 $search_stuff = '&where='.urlencode($where).'&what='.urlencode($what);
105 $checked = ' checked';
109 for ($i=1; $i <= count($index_order); $i++
) {
110 switch ($index_order[$i]) {
112 echo " <td width=1% bgcolor=$hlt_color align=center><input type=checkbox name=\"msg[$t]\" value=".$msg["ID"]."$checked></TD>\n";
115 echo " <td width=30% bgcolor=$hlt_color>$italic$bold$flag$fontstr$senderName$fontstr_end$flag_end$bold_end$italic_end</td>\n";
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";
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";
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) {
135 if ($msg['TYPE0'] == 'multipart') {
139 if (ereg('(1|2)',substr($msg['PRIORITY'],0,1))) {
140 echo "<font color=$color[1]>!</font>\n";
143 if (isset($msg['FLAG_DELETED']) && $msg['FLAG_DELETED']) {
144 echo "<font color=\"$color[1]\">D</font>\n";
148 if (!$stuff) echo " \n";
149 echo "</small></b></td>\n";
152 echo " <td bgcolor=$hlt_color width=1%>$bold$fontstr".show_readable_size($msg['SIZE'])."$fontstr_end$bold_end</td>\n";
162 ** This function loops through a group of messages in the mailbox and shows them
164 function showMessagesForMailbox($imapConnection, $mailbox, $numMessages, $startMessage, $sort, $color,$show_num, $use_cache) {
165 global $msgs, $msort;
167 global $message_highlight_list;
168 global $auto_expunge;
170 if ($auto_expunge == true) sqimap_mailbox_expunge($imapConnection, $mailbox, false);
171 sqimap_mailbox_select($imapConnection, $mailbox);
175 if ($numMessages >= 1) {
177 for ($q = 0; $q < $numMessages; $q++
) {
178 if($mailbox == $sent_folder)
179 $hdr = sqimap_get_small_header ($imapConnection, $q+
1, true);
181 $hdr = sqimap_get_small_header ($imapConnection, $q+
1, false);
183 $from[$q] = $hdr->from
;
184 $date[$q] = $hdr->date
;
185 $subject[$q] = $hdr->subject
;
187 $priority[$q] = $hdr->priority
;
189 $size[$q] = $hdr->size
;
190 $type[$q] = $hdr->type0
;
191 $flags[$q] = sqimap_get_flags ($imapConnection, $q+
1);
195 // if it's not sorted
196 if ($startMessage +
($show_num - 1) < $numMessages) {
197 $endMessage = $startMessage +
($show_num-1);
199 $endMessage = $numMessages;
202 if ($endMessage < $startMessage) {
203 $startMessage = $startMessage - $show_num;
204 if ($startMessage < 1)
209 $real_startMessage = $numMessages - $startMessage +
1;
210 $real_endMessage = $numMessages - $startMessage - $show_num;
211 if ($real_endMessage <= 0)
212 $real_endMessage = 1;
215 for ($q = $real_startMessage; $q >= $real_endMessage; $q--) {
216 if($mailbox == $sent_folder)
217 $hdr = sqimap_get_small_header ($imapConnection, $q, true);
219 $hdr = sqimap_get_small_header ($imapConnection, $q, false);
221 $from[$j] = $hdr->from
;
222 $date[$j] = $hdr->date
;
223 $subject[$j] = $hdr->subject
;
225 $priority[$j] = $hdr->priority
;
227 $size[$j] = $hdr->size
;
228 $type[$j] = $hdr->type0
;
229 $flags[$j] = sqimap_get_flags ($imapConnection, $q);
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;
244 $end_loop = $show_num;
249 while ($j < $end_loop) {
250 if (isset($date[$j])) {
251 $date[$j] = ereg_replace(' ', ' ', $date[$j]);
252 $tmpdate = explode(' ', trim($date[$j]));
254 $tmpdate = $date = array("","","","","","");
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];
270 # fix SUBJECT-SORT to remove Re:
271 $re_abbr = # Add more here!
272 'vedr|sv|' . # Danish
274 if (eregi("^($re_abbr):[ ]*(.*)$", $messages[$j]['SUBJECT-SORT'], $regs))
275 $messages[$j]['SUBJECT-SORT'] = $regs[2];
278 while ($num < count($flags[$j])) {
279 if ($flags[$j][$num] == 'Deleted') {
280 $messages[$j]['FLAG_DELETED'] = true;
282 elseif ($flags[$j][$num] == 'Answered') {
283 $messages[$j]['FLAG_ANSWERED'] = true;
285 elseif ($flags[$j][$num] == 'Seen') {
286 $messages[$j]['FLAG_SEEN'] = true;
288 elseif ($flags[$j][$num] == 'Flagged') {
289 $messages[$j]['FLAG_FLAGGED'] = true;
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)
301 /** Find and remove the ones that are deleted */
304 while ($j < $numMessages) {
305 if (isset($messages[$j]['FLAG_DELETED']) && $messages[$j]['FLAG_DELETED'] == true) {
309 $msgs[$i] = $messages[$j];
316 if (! isset($messages))
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)
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');
346 session_register('msort');
348 displayMessageArray($imapConnection, $numMessages, $startMessage, $msgs, $msort, $mailbox, $sort, $color,$show_num);
349 session_register('msgs');
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;
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');
364 if ($startMessage +
($show_num - 1) < $numMessages) {
365 $endMessage = $startMessage +
($show_num-1);
367 $endMessage = $numMessages;
370 if ($endMessage < $startMessage) {
371 $startMessage = $startMessage - $show_num;
372 if ($startMessage < 1)
376 $nextGroup = $startMessage +
$show_num;
377 $prevGroup = $startMessage - $show_num;
378 $urlMailbox = urlencode($mailbox);
380 do_hook('mailbox_index_before');
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";
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";
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";
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";
410 mail_message_listing_beginning($imapConnection,
411 "move_messages.php?msg=$msg&mailbox=$urlMailbox&startMessage=$startMessage",
412 $mailbox, $sort, $Message, $More, $startMessage);
414 $groupNum = $startMessage %
($show_num - 1);
415 $real_startMessage = $startMessage;
417 if ($endMessage - $startMessage < $show_num - 1) {
418 $endMessage = $endMessage - $startMessage +
1;
420 } else if ($startMessage > $show_num) {
421 $endMessage = $show_num;
426 $endVar = $endMessage +
1;
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> </CENTER></TD></TR>";
433 } else if ($startMessage == $endMessage) { // if there's only one message in the box, handle it different.
444 } while (isset ($key) && ($k < $i));
445 printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $real_startMessage, 0, 0);
455 } while (isset ($key) && ($k < $i));
458 printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $real_startMessage, 0, 0);
463 } while ($i && $i < $endVar);
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);
475 echo '</td></tr></table>';
477 echo '</table>'; /** End of message-list table */
479 do_hook('mailbox_index_after');
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
490 function mail_message_listing_beginning($imapConnection, $moveURL,
491 $mailbox = '', $sort = -1, $Message = '', $More = '', $startMessage = 1)
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">';
501 echo "<TR BGCOLOR=\"$color[4]\"><TD align=center>$Message</td></tr>\n";
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);
509 echo '</td></tr></table>';
512 /** The delete and move options */
513 echo "<TR><TD BGCOLOR=\"$color[0]\">";
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";
518 echo " <TD WIDTH=60% ALIGN=LEFT VALIGN=CENTER>\n";
521 echo ' <NOBR><SMALL>'. _("Move selected to:") .'</SMALL>';
522 echo ' <TT><SMALL><SELECT NAME="targetMailbox">';
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(' ', ' ', $boxes[$i]['unformatted-disp']);
529 echo " <OPTION VALUE=\"$box\">$box2</option>\n";
532 echo ' </SELECT></SMALL></TT>';
533 echo ' <SMALL><INPUT TYPE=SUBMIT NAME="moveButton" VALUE="'. _("Move") ."\"></SMALL></NOBR>\n";
535 echo " <TD WIDTH=40% ALIGN=RIGHT>\n";
536 if (! $auto_expunge) {
537 echo ' <NOBR><SMALL><INPUT TYPE=SUBMIT NAME="expungeButton" VALUE="'. _("Expunge") .'"> '. _("mailbox") ."</SMALL></NOBR> \n";
539 echo " <NOBR><SMALL><INPUT TYPE=SUBMIT VALUE=\"". _("Delete") ."\"> ". _("checked messages") ."</SMALL></NOBR>\n";
544 do_hook('mailbox_form_before');
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\">";
551 $urlMailbox=urlencode($mailbox);
554 for ($i=1; $i <= count($index_order); $i++
) {
555 switch ($index_order[$i]) {
558 echo ' <TD WIDTH="1%"><B> </B></TD>';
562 if ($mailbox == $sent_folder)
563 echo ' <TD WIDTH="30%"><B>'. _("To") .'</B>';
565 echo ' <TD WIDTH="30%"><B>'. _("From") .'</B>';
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";
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";
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";
577 echo ' <TD nowrap WIDTH="1%"><B>'. _("Date") .'</B>';
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";
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";
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";
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";
590 echo ' <TD><B>'. _("Subject") ."</B>\n";
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";
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";
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";
601 echo ' <TD WIDTH="1%"><b>' . _("Size")."</b></TD>\n";
608 function ShowSelectAllLink($startMessage, $sort)
610 global $checkall, $PHP_SELF, $what, $where, $mailbox;
612 echo "\n<A HREF=\"$PHP_SELF?mailbox=" . urlencode($mailbox) .
613 "&startMessage=$startMessage&sort=$sort&";
614 if ( isset($checkall) && $checkall == '1')
618 if (isset($where) && isset($what))
619 echo "&where=" . urlencode($where) . "&what=" . urlencode($what);
621 if (isset($checkall) && $checkall == '1')
622 echo _("Unselect All");
624 echo _("Select All");
628 function processSubject($subject)
630 // Shouldn't ever happen -- caught too many times in the IMAP functions
632 return _("(no subject)");
634 if (strlen($subject) <= 55)
637 $ent_strlen=strlen($subject);
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)
647 $trim_val +
= ($ent_loc_end-$ent_loc)+
1;
648 $ent_strlen -= $ent_loc_end-$ent_loc;
649 $ent_offset = $ent_loc_end+
1;
652 if ($ent_strlen <= 55)
655 return substr($subject, 0, $trim_val) . '...';