'; echo 'mail / '; echo htmlspecialchars($_POST['username']).''; echo ''; // New Message button echo ''; echo '
'; echo '
'; echo ''; echo ""; echo ""; echo ''; echo '
'; echo '
'; if(isset($_POST['username'])) { $name = $_POST['username']; // Save name in cookie if ($setcookies==true) { setcookie("cookie_name",stripslashes($name),time()+(3600*24*90)); } } else { if ($setcookies) { if ((isset($_COOKIE["cookie_name"])) && (!isset($name))) { $name=$_COOKIE["cookie_name"]; } else { $name = ''; } } } if($logged_in !== true) { echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo '
Please Login
Username:
Password:
 
'; exit(0); } $user = strtolower($_POST['username']); if(isset($_POST['command']) && $_POST['command'] == 'Message') { $database = $spooldir.'/mail.db3'; $dbh = mail_db_open($database); $query = $dbh->prepare('SELECT * FROM messages where id=:id'); $query->execute(['id' => $_POST['id']]); while (($row = $query->fetch()) !== false) { $ts = new DateTime(date("D, j M Y H:i T", $row["date"]), new DateTimeZone('UTC')); $ts->add(DateInterval::createFromDateString($offset.' minutes')); if($offset != 0) { $newdate = $ts->format('D, j M Y H:i'); } else { $newdate = $ts->format('D, j M Y H:i T'); } unset($ts); if(($row['mail_from'] != $user) && ($row['rcpt_to'] != $user)) { continue; } $body = rtrim(nl2br($row['message'])).'
'; echo '
'; echo 'Subject: '.$row['subject'].'
'; echo 'From: '.$row['mail_from'].'
'; echo 'To: '.$row['rcpt_to'].'
'; echo 'Date: '.$newdate.'
'; echo '
'; echo '
'; echo $body; echo '
'; echo ''; echo ""; echo ""; echo ""; echo ''; echo '
'; echo '
'; } $dbh = null; } if (isSet($_POST['sendMessage'])) { if (isSet($_POST['to']) && $_POST['to'] != '' && isSet($_POST['from']) && $_POST['from'] != '' && isSet($_POST['message']) && $_POST['message'] != '') { if(($to = get_config_value('aliases.conf', strtolower($_POST['to']))) == false) { $to = $_POST['to']; } $userlist = scandir($config_dir.'/users/'); $found = 0; foreach($userlist as $user) { if(trim($to) == trim($user)) { $found = 1; break; } } if($found == 0) { echo 'User not found: '.$to; } else { $database = $spooldir.'/mail.db3'; $dbh = mail_db_open($database); $from = $_POST['from']; $subject = $_POST['subject']; $message = $_POST['message']; $date = time(); $message = $_POST['message']; $msgid = '<'.md5(strtolower($to).strtolower($from).strtolower($subject).strtolower($message)).'>'; $sql = 'INSERT INTO messages(msgid, mail_from, rcpt_to, rcpt_target, date, subject, message, from_hide, to_hide, mail_viewed, rcpt_viewed) VALUES(?,?,?,?,?,?,?,?,?,?,?)'; $stmt = $dbh->prepare($sql); // For possible future use $target = "local"; $mail_viewed = "1"; $rcpt_viewed = null; $q = $stmt->execute([$msgid, $from, $to, $target, $date, $subject, $message, null, null, $mail_viewed, $rcpt_viewed]); if ($q) { echo 'Message sent.'; }else echo 'Failed to send message.'; } $dbh = null; } } if(isset($_POST['command']) && $_POST['command'] == 'Send') { if(isset($_POST['id'])) { $database = $spooldir.'/mail.db3'; $dbh = mail_db_open($database); $query = $dbh->prepare('SELECT * FROM messages where id=:id'); $query->execute(['id' => $_POST['id']]); while (($row = $query->fetch()) !== false) { $mail_to = $row['mail_from']; if(strpos($row['subject'], 'Re: ') !== 0) { $subject = 'Re: '.$row['subject']; } else { $subject = $row['subject']; } $body=explode("\n",$row['message']); $message = $row['mail_from']." wrote:\n\n"; foreach($body as $line) { if(trim($line) !== '') { $line = '>'.$line; } $message.=$line; } } $dbh = null; } echo '

Send Message:

'; echo "
"; echo ''; echo ""; echo ''; echo ""; echo ''; echo ""; echo ''; echo ""; echo ""; echo ""; echo ""; echo '
To:
Subject:
'; } // Show My Messages $database = $spooldir.'/mail.db3'; $dbh = mail_db_open($database); echo '

My Messages:

'; echo ''; $query = $dbh->prepare('SELECT * FROM messages WHERE mail_from=:mail_from OR rcpt_to=:mail_from ORDER BY date DESC'); $query->execute(['mail_from' => $user]); echo ''; $i=1; while (($row = $query->fetch()) !== false) { if(($i % 2) != 0){ echo ''; $i++; } echo '
SubjectFromToDate
'; } else { echo '
'; } // Use local timezone if possible $ts = new DateTime(date("D, j M Y H:i T", $row["date"]), new DateTimeZone('UTC')); $ts->add(DateInterval::createFromDateString($offset.' minutes')); if($offset != 0) { $newdate = $ts->format('D, j M Y H:i'); } else { $newdate = $ts->format('D, j M Y H:i T'); } unset($ts); echo '
'; echo ''; echo ""; echo ""; echo ""; echo ''; echo '
'; echo '
'.$row["mail_from"].''.$row["rcpt_to"].''.$newdate.'

'; include "tail.inc"; function mail_db_open($database, $table='messages') { try { $dbh = new PDO('sqlite:'.$database); } catch (PDOExeption $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); } ?>