@@ -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); |
@@ -68,52 +68,52 @@ discard block |
||
| 68 | 68 | /* Each line must end with /r/n */ |
| 69 | 69 | |
| 70 | 70 | $result = array( |
| 71 | - 'date' => NULL, |
|
| 72 | - 'from' => NULL, |
|
| 73 | - 'messageid' => NULL, |
|
| 71 | + 'date' => NULL, |
|
| 72 | + 'from' => NULL, |
|
| 73 | + 'messageid' => NULL, |
|
| 74 | 74 | 'dmarc' => array( |
| 75 | 75 | 'result' => NULL, |
| 76 | 76 | 'dom' => NULL |
| 77 | 77 | ), |
| 78 | 78 | 'spf' => array( |
| 79 | - 'result' => NULL, |
|
| 80 | - 'dom' => NULL |
|
| 81 | - ), |
|
| 79 | + 'result' => NULL, |
|
| 80 | + 'dom' => NULL |
|
| 81 | + ), |
|
| 82 | 82 | 'dkim' => array( |
| 83 | - 'result' => NULL, |
|
| 84 | - 'dom' => NULL |
|
| 85 | - ), |
|
| 86 | - 'spam' => array( |
|
| 87 | - 'status' => NULL, |
|
| 88 | - 'score' => NULL, |
|
| 89 | - 'th' => NULL, |
|
| 90 | - ), |
|
| 91 | - 'dspam' => array( |
|
| 92 | - 'type' => NULL, |
|
| 93 | - 'level' => NULL, |
|
| 83 | + 'result' => NULL, |
|
| 84 | + 'dom' => NULL |
|
| 85 | + ), |
|
| 86 | + 'spam' => array( |
|
| 87 | + 'status' => NULL, |
|
| 88 | + 'score' => NULL, |
|
| 89 | + 'th' => NULL, |
|
| 90 | + ), |
|
| 91 | + 'dspam' => array( |
|
| 92 | + 'type' => NULL, |
|
| 93 | + 'level' => NULL, |
|
| 94 | 94 | 'learn' => NULL |
| 95 | - ), |
|
| 95 | + ), |
|
| 96 | 96 | 'warn' => NULL |
| 97 | - ); |
|
| 97 | + ); |
|
| 98 | 98 | |
| 99 | 99 | |
| 100 | - 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) ) { |
|
| 100 | + 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) ) { |
|
| 101 | 101 | $k=0; |
| 102 | - for ($i = count($received[0])-1;$i>=0;$i--) { |
|
| 103 | - foreach ($ARhosts as $mx) { |
|
| 102 | + for ($i = count($received[0])-1;$i>=0;$i--) { |
|
| 103 | + foreach ($ARhosts as $mx) { |
|
| 104 | 104 | if ($mx == $received['host'][$i]) { |
| 105 | 105 | /* This is a trusted AR result */ |
| 106 | 106 | $result['dmarc']['result']=$received['dmarc'][$i]; |
| 107 | 107 | $result['dmarc']['dom'] = $received['DMARCfrom'][$i]; |
| 108 | 108 | $k++; |
| 109 | 109 | } |
| 110 | - } |
|
| 110 | + } |
|
| 111 | + } |
|
| 111 | 112 | } |
| 112 | - } |
|
| 113 | 113 | $received=NULL; |
| 114 | 114 | if ($k>1) $result['warn'][] = 'The trusted DMARC AR Headers are present more than once. Something wrong.'; |
| 115 | 115 | |
| 116 | - 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) ) { |
|
| 116 | + 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) ) { |
|
| 117 | 117 | $k=0; |
| 118 | 118 | for ($i = count($received[0])-1;$i>=0;$i--) { |
| 119 | 119 | foreach ($ARhosts as $mx) { |
@@ -122,25 +122,25 @@ discard block |
||
| 122 | 122 | $result['spf']['result']=$received['spf'][$i]; |
| 123 | 123 | $result['spf']['dom'] = $received['SPFfrom'][$i]; |
| 124 | 124 | $k++; |
| 125 | - } |
|
| 126 | - } |
|
| 127 | - } |
|
| 125 | + } |
|
| 126 | + } |
|
| 127 | + } |
|
| 128 | 128 | } |
| 129 | 129 | $received=NULL; |
| 130 | 130 | if ($k>1) $result['warn'][] = 'The trusted SPF AR Headers are present more than once. Something wrong.'; |
| 131 | 131 | |
| 132 | 132 | $k=0; |
| 133 | - 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) ) { |
|
| 133 | + 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) ) { |
|
| 134 | 134 | for ($i = count($received[0])-1;$i>=0;$i--) { |
| 135 | - foreach ($ARhosts as $mx) { |
|
| 136 | - if ($mx == $received['host'][$i]) { |
|
| 137 | - /* This is a trusted AR result */ |
|
| 138 | - $result['dkim']['result']=$received['dkim'][$i]; |
|
| 139 | - $result['dkim']['dom'] = $received['DKIMdom'][$i]; |
|
| 135 | + foreach ($ARhosts as $mx) { |
|
| 136 | + if ($mx == $received['host'][$i]) { |
|
| 137 | + /* This is a trusted AR result */ |
|
| 138 | + $result['dkim']['result']=$received['dkim'][$i]; |
|
| 139 | + $result['dkim']['dom'] = $received['DKIMdom'][$i]; |
|
| 140 | 140 | $k++; |
| 141 | - } |
|
| 142 | - } |
|
| 143 | - } |
|
| 141 | + } |
|
| 142 | + } |
|
| 143 | + } |
|
| 144 | 144 | } |
| 145 | 145 | $received=NULL; |
| 146 | 146 | if ($k>1) $result['warn'][] = 'The trusted DKIM AR Headers are present more than once. Something wrong.'; |
@@ -148,59 +148,59 @@ discard block |
||
| 148 | 148 | if ($dpl) { /* Use Spamassassin Plugin */ |
| 149 | 149 | 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) ) { |
| 150 | 150 | $result['spam']['status']=$received['spamstatus'][0]; |
| 151 | - $result['spam']['score'] = $received['score'][0]; |
|
| 151 | + $result['spam']['score'] = $received['score'][0]; |
|
| 152 | 152 | $result['spam']['th'] = $received['th'][0]; |
| 153 | 153 | $result['dspam']['type'] = $received['dtype'][0]; |
| 154 | 154 | $result['dspam']['level'] =$received['dlevel'][0]; |
| 155 | - } |
|
| 156 | - if (count($received[0])>1) $result['warn'][] = 'The Spamassassin Headers are present more than once. I consider only the last one.'; |
|
| 155 | + } |
|
| 156 | + if (count($received[0])>1) $result['warn'][] = 'The Spamassassin Headers are present more than once. I consider only the last one.'; |
|
| 157 | 157 | } |
| 158 | 158 | else { /* Parse apart all DSPAM Header and calculate a level */ |
| 159 | 159 | 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) ) { |
| 160 | - $result['spam']['status']=$received['spamstatus'][0]; |
|
| 161 | - $result['spam']['score'] = $received['score'][0]; |
|
| 162 | - $result['spam']['th'] = $received['th'][0]; |
|
| 160 | + $result['spam']['status']=$received['spamstatus'][0]; |
|
| 161 | + $result['spam']['score'] = $received['score'][0]; |
|
| 162 | + $result['spam']['th'] = $received['th'][0]; |
|
| 163 | 163 | if (count($received[0])>1) |
| 164 | 164 | $result['warn'][]= 'The Spamassassin Headers are present more than once. I consider only the last one.'; |
| 165 | 165 | } |
| 166 | 166 | if ( preg_match ('/\r\nX\-DSPAM\-Result:\s(?P<result>.*)\r\n/',$header,$received) != 1) |
| 167 | - $result['warn'] = 'DSPAM Result invalid, not present or present more than once.'; |
|
| 168 | - else |
|
| 169 | - $result['dspam']['type']=$received['result']; |
|
| 167 | + $result['warn'] = 'DSPAM Result invalid, not present or present more than once.'; |
|
| 168 | + else |
|
| 169 | + $result['dspam']['type']=$received['result']; |
|
| 170 | 170 | $prob = NULL; |
| 171 | 171 | $conf = NULL; |
| 172 | - if ( preg_match ('/\r\nX\-DSPAM\-Probability:\s(?P<prob>.*)\r\n/',$header,$received) != 1) |
|
| 173 | - $result['warn'][] = 'DSPAM Probability invalid, not present or present more than once.'; |
|
| 172 | + if ( preg_match ('/\r\nX\-DSPAM\-Probability:\s(?P<prob>.*)\r\n/',$header,$received) != 1) |
|
| 173 | + $result['warn'][] = 'DSPAM Probability invalid, not present or present more than once.'; |
|
| 174 | 174 | else |
| 175 | 175 | $prob = $received['prob']; |
| 176 | 176 | if ( preg_match ('/\r\nX\-DSPAM\-Confidence:\s(?P<conf>.*)\r\n/',$header,$received) != 1) |
| 177 | - $result['warn'][] = 'DSPAM Confidence invalid, not present or present more than once.'; |
|
| 177 | + $result['warn'][] = 'DSPAM Confidence invalid, not present or present more than once.'; |
|
| 178 | 178 | else |
| 179 | 179 | $conf = $received['conf']; |
| 180 | 180 | $result['dspam']['level'] = dspamLevel($prob,$conf); |
| 181 | 181 | } |
| 182 | 182 | $received=NULL; |
| 183 | 183 | if ( preg_match ('/\r\nFrom:\s(?P<from>.*)\r\n/',$header,$received) != 1) |
| 184 | - $result['warn'][] = 'From header invalid or not present'; |
|
| 185 | - else |
|
| 186 | - $result['from'] = $received['from']; |
|
| 184 | + $result['warn'][] = 'From header invalid or not present'; |
|
| 185 | + else |
|
| 186 | + $result['from'] = $received['from']; |
|
| 187 | 187 | |
| 188 | - if ( preg_match ('/\r\nDate:\s(?P<date>.*)\r\n/',$header,$received) != 1) |
|
| 189 | - $result['warn'][] = 'Date header invalid or not present'; |
|
| 188 | + if ( preg_match ('/\r\nDate:\s(?P<date>.*)\r\n/',$header,$received) != 1) |
|
| 189 | + $result['warn'][] = 'Date header invalid or not present'; |
|
| 190 | 190 | else |
| 191 | 191 | $result['date'] = $received['date']; |
| 192 | 192 | |
| 193 | 193 | $received=NULL; |
| 194 | - if ( preg_match ('/\r\nMessage\-I(?:D|d):\s(?P<mid>.*)\r\n/',$header,$received) != 1) |
|
| 195 | - $result['warn'][] = 'Message-ID invalid, not present or present more than once.'; |
|
| 194 | + if ( preg_match ('/\r\nMessage\-I(?:D|d):\s(?P<mid>.*)\r\n/',$header,$received) != 1) |
|
| 195 | + $result['warn'][] = 'Message-ID invalid, not present or present more than once.'; |
|
| 196 | 196 | else |
| 197 | 197 | $result['messageid']=$received['mid']; |
| 198 | 198 | |
| 199 | - $received=NULL; |
|
| 199 | + $received=NULL; |
|
| 200 | 200 | |
| 201 | - switch ($learn) { |
|
| 201 | + switch ($learn) { |
|
| 202 | 202 | case 'dspamc': |
| 203 | - if ( preg_match ('/\r\nX\-DSPAM\-Signature:\s(?P<sig>.*)\r\n/',$header,$received) != 1) |
|
| 203 | + if ( preg_match ('/\r\nX\-DSPAM\-Signature:\s(?P<sig>.*)\r\n/',$header,$received) != 1) |
|
| 204 | 204 | $result['warn'] = 'DSPAM Signature invalid, not present or present more than once.'; |
| 205 | 205 | else |
| 206 | 206 | $result['dspam']['learn']=$received['sig']; |
@@ -211,23 +211,23 @@ discard block |
||
| 211 | 211 | syslog (LOG_INFO,$user.': Error in "learn" imap configuration value. Please, set "dspamc" or "false".'); |
| 212 | 212 | } |
| 213 | 213 | |
| 214 | - return $result; |
|
| 214 | + return $result; |
|
| 215 | 215 | } |
| 216 | 216 | |
| 217 | 217 | |
| 218 | 218 | |
| 219 | 219 | |
| 220 | 220 | function printTableHeader($title,$content,$footer=FALSE,$fcontent) { |
| 221 | - print <<<END |
|
| 221 | + print <<<END |
|
| 222 | 222 | <caption>$title</caption> |
| 223 | 223 | <thead> |
| 224 | 224 | <tr> |
| 225 | 225 | END; |
| 226 | 226 | $kcontent = array_keys($content); |
| 227 | - $cols = count($kcontent); |
|
| 228 | - for ($i=0; $i<$cols; $i++) { |
|
| 227 | + $cols = count($kcontent); |
|
| 228 | + for ($i=0; $i<$cols; $i++) { |
|
| 229 | 229 | $key = $kcontent[$i]; |
| 230 | - printf ('<th colspan="%d" rowspan="%d">%s</th>', |
|
| 230 | + printf ('<th colspan="%d" rowspan="%d">%s</th>', |
|
| 231 | 231 | !is_array($content[$key]) ?: |
| 232 | 232 | count(array_keys($content[$key])) ?: '1', |
| 233 | 233 | !is_array($content[$key]) ?: |
@@ -243,13 +243,13 @@ discard block |
||
| 243 | 243 | } |
| 244 | 244 | } |
| 245 | 245 | |
| 246 | - print '</tr></thead>'; |
|
| 247 | - if ($footer) { |
|
| 248 | - print '<tfoot><tr>'; |
|
| 249 | - print "<th colspan=\"$cols\">".$fcontent.'</th>'; |
|
| 250 | - print '</tr></tfoot>'; |
|
| 251 | - } |
|
| 252 | - return TRUE; |
|
| 246 | + print '</tr></thead>'; |
|
| 247 | + if ($footer) { |
|
| 248 | + print '<tfoot><tr>'; |
|
| 249 | + print "<th colspan=\"$cols\">".$fcontent.'</th>'; |
|
| 250 | + print '</tr></tfoot>'; |
|
| 251 | + } |
|
| 252 | + return TRUE; |
|
| 253 | 253 | } |
| 254 | 254 | |
| 255 | 255 | |
@@ -324,7 +324,7 @@ discard block |
||
| 324 | 324 | } |
| 325 | 325 | /* Spamassassin format */ |
| 326 | 326 | if (isset($row['status'])) |
| 327 | - switch($row['status']) { |
|
| 327 | + switch($row['status']) { |
|
| 328 | 328 | case 'No': |
| 329 | 329 | $color = 'rgba(0,255,0, %.1f)'; |
| 330 | 330 | break; |