]>
Commit | Line | Data |
---|---|---|
6df4b805 MR |
1 | <?php |
2 | /* vim: set ts=4 tw=0 sw=4 noet: */ | |
3 | require_once 'Mail/mimeDecode.php'; | |
4 | require_once 'config.php'; | |
5 | require_once $CFG->root . 'lib/db_factory.php'; | |
6 | require_once $CFG->root . 'lib/utils.inc.php'; | |
7 | ||
8 | $util = Utils::getInstance(); | |
9 | $loggedIn = $util->isLoggedIn(); | |
10 | if ($loggedIn && isset($_GET['id'])) { | |
11 | $util->setHeading('Spam Report'); | |
12 | echo $util->getHeader(); | |
13 | echo $util->getHeading(); | |
14 | ||
15 | $id = $_GET['id']; | |
16 | $mail = unserialize($_SESSION['mailInfo'][$id]); | |
17 | ||
18 | $row = $DB->getMail($id); | |
19 | $string = $row->mail_text; | |
20 | $sa_tests = null; | |
21 | $params['include_bodies'] = false; | |
22 | $params['decode_bodies'] = true; | |
23 | $params['decode_headers'] = true; | |
24 | $params['input'] = $string; | |
25 | $params['crlf'] = "\r\n"; | |
26 | ||
27 | $structure = Mail_mimeDecode::decode($params); | |
28 | $headers = $structure->headers; | |
29 | $rows = array(); | |
30 | foreach ($headers as $header => $value) { | |
31 | if ($header == 'x-spam-status') { | |
32 | if (preg_match('/^(.*),\s*score=([\d\.]+).*tests=\[(.*)\].*/', | |
33 | $value, $matches)) { | |
34 | $sa_tests = array('x-spam-status' => $matches[1], | |
35 | 'score' => $matches[2], 'tests' => $matches[3]); | |
36 | } | |
37 | } else if ($header == 'x-spam-flag') { | |
38 | $value = str_replace("<", "<", $value); | |
39 | $value = str_replace(">", ">", $value); | |
40 | $rows['spam'] = "<tr><td class=\"label\">Spam</td><td class=\"value\">$value</td></tr>"; | |
41 | } else if ($header == 'x-spam-score') { | |
42 | $value = str_replace("<", "<", $value); | |
43 | $value = str_replace(">", ">", $value); | |
44 | $rows['score'] = "<tr><td class=\"label\">Spam Score</td><td class=\"value\">$value</td></tr>"; | |
45 | } else if ($header == 'x-spam-level') { | |
46 | $value = str_replace("<", "<", $value); | |
47 | $value = str_replace(">", ">", $value); | |
48 | $rows['level'] = "<tr><td class=\"label\">Spam Level</td><td class=\"value\">$value</td></tr>"; | |
49 | } else if ($header == 'date') { | |
50 | $value = str_replace("<", "<", $value); | |
51 | $value = str_replace(">", ">", $value); | |
52 | $rows['date'] = "<tr><td class=\"label\">Date</td><td class=\"value\">$value</td></tr>"; | |
53 | } else if ($header == 'from') { | |
54 | $value = str_replace("<", "<", $value); | |
55 | $value = str_replace(">", ">", $value); | |
56 | $rows['from'] = "<tr><td class=\"label\">From</td><td class=\"value\">$value</td></tr>"; | |
57 | } else if ($header == 'reply-to') { | |
58 | $value = str_replace("<", "<", $value); | |
59 | $value = str_replace(">", ">", $value); | |
60 | $rows['reply-to'] = "<tr><td class=\"label\">Reply-to</td><td class=\"value\">$value</td></tr>"; | |
61 | } else if ($header == 'to') { | |
62 | $value = str_replace("<", "<", $value); | |
63 | $value = str_replace(">", ">", $value); | |
64 | $rows['to'] = "<tr><td class=\"label\">To</td><td class=\"value\">$value</td></tr>"; | |
65 | } else if ($header == 'subject') { | |
66 | $value = str_replace("<", "<", $value); | |
67 | $value = str_replace(">", ">", $value); | |
68 | $rows['subject'] = "<tr><td class=\"label\">Subject</td><td class=\"value\">$value</td></tr>"; | |
69 | } else if ($header == 'received') { | |
70 | $headers = ''; | |
71 | foreach ($value as $val) { | |
72 | $val = str_replace("<", "<", $val); | |
73 | $val = str_replace(">", ">", $val); | |
74 | $headers .= ($headers == '') ? "$val" : "<br/><br/>$val"; | |
75 | } | |
76 | $rows['headers'] = "<tr><td class=\"label\">Headers</td><td class=\"value\">$headers</td></tr>"; | |
77 | } | |
78 | } | |
79 | $bayes = array(); | |
80 | if ($sa_tests) { | |
81 | $sa_tests['tests'] = str_replace(" ","",$sa_tests['tests']); | |
82 | $sa_rules = explode(",",$sa_tests['tests']); | |
83 | $sa_count = count($sa_rules); | |
84 | for ($i = 0; $i < $sa_count; $i++) { | |
85 | $sa_rule = explode("=", $sa_rules[$i]); | |
86 | $bayes[$i] = "<tr><td class=\"label\">$sa_rule[0]</td><td class=\"value\">$sa_rule[1]</td></tr>"; | |
87 | } | |
88 | $bayes['total'] = "<tr><td class=\"label\">TOTAL</td><td class=\"value\">".$sa_tests['score']."</td></tr>"; | |
89 | } else { | |
90 | $bayes['total'] = "<tr><td class=\"label\">TOTAL</td><td class=\"value\">-</td></tr>"; | |
91 | } | |
92 | $plain = "?id=$id&format=plain"; | |
93 | $html = "?id=$id&format=html"; | |
94 | echo '<p class="ruler">Message ID : ' . $mail->mail_id . '</p>'; | |
95 | echo '<table class="button-menu">'; | |
96 | echo '<tr class="button-row">'; | |
97 | echo '<td class="button"><input class="btn-input" type="button" value="Return" | |
98 | onclick="javascript: history.back();"/></td>'; | |
99 | echo '<td class="button"><input class="btn-input" type="button" value="View HTML" | |
100 | onclick="javascript: window.location.href=\'message_view.php'.$html.'\'"/></td>'; | |
101 | echo '<td class="button"><input class="btn-input" type="button" value="View Plain Text" | |
102 | onclick="javascript: window.location.href=\'message_view.php'.$plain.'\'"/></td>'; | |
103 | echo '<td class="button"><input class="btn-input" type="button" value="View Full Headers" | |
104 | onclick="javascript: window.location.href=\'show_headers.php?id='.$id.'\'"/></td>'; | |
105 | echo '</tr></table>'; | |
106 | echo '<table>'; | |
107 | if (isset($rows['spam'])) | |
108 | echo $rows['spam']; | |
109 | if (isset($rows['score'])) | |
110 | echo $rows['score']; | |
111 | if (isset($rows['level'])) | |
112 | echo $rows['level']; | |
113 | if (isset($rows['headers'])) | |
114 | echo $rows['headers']; | |
115 | if (isset($rows['date'])) | |
116 | echo $rows['date']; | |
117 | if (isset($rows['from'])) | |
118 | echo $rows['from']; | |
119 | if (isset($rows['reply-to'])) | |
120 | echo $rows['reply-to']; | |
121 | if (isset($rows['to'])) | |
122 | echo $rows['to']; | |
123 | if (isset($rows['subject'])) | |
124 | echo $rows['subject']; | |
125 | echo '</table>'; | |
126 | echo '<p class="ruler">Spamassassin Report</p>'; | |
127 | echo '<table><tr><th>Rule</th><th>Score</th></tr>'; | |
128 | foreach ($bayes as $key => $row) { | |
129 | if ($key != 'total') { | |
130 | echo $row; | |
131 | } | |
132 | } | |
133 | echo $bayes['total']; | |
134 | echo '</table>'; | |
135 | echo $util->getFooter(); | |
136 | } else if ($loggedIn) { | |
137 | header('Location: index.php'); | |
138 | } else { | |
139 | header('Location: auth.php'); | |
140 | } | |
141 | ||
142 | ?> |