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