loadClasses();
$this->initVars();
switch($this->type) {
case 'mbox':
$this->mail = new Zend_Mail_Mbox(array('filename' => $this->param));
break;
case 'pop3':
if(!isset($_SERVER['PHP_AUTH_USER'])) {
$this->needAuth();
} else {
$this->mail = new Zend_Mail_Pop3(array('host' => $this->param, 'user' => $_SERVER['PHP_AUTH_USER'],
'password' => $_SERVER['PHP_AUTH_PW']));
}
break;
default:
break;
$this->mail = null;
}
}
function loadClasses() {
include_once 'init.inc';
Zend::loadClass('Zend_Mail_Mbox');
Zend::loadClass('Zend_Mail_Pop3');
Zend::loadClass('Zend_Mail_List');
}
function initVars() {
$this->type = isset($_GET['type']) ? $_GET['type'] : null;
$this->param = isset($_GET['param']) ? $_GET['param'] : null;
$this->queryString = "type={$this->type}¶m={$this->param}";
$this->messageNum = isset($_GET['message']) && is_numeric($_GET['message']) ? $_GET['message'] : null;
}
function needAuth() {
header('WWW-Authenticate: Basic realm="POP3 credentials"');
header('HTTP/1.0 401 Please enter credentials');
$this->noRun = true;
}
function run() {
if($this->noRun) {
return;
}
$message = null;
try {
if($this->messageNum) {
$message = $this->mail->getMessage($this->messageNum);
}
} catch(Exception $e) {
}
if(!$this->mail) {
$this->showChooseType();
} else if($message) {
$this->showMessage($message);
} else {
$this->showList();
}
}
function showHeader($title) {
echo "
{$title}
{$title}
";
}
function showFooter() {
echo '';
}
function showChooseType() {
$this->showHeader('Choose Type');
echo '
';
$this->showFooter();
}
function showMessage($message) {
try {
$from = $message->from;
} catch(Exception $e) {
$from = '(unknown)';
}
try {
$to = $message->to;
} catch(Exception $e) {
$to = '(unknown)';
}
try {
$subject = $message->subject;
} catch(Exception $e) {
$subject = '(unknown)';
}
$content = htmlentities($message->getContent());
$this->showHeader($subject);
echo "
From: | $from |
Subject: | $subject |
To: | $to |
$content |
back to list";
if($this->messageNum > 1) {
echo " - queryString}&message=", $this->messageNum - 1, '">prev';
}
if($this->messageNum < $this->mail->countMessages()) {
echo " - queryString}&message=", $this->messageNum + 1, '">next';
}
$this->showFooter();
}
function showList() {
$this->showHeader('Overview');
echo ' | From | To | Subject |
';
foreach(new Zend_Mail_List($this->mail) as $num => $message) {
echo "read | ";
try {
echo "{$message->from} | {$message->to} | {$message->subject} | ";
} catch(Exception $e){
echo 'error | ';
}
echo '
';
}
echo '
';
$this->showFooter();
}
}
$example3 = new Example3();
$example3->run();