/**
** right_main.php3
**
** This is where the mailboxes are listed. This controls most of what
** goes on in SquirrelMail.
**
**/
if(!isset($logged_in)) {
echo "You must login first.";
exit;
}
if(!isset($username) || !isset($key)) {
echo "You need a valid user and password to access this page!";
exit;
}
?>
include("../config/config.php3");
include("functions/imap.php3");
include("functions/strings.php3");
include("functions/date.php3");
include("functions/page_header.php3");
include("functions/array.php3");
include("functions/mailbox.php3");
include("functions/mailbox_display.php3");
include("functions/display_messages.php3");
/////////////////////////////////////////////////////////////////////////////////
//
// incoming variables from URL:
// $sort Direction to sort by date
// values: 0 - descending order
// values: 1 - ascending order
// $startMessage Message to start at
// $mailbox Full Mailbox name
//
// incoming from cookie:
// $username duh
// $key pass
//
/////////////////////////////////////////////////////////////////////////////////
// open a connection on the imap port (143)
$imapConnection = fsockopen($imapServerAddress, 143, &$errorNumber, &$errorString);
if (!$imapConnection) {
echo "Error connecting to IMAP Server.
";
echo "$errorNumber : $errorString
";
exit;
}
$serverInfo = fgets($imapConnection, 256);
// login
fputs($imapConnection, "1 login $username $key\n");
$read = fgets($imapConnection, 1024);
if (strpos($read, "NO")) {
error_username_password_incorrect();
exit;
}
// If the page has been loaded without a specific mailbox,
// just show a page of general info.
if (!isset($mailbox)) {
displayPageHeader("None");
general_info($motd, $org_logo, $version, $org_name);
exit;
}
// switch to the mailbox, and get the number of messages in it.
selectMailbox($imapConnection, $mailbox, $numMessages);
// make a URL safe $mailbox for use in the links
$urlMailbox = urlencode($mailbox);
displayPageHeader($mailbox);
$i = 1;
while ($i <= $numMessages) {
getMessageHeaders($imapConnection, $i, $from, $subject, $date);
$messages[$i]["DATE"] = getTimeStamp(explode(" ", trim($date)));
$messages[$i]["ID"] = $i;
$messages[$i]["FROM"] = $from;
$messages[$i]["SUBJECT"] = $subject;
$i++;
}
if ($sort == 0)
$msgs = ary_sort($messages, "DATE", -1);
else
$msgs = ary_sort($messages, "DATE", 1);
if ($endMessage > 24) {
echo "Next   ";
$endMessage = 24;
}
/** Display "Next, Previous" on top */
/** This is the beginning of the message list table. It wraps around all messages */
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.
for ($i = $startMessage;$i <= $endMessage; $i++) {
printMessageInfo($imapConnection, $msgs[$i]["ID"], $msgs[$i]["FROM"], $msgs[$i]["SUBJECT"], $msgs[$i]["DATE"]);
}
echo " \n";
echo " |
"; /** End of message-list table */
/** Display "Next, Previous" on bottom */
fclose($imapConnection);
?>