@@ -3,13 +3,13 @@ discard block |
||
| 3 | 3 | function imapFolder($cf, $username) { |
| 4 | 4 | $return = array(); |
| 5 | 5 | $open='{'.$cf['mailhost'].':143/imap/novalidate-cert/authuser='.$cf['authuser'].'}'; |
| 6 | - $m_mail = imap_open($open, $username, $cf['authpassword'], OP_READONLY) |
|
| 7 | - or syslog (LOG_EMERG, $cf['user'].': Error in IMAP connection to <'.$cf['mailhost'].'>: ' . imap_last_error()); |
|
| 8 | - if ( !$m_mail ) exit(254); |
|
| 6 | + $m_mail = imap_open($open, $username, $cf['authpassword'], OP_READONLY) |
|
| 7 | + or syslog (LOG_EMERG, $cf['user'].': Error in IMAP connection to <'.$cf['mailhost'].'>: ' . imap_last_error()); |
|
| 8 | + if ( !$m_mail ) exit(254); |
|
| 9 | 9 | |
| 10 | 10 | |
| 11 | - syslog (LOG_INFO,$cf['user'].': Successfully connected to <'.$cf['mailhost'].'>; Listing folders of account <'.$username.'>...'); |
|
| 12 | - //get all folder |
|
| 11 | + syslog (LOG_INFO,$cf['user'].': Successfully connected to <'.$cf['mailhost'].'>; Listing folders of account <'.$username.'>...'); |
|
| 12 | + //get all folder |
|
| 13 | 13 | $list = imap_list($m_mail, $open, "*"); |
| 14 | 14 | imap_close($m_mail); |
| 15 | 15 | if (is_array($list)) |
@@ -23,7 +23,7 @@ discard block |
||
| 23 | 23 | function imapFind ($cf, $username, $folder) { |
| 24 | 24 | $head=array(); |
| 25 | 25 | $m_mail = imap_open('{'.$cf['mailhost'].':143/imap/novalidate-cert/authuser='.$cf['authuser'].'}'.$folder, $username,$cf['authpassword'], OP_READONLY) |
| 26 | - or syslog (LOG_EMERG, $cf['user'].': Error in IMAP connection to <'.$cf['mailhost'].'>: ' . imap_last_error()); |
|
| 26 | + or syslog (LOG_EMERG, $cf['user'].': Error in IMAP connection to <'.$cf['mailhost'].'>: ' . imap_last_error()); |
|
| 27 | 27 | if ( !$m_mail ) exit(254); |
| 28 | 28 | |
| 29 | 29 | |
@@ -36,12 +36,12 @@ discard block |
||
| 36 | 36 | // Order results starting from newest message |
| 37 | 37 | if ( empty($m_search) ) { |
| 38 | 38 | syslog (LOG_INFO,$cf['user'].": No suitable mail found in <$folder> folder."); |
| 39 | - if ( $ierr = imap_errors() ) |
|
| 40 | - foreach ( $ierr as $thiserr ) |
|
| 41 | - syslog (LOG_ERR, $cf['user'].": IMAP Error: $thiserr"); |
|
| 42 | - if ( $ierr = imap_alerts() ) |
|
| 43 | - foreach ( $ierr as $thiserr ) |
|
| 44 | - syslog (LOG_ALERT, $cf['user'].": IMAP Alert: $thiserr"); |
|
| 39 | + if ( $ierr = imap_errors() ) |
|
| 40 | + foreach ( $ierr as $thiserr ) |
|
| 41 | + syslog (LOG_ERR, $cf['user'].": IMAP Error: $thiserr"); |
|
| 42 | + if ( $ierr = imap_alerts() ) |
|
| 43 | + foreach ( $ierr as $thiserr ) |
|
| 44 | + syslog (LOG_ALERT, $cf['user'].": IMAP Alert: $thiserr"); |
|
| 45 | 45 | imap_close( $m_mail ); |
| 46 | 46 | return FALSE; |
| 47 | 47 | } |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | syslog (LOG_INFO,$cf['user'].": Found $nmes mail in <$folder> folder."); |
| 50 | 50 | if ($nmes>0) rsort($m_search); |
| 51 | 51 | |
| 52 | - // loop for each message |
|
| 52 | + // loop for each message |
|
| 53 | 53 | foreach ($m_search as $onem) |
| 54 | 54 | $head[] = imap_fetchheader($m_mail, $onem ); |
| 55 | 55 | imap_close($m_mail); |
@@ -80,52 +80,52 @@ discard block |
||
| 80 | 80 | /* Each line must end with /r/n */ |
| 81 | 81 | |
| 82 | 82 | $result = array( |
| 83 | - 'date' => NULL, |
|
| 84 | - 'from' => NULL, |
|
| 85 | - 'messageid' => NULL, |
|
| 83 | + 'date' => NULL, |
|
| 84 | + 'from' => NULL, |
|
| 85 | + 'messageid' => NULL, |
|
| 86 | 86 | 'dmarc' => array( |
| 87 | 87 | 'result' => NULL, |
| 88 | 88 | 'dom' => NULL |
| 89 | 89 | ), |
| 90 | 90 | 'spf' => array( |
| 91 | - 'result' => NULL, |
|
| 92 | - 'dom' => NULL |
|
| 93 | - ), |
|
| 91 | + 'result' => NULL, |
|
| 92 | + 'dom' => NULL |
|
| 93 | + ), |
|
| 94 | 94 | 'dkim' => array( |
| 95 | - 'result' => NULL, |
|
| 96 | - 'dom' => NULL |
|
| 97 | - ), |
|
| 98 | - 'spam' => array( |
|
| 99 | - 'status' => NULL, |
|
| 100 | - 'score' => NULL, |
|
| 101 | - 'th' => NULL, |
|
| 102 | - ), |
|
| 103 | - 'dspam' => array( |
|
| 104 | - 'type' => NULL, |
|
| 105 | - 'level' => NULL, |
|
| 95 | + 'result' => NULL, |
|
| 96 | + 'dom' => NULL |
|
| 97 | + ), |
|
| 98 | + 'spam' => array( |
|
| 99 | + 'status' => NULL, |
|
| 100 | + 'score' => NULL, |
|
| 101 | + 'th' => NULL, |
|
| 102 | + ), |
|
| 103 | + 'dspam' => array( |
|
| 104 | + 'type' => NULL, |
|
| 105 | + 'level' => NULL, |
|
| 106 | 106 | 'learn' => NULL |
| 107 | - ), |
|
| 107 | + ), |
|
| 108 | 108 | 'warn' => NULL |
| 109 | - ); |
|
| 109 | + ); |
|
| 110 | 110 | |
| 111 | 111 | |
| 112 | - if ( preg_match_all ('/^Authentication\-Results:\s+(?<host>[\w\.]+);(?:\s+|\r\n\s+)dmarc=(?<dmarc>\w+)\s+\(p=\w+\s+dis=\w+\)\s+header\.from=(?<DMARCfrom>[\w\.]+)/m',$header,$received) ) { |
|
| 112 | + if ( preg_match_all ('/^Authentication\-Results:\s+(?<host>[\w\.]+);(?:\s+|\r\n\s+)dmarc=(?<dmarc>\w+)\s+\(p=\w+\s+dis=\w+\)\s+header\.from=(?<DMARCfrom>[\w\.]+)/m',$header,$received) ) { |
|
| 113 | 113 | $k=0; |
| 114 | - for ($i = count($received[0])-1;$i>=0;$i--) { |
|
| 115 | - foreach ($ARhosts as $mx) { |
|
| 114 | + for ($i = count($received[0])-1;$i>=0;$i--) { |
|
| 115 | + foreach ($ARhosts as $mx) { |
|
| 116 | 116 | if ($mx == $received['host'][$i]) { |
| 117 | 117 | /* This is a trusted AR result */ |
| 118 | 118 | $result['dmarc']['result']=$received['dmarc'][$i]; |
| 119 | 119 | $result['dmarc']['dom'] = $received['DMARCfrom'][$i]; |
| 120 | 120 | $k++; |
| 121 | 121 | } |
| 122 | - } |
|
| 122 | + } |
|
| 123 | + } |
|
| 123 | 124 | } |
| 124 | - } |
|
| 125 | 125 | $received=NULL; |
| 126 | 126 | if ($k>1) $result['warn'][] = 'The trusted DMARC AR Headers are present more than once. Something wrong.'; |
| 127 | 127 | |
| 128 | - if ( preg_match_all('/^Authentication\-Results:\s+(?<host>[\w\.]+);(?:\s+|\r\n\s+)spf=(?<spf>\w+)\s+smtp\.(?:mailfrom|helo)=(?<SPFfrom>[\w\.]+)/m',$header,$received) ) { |
|
| 128 | + if ( preg_match_all('/^Authentication\-Results:\s+(?<host>[\w\.]+);(?:\s+|\r\n\s+)spf=(?<spf>\w+)\s+smtp\.(?:mailfrom|helo)=(?<SPFfrom>[\w\.]+)/m',$header,$received) ) { |
|
| 129 | 129 | $k=0; |
| 130 | 130 | for ($i = count($received[0])-1;$i>=0;$i--) { |
| 131 | 131 | foreach ($ARhosts as $mx) { |
@@ -134,25 +134,25 @@ discard block |
||
| 134 | 134 | $result['spf']['result']=$received['spf'][$i]; |
| 135 | 135 | $result['spf']['dom'] = $received['SPFfrom'][$i]; |
| 136 | 136 | $k++; |
| 137 | - } |
|
| 138 | - } |
|
| 139 | - } |
|
| 137 | + } |
|
| 138 | + } |
|
| 139 | + } |
|
| 140 | 140 | } |
| 141 | 141 | $received=NULL; |
| 142 | 142 | if ($k>1) $result['warn'][] = 'The trusted SPF AR Headers are present more than once. Something wrong.'; |
| 143 | 143 | |
| 144 | 144 | $k=0; |
| 145 | - if ( preg_match_all('/^Authentication\-Results:\s+(?<host>[\w\.]+);(?:\s+|\r\n\s+)dkim=(?<dkim>\w+)\s+[\w\s\(\)\-]+header\.d=(?<DKIMdom>[\w\.]+)/m',$header,$received) ) { |
|
| 145 | + if ( preg_match_all('/^Authentication\-Results:\s+(?<host>[\w\.]+);(?:\s+|\r\n\s+)dkim=(?<dkim>\w+)\s+[\w\s\(\)\-]+header\.d=(?<DKIMdom>[\w\.]+)/m',$header,$received) ) { |
|
| 146 | 146 | for ($i = count($received[0])-1;$i>=0;$i--) { |
| 147 | - foreach ($ARhosts as $mx) { |
|
| 148 | - if ($mx == $received['host'][$i]) { |
|
| 149 | - /* This is a trusted AR result */ |
|
| 150 | - $result['dkim']['result']=$received['dkim'][$i]; |
|
| 151 | - $result['dkim']['dom'] = $received['DKIMdom'][$i]; |
|
| 147 | + foreach ($ARhosts as $mx) { |
|
| 148 | + if ($mx == $received['host'][$i]) { |
|
| 149 | + /* This is a trusted AR result */ |
|
| 150 | + $result['dkim']['result']=$received['dkim'][$i]; |
|
| 151 | + $result['dkim']['dom'] = $received['DKIMdom'][$i]; |
|
| 152 | 152 | $k++; |
| 153 | - } |
|
| 154 | - } |
|
| 155 | - } |
|
| 153 | + } |
|
| 154 | + } |
|
| 155 | + } |
|
| 156 | 156 | } |
| 157 | 157 | $received=NULL; |
| 158 | 158 | if ($k>1) $result['warn'][] = 'The trusted DKIM AR Headers are present more than once. Something wrong.'; |
@@ -160,59 +160,59 @@ discard block |
||
| 160 | 160 | if ($dpl) { /* Use Spamassassin Plugin */ |
| 161 | 161 | if ( preg_match_all('/^X\-Spam\-Status:\s(?P<spamstatus>\w+)\,(?:\s+|\r\n\s+)score=(?P<score>[\-\.\d]+)(?:\s+|\r\n\s+)tagged_above=\-{0,1}\d+(?:\s+|\r\n\s+)required=(?P<th>[\-\.\d]+)(?:\s+|\r\n\s+)tests=\[(?:.|\r\n\s+)*DSPAM_(?P<dtype>SPAM|HAM)_(?P<dlevel>\d\d)(?:.|\r\n\s+)*\]/m',$header,$received) ) { |
| 162 | 162 | $result['spam']['status']=$received['spamstatus'][0]; |
| 163 | - $result['spam']['score'] = $received['score'][0]; |
|
| 163 | + $result['spam']['score'] = $received['score'][0]; |
|
| 164 | 164 | $result['spam']['th'] = $received['th'][0]; |
| 165 | 165 | $result['dspam']['type'] = dspamType($received['dtype'][0]); |
| 166 | 166 | $result['dspam']['level'] =$received['dlevel'][0]; |
| 167 | - } |
|
| 168 | - if (count($received[0])>1) $result['warn'][] = 'The Spamassassin Headers are present more than once. I consider only the last one.'; |
|
| 167 | + } |
|
| 168 | + if (count($received[0])>1) $result['warn'][] = 'The Spamassassin Headers are present more than once. I consider only the last one.'; |
|
| 169 | 169 | } |
| 170 | 170 | else { /* Parse apart all DSPAM Header and calculate a level */ |
| 171 | 171 | if ( preg_match_all('/^X\-Spam\-Status:\s(?P<spamstatus>\w+)\,(?:\s+|\r\n\s+)score=(?P<score>[\-\.\d]+)(?:\s+|\r\n\s+)tagged_above=\-{0,1}\d+(?:\s+|\r\n\s+)required=(?P<th>[\-\.\d]+)(?:\s+|\r\n\s+)tests=\[(?:.|\r\n\s+)*\]/m',$header,$received) ) { |
| 172 | - $result['spam']['status']=$received['spamstatus'][0]; |
|
| 173 | - $result['spam']['score'] = $received['score'][0]; |
|
| 174 | - $result['spam']['th'] = $received['th'][0]; |
|
| 172 | + $result['spam']['status']=$received['spamstatus'][0]; |
|
| 173 | + $result['spam']['score'] = $received['score'][0]; |
|
| 174 | + $result['spam']['th'] = $received['th'][0]; |
|
| 175 | 175 | if (count($received[0])>1) |
| 176 | 176 | $result['warn'][]= 'The Spamassassin Headers are present more than once. I consider only the last one.'; |
| 177 | 177 | } |
| 178 | 178 | if ( preg_match ('/\r\nX\-DSPAM\-Result:\s(?P<result>.*)\r\n/',$header,$received) != 1) |
| 179 | - $result['warn'] = 'DSPAM Result invalid, not present or present more than once.'; |
|
| 180 | - else |
|
| 181 | - $result['dspam']['type']=$received['result']; |
|
| 179 | + $result['warn'] = 'DSPAM Result invalid, not present or present more than once.'; |
|
| 180 | + else |
|
| 181 | + $result['dspam']['type']=$received['result']; |
|
| 182 | 182 | $prob = NULL; |
| 183 | 183 | $conf = NULL; |
| 184 | - if ( preg_match ('/\r\nX\-DSPAM\-Probability:\s(?P<prob>.*)\r\n/',$header,$received) != 1) |
|
| 185 | - $result['warn'][] = 'DSPAM Probability invalid, not present or present more than once.'; |
|
| 184 | + if ( preg_match ('/\r\nX\-DSPAM\-Probability:\s(?P<prob>.*)\r\n/',$header,$received) != 1) |
|
| 185 | + $result['warn'][] = 'DSPAM Probability invalid, not present or present more than once.'; |
|
| 186 | 186 | else |
| 187 | 187 | $prob = $received['prob']; |
| 188 | 188 | if ( preg_match ('/\r\nX\-DSPAM\-Confidence:\s(?P<conf>.*)\r\n/',$header,$received) != 1) |
| 189 | - $result['warn'][] = 'DSPAM Confidence invalid, not present or present more than once.'; |
|
| 189 | + $result['warn'][] = 'DSPAM Confidence invalid, not present or present more than once.'; |
|
| 190 | 190 | else |
| 191 | 191 | $conf = $received['conf']; |
| 192 | 192 | $result['dspam']['level'] = dspamLevel($prob,$conf); |
| 193 | 193 | } |
| 194 | 194 | $received=NULL; |
| 195 | 195 | if ( preg_match ('/\r\nFrom:\s(?P<from>.*)\r\n/',$header,$received) != 1) |
| 196 | - $result['warn'][] = 'From header invalid or not present'; |
|
| 197 | - else |
|
| 198 | - $result['from'] = $received['from']; |
|
| 196 | + $result['warn'][] = 'From header invalid or not present'; |
|
| 197 | + else |
|
| 198 | + $result['from'] = $received['from']; |
|
| 199 | 199 | |
| 200 | - if ( preg_match ('/\r\nDate:\s(?P<date>.*)\r\n/',$header,$received) != 1) |
|
| 201 | - $result['warn'][] = 'Date header invalid or not present'; |
|
| 200 | + if ( preg_match ('/\r\nDate:\s(?P<date>.*)\r\n/',$header,$received) != 1) |
|
| 201 | + $result['warn'][] = 'Date header invalid or not present'; |
|
| 202 | 202 | else |
| 203 | 203 | $result['date'] = $received['date']; |
| 204 | 204 | |
| 205 | 205 | $received=NULL; |
| 206 | - if ( preg_match ('/\r\nMessage\-I(?:D|d):\s(?P<mid>.*)\r\n/',$header,$received) != 1) |
|
| 207 | - $result['warn'][] = 'Message-ID invalid, not present or present more than once.'; |
|
| 206 | + if ( preg_match ('/\r\nMessage\-I(?:D|d):\s(?P<mid>.*)\r\n/',$header,$received) != 1) |
|
| 207 | + $result['warn'][] = 'Message-ID invalid, not present or present more than once.'; |
|
| 208 | 208 | else |
| 209 | 209 | $result['messageid']=$received['mid']; |
| 210 | 210 | |
| 211 | - $received=NULL; |
|
| 211 | + $received=NULL; |
|
| 212 | 212 | |
| 213 | - switch ($learn) { |
|
| 213 | + switch ($learn) { |
|
| 214 | 214 | case 'dspamc': |
| 215 | - if ( preg_match ('/\r\nX\-DSPAM\-Signature:\s(?P<sig>.*)\r\n/',$header,$received) != 1) |
|
| 215 | + if ( preg_match ('/\r\nX\-DSPAM\-Signature:\s(?P<sig>.*)\r\n/',$header,$received) != 1) |
|
| 216 | 216 | $result['warn'] = 'DSPAM Signature invalid, not present or present more than once.'; |
| 217 | 217 | else |
| 218 | 218 | $result['dspam']['learn']=$received['sig']; |
@@ -223,23 +223,23 @@ discard block |
||
| 223 | 223 | syslog (LOG_INFO,$user.': Error in "learn" imap configuration value. Please, set "dspamc" or "false".'); |
| 224 | 224 | } |
| 225 | 225 | |
| 226 | - return $result; |
|
| 226 | + return $result; |
|
| 227 | 227 | } |
| 228 | 228 | |
| 229 | 229 | |
| 230 | 230 | |
| 231 | 231 | |
| 232 | 232 | function printTableHeader($title,$content,$footer=FALSE,$fcontent) { |
| 233 | - print <<<END |
|
| 233 | + print <<<END |
|
| 234 | 234 | <caption>$title</caption> |
| 235 | 235 | <thead> |
| 236 | 236 | <tr> |
| 237 | 237 | END; |
| 238 | 238 | $kcontent = array_keys($content); |
| 239 | - $cols = count($kcontent); |
|
| 240 | - for ($i=0; $i<$cols; $i++) { |
|
| 239 | + $cols = count($kcontent); |
|
| 240 | + for ($i=0; $i<$cols; $i++) { |
|
| 241 | 241 | $key = $kcontent[$i]; |
| 242 | - printf ('<th colspan="%d" rowspan="%d">%s</th>', |
|
| 242 | + printf ('<th colspan="%d" rowspan="%d">%s</th>', |
|
| 243 | 243 | !is_array($content[$key]) ?: |
| 244 | 244 | count(array_keys($content[$key])) ?: '1', |
| 245 | 245 | !is_array($content[$key]) ?: |
@@ -255,13 +255,13 @@ discard block |
||
| 255 | 255 | } |
| 256 | 256 | } |
| 257 | 257 | |
| 258 | - print '</tr></thead>'; |
|
| 259 | - if ($footer) { |
|
| 260 | - print '<tfoot><tr>'; |
|
| 261 | - print "<th colspan=\"$cols\">".$fcontent.'</th>'; |
|
| 262 | - print '</tr></tfoot>'; |
|
| 263 | - } |
|
| 264 | - return TRUE; |
|
| 258 | + print '</tr></thead>'; |
|
| 259 | + if ($footer) { |
|
| 260 | + print '<tfoot><tr>'; |
|
| 261 | + print "<th colspan=\"$cols\">".$fcontent.'</th>'; |
|
| 262 | + print '</tr></tfoot>'; |
|
| 263 | + } |
|
| 264 | + return TRUE; |
|
| 265 | 265 | } |
| 266 | 266 | |
| 267 | 267 | |
@@ -336,7 +336,7 @@ discard block |
||
| 336 | 336 | } |
| 337 | 337 | /* Spamassassin format */ |
| 338 | 338 | if (isset($row['status'])) |
| 339 | - switch($row['status']) { |
|
| 339 | + switch($row['status']) { |
|
| 340 | 340 | case 'No': |
| 341 | 341 | $color = 'rgba(0,255,0, %.1f)'; |
| 342 | 342 | break; |
@@ -26,12 +26,12 @@ |
||
| 26 | 26 | if ( preg_match ('/^X-DSPAM-Result:\s+(?P<user>[\w\.\@]+);\s+result="(?P<result>\w+)";\s+class="(?P<class>\w+)";\s+probability=(?P<prob>[\d\.]+);\s+confidence=(?P<conf>[\d\.]+);\s+signature=(?P<sig>[\w\,]+)$/',$out[0],$received) != 1) { |
| 27 | 27 | $err = 'DSPAM Client returned an unparseable result.'; |
| 28 | 28 | syslog(LOG_ERR, $username.': Learn Error: '.$err); |
| 29 | - exit (sprintf('<p>%s</p>',htmlentities($err))); |
|
| 29 | + exit (sprintf('<p>%s</p>',htmlentities($err))); |
|
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | printf('<p>Message learned successfully with following result:</p><ul><li>Owner: <b>%s</b></li><li>Result: <b>%s</b></li><li>Class: <b>%s</b></li></ul>', |
| 33 | 33 | htmlentities($received['user']), |
| 34 | - $received['result'], $received['class']); |
|
| 34 | + $received['result'], $received['class']); |
|
| 35 | 35 | closelog(); |
| 36 | 36 | ?> |
| 37 | 37 | </div> |