root . 'lib/db_factory.php';
require_once $CFG->root . 'lib/utils.inc.php';
$util = new Utils;
$loggedIn = $util->isLoggedIn();
if ($loggedIn && isset($_GET['id'])) {
$id = $_GET['id'];
$mail = unserialize($_SESSION['mailInfo'][$id]);
if (! is_object($mail) || false == $util->authorized($mail->recipient)) {
header('Location: index.php');
exit;
}
$util->setHeading('Spam Report');
echo $util->getHeader();
echo $util->getHeading();
$row = $DB->getMail($id);
$string = $row->mail_text;
$sa_tests = null;
$params['include_bodies'] = false;
$params['decode_bodies'] = true;
$params['decode_headers'] = true;
$params['input'] = $string;
$params['crlf'] = "\r\n";
$structure = Mail_mimeDecode::decode($params);
$headers = $structure->headers;
$rows = array();
foreach ($headers as $header => $value) {
if ($header == 'x-spam-status') {
if (preg_match('/^(.*),\s*score=([\d\.]+).*tests=\[(.*)\].*/',
$value, $matches)) {
$sa_tests = array('x-spam-status' => $matches[1],
'score' => $matches[2], 'tests' => $matches[3]);
}
} else if ($header == 'x-spam-flag') {
$value = str_replace("<", "<", $value);
$value = str_replace(">", ">", $value);
$rows['spam'] = "
Spam | $value |
";
} else if ($header == 'x-spam-score') {
$value = str_replace("<", "<", $value);
$value = str_replace(">", ">", $value);
$rows['score'] = "Spam Score | $value |
";
} else if ($header == 'x-spam-level') {
$value = str_replace("<", "<", $value);
$value = str_replace(">", ">", $value);
$rows['level'] = "Spam Level | $value |
";
} else if ($header == 'date') {
$value = str_replace("<", "<", $value);
$value = str_replace(">", ">", $value);
$rows['date'] = "Date | $value |
";
} else if ($header == 'from') {
$value = str_replace("<", "<", $value);
$value = str_replace(">", ">", $value);
$rows['from'] = "From | $value |
";
} else if ($header == 'reply-to') {
$value = str_replace("<", "<", $value);
$value = str_replace(">", ">", $value);
$rows['reply-to'] = "Reply-to | $value |
";
} else if ($header == 'to') {
$value = str_replace("<", "<", $value);
$value = str_replace(">", ">", $value);
$rows['to'] = "To | $value |
";
} else if ($header == 'subject') {
$value = str_replace("<", "<", $value);
$value = str_replace(">", ">", $value);
$rows['subject'] = "Subject | $value |
";
} else if ($header == 'received') {
$headers = '';
foreach ($value as $val) {
$val = str_replace("<", "<", $val);
$val = str_replace(">", ">", $val);
$headers .= ($headers == '') ? "$val" : "
$val";
}
$rows['headers'] = "Headers | $headers |
";
}
}
$bayes = array();
if ($sa_tests) {
$sa_tests['tests'] = str_replace(" ","",$sa_tests['tests']);
$sa_rules = explode(",",$sa_tests['tests']);
$sa_count = count($sa_rules);
for ($i = 0; $i < $sa_count; $i++) {
$sa_rule = explode("=", $sa_rules[$i]);
$bayes[$i] = "$sa_rule[0] | $sa_rule[1] |
";
}
$bayes['total'] = "TOTAL | ".$sa_tests['score']." |
";
} else {
$bayes['total'] = "TOTAL | - |
";
}
$plain = "?id=$id&format=plain";
$html = "?id=$id&format=html";
echo 'Message ID : ' . $mail->mail_id . '
';
echo '';
echo '';
if (isset($rows['spam']))
echo $rows['spam'];
if (isset($rows['score']))
echo $rows['score'];
if (isset($rows['level']))
echo $rows['level'];
if (isset($rows['headers']))
echo $rows['headers'];
if (isset($rows['date']))
echo $rows['date'];
if (isset($rows['from']))
echo $rows['from'];
if (isset($rows['reply-to']))
echo $rows['reply-to'];
if (isset($rows['to']))
echo $rows['to'];
if (isset($rows['subject']))
echo $rows['subject'];
echo '
';
echo 'Spamassassin Report
';
echo 'Rule | Score |
';
foreach ($bayes as $key => $row) {
if ($key != 'total') {
echo $row;
}
}
echo $bayes['total'];
echo '
';
echo $util->getFooter();
} else if ($loggedIn) {
header('Location: index.php');
} else {
header('Location: auth.php');
}
?>