';;
} else {
echo '
';
}
echo $motd;
echo '
';
function check_unread_mail()
{
global $CONFIG, $spooldir;
if (isset($_COOKIE['mail_name'])) {
$name = strtolower($_COOKIE['mail_name']);
$database = $spooldir . '/mail.db3';
if (is_file($database)) {
$dbh = head_mail_db_open($database);
$query = $dbh->prepare('SELECT * FROM messages where rcpt_to=:rcpt_to');
$query->execute([
'rcpt_to' => $name
]);
$newmail = false;
while (($row = $query->fetch()) !== false) {
if (($row['rcpt_viewed'] != 'true') && ($row['to_hide'] != 'true')) {
$newmail = true;
}
}
$dbh = null;
return $newmail;
} else {
return false;
}
}
}
function head_mail_db_open($database, $table = 'messages')
{
try {
$dbh = new PDO('sqlite:' . $database);
} catch (PDOException $e) {
echo 'Connection failed: ' . $e->getMessage();
exit();
}
$dbh->exec("CREATE TABLE IF NOT EXISTS messages(
id INTEGER PRIMARY KEY,
msgid TEXT UNIQUE,
mail_from TEXT,
mail_viewed TEXT,
rcpt_to TEXT,
rcpt_viewed TEXT,
rcpt_target TEXT,
date TEXT,
subject TEXT,
message TEXT,
from_hide TEXT,
to_hide TEXT)");
return ($dbh);
}