/**
** mailbox_display.php
**
** This contains functions that display mailbox information, such as the
** table row that has sender, date, subject, etc...
**
**/
function printMessageInfo($imapConnection, $t, $i, $from, $subject, $dateString, $answered, $seen) {
$senderName = getSenderName($from);
if (strlen(Chop($subject)) == 0)
$subject = "(no subject)";
echo "
\n";
if ($seen == false) {
echo " \n";
echo " $senderName \n";
echo " $dateString \n";
echo " $subject \n";
} else {
echo " \n";
echo " $senderName \n";
echo " $dateString \n";
echo " $subject \n";
}
echo " \n";
}
/**
** This function loops through a group of messages in the mailbox and shows them
**/
function showMessagesForMailbox($imapConnection, $mailbox, $numMessages, $startMessage, $sort) {
include("../config/config.php");
$j = 1;
while ($j <= $numMessages) {
$q = 0;
getMessageHeaders($imapConnection, $j, $from, $subject, $date);
getMessageFlags($imapConnection, $j, $flags);
$messages[$j]["TIME_STAMP"] = getTimeStamp(explode(" ", trim($date)));
$messages[$j]["DATE_STRING"] = getDateString(explode(" ", trim($date)));
$messages[$j]["ID"] = $j;
$messages[$j]["FROM"] = $from;
$messages[$j]["SUBJECT"] = $subject;
$messages[$j]["FLAG_DELETED"] = false;
$messages[$j]["FLAG_ANSWERED"] = false;
$messages[$j]["FLAG_SEEN"] = false;
while ($q < count($flags)) {
if ($flags[$q] == "Deleted") {
$messages[$j]["FLAG_DELETED"] = true;
}
else if ($flags[$q] == "Answered") {
$messages[$j]["FLAG_ANSWERED"] = true;
}
else if ($flags[$q] == "Seen") {
$messages[$j]["FLAG_SEEN"] = true;
}
$q++;
}
$j++;
}
/** Find and remove the ones that are deleted */
$i = 1;
$j = 1;
while ($j <= $numMessages) {
if ($messages[$j]["FLAG_DELETED"] == true) {
$j++;
continue;
}
$msgs[$i]["TIME_STAMP"] = $messages[$j]["TIME_STAMP"];
$msgs[$i]["DATE_STRING"] = $messages[$j]["DATE_STRING"];
$msgs[$i]["ID"] = $messages[$j]["ID"];
$msgs[$i]["FROM"] = $messages[$j]["FROM"];
$msgs[$i]["SUBJECT"] = $messages[$j]["SUBJECT"];
$msgs[$i]["FLAG_DELETED"] = $messages[$j]["FLAG_DELETED"];
$msgs[$i]["FLAG_ANSWERED"] = $messages[$j]["FLAG_ANSWERED"];
$msgs[$i]["FLAG_SEEN"] = $messages[$j]["FLAG_SEEN"];
$i++;
$j++;
}
$numMessagesOld = $numMessages;
$numMessages = $i - 1;
// There's gotta be messages in the array for it to sort them.
if ($numMessages > 0) {
if ($sort == 0)
$msgs = ary_sort($msgs, "TIME_STAMP", -1);
else
$msgs = ary_sort($msgs, "TIME_STAMP", 1);
}
if ($startMessage + 24 < $numMessages) {
$endMessage = $startMessage + 24;
} else {
$endMessage = $numMessages;
}
$nextGroup = $startMessage + 25;
$prevGroup = $startMessage - 25;
$urlMailbox = urlencode($mailbox);
/** This is the beginning of the message list table. It wraps around all messages */
echo "";
echo "";
echo "Viewing messages $startMessage to $endMessage ($numMessages total) \n";
echo " \n";
echo "";
if (($nextGroup <= $numMessages) && ($prevGroup >= 0)) {
echo "Previous \n";
echo "Next \n";
}
else if (($nextGroup > $numMessages) && ($prevGroup >= 0)) {
echo "Previous \n";
echo "Next \n";
}
else if (($nextGroup <= $numMessages) && ($prevGroup < 0)) {
echo "Previous \n";
echo "Next \n";
}
echo " \n";
/** The "DELETE" button */
echo "";
echo " ";
echo "";
echo "";
echo "";
echo " Num ";
echo " From ";
echo " Date ";
if ($sort == 0)
echo " \n";
else
echo " \n";
echo " Subject \n";
echo " ";
// loop through and display the info for each message.
$t = 0; // $t is used for the checkbox number
if ($numMessages == 0) { // if there's no messages in this folder
echo "THIS FOLDER IS EMPTY   ";
} else if ($startMessage == $endMessage) { // if there's only one message in the box, handle it different.
$i = $startMessage;
printMessageInfo($imapConnection, $t, $msgs[$i]["ID"], $msgs[$i]["FROM"], $msgs[$i]["SUBJECT"], $msgs[$i]["DATE_STRING"], $msgs[$i]["FLAG_ANSWERED"], $msgs[$i]["FLAG_SEEN"]);
} else {
for ($i = $startMessage - 1;$i <= $endMessage - 1; $i++) {
printMessageInfo($imapConnection, $t, $msgs[$i]["ID"], $msgs[$i]["FROM"], $msgs[$i]["SUBJECT"], $msgs[$i]["DATE_STRING"], $msgs[$i]["FLAG_ANSWERED"], $msgs[$i]["FLAG_SEEN"]);
$t++;
}
}
echo "
";
/** The "DELETE" button */
echo " ";
echo " ";
if (($move_to_trash == true) && ($mailbox == $trash_folder))
echo " Empty Trash ";
echo " ";
echo "
\n";
echo "\n";
echo "";
if (($nextGroup <= $numMessages) && ($prevGroup >= 0)) {
echo "Previous \n";
echo "Next \n";
}
else if (($nextGroup > $numMessages) && ($prevGroup >= 0)) {
echo "Previous \n";
echo "Next \n";
}
else if (($nextGroup <= $numMessages) && ($prevGroup < 0)) {
echo "Previous \n";
echo "Next \n";
}
echo " "; /** End of message-list table */
}
?>