GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 85bafa...f24c75 )
by Marco
02:02
created
contrib/mailClassifier/function.php 3 patches
Indentation   +85 added lines, -85 removed lines patch added patch discarded remove patch
@@ -3,13 +3,13 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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;
Please login to merge, or discard this patch.
Spacing   +85 added lines, -87 removed lines patch added patch discarded remove patch
@@ -2,56 +2,56 @@  discard block
 block discarded – undo
2 2
 
3 3
 function imapFolder($cf, $username) {
4 4
 	$return = array();
5
-	$open='{'.$cf['mailhost'].':143/imap/novalidate-cert/authuser='.$cf['authuser'].'}';
5
+	$open = '{'.$cf['mailhost'].':143/imap/novalidate-cert/authuser='.$cf['authuser'].'}';
6 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);
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.'>...');
11
+        syslog(LOG_INFO, $cf['user'].': Successfully connected to <'.$cf['mailhost'].'>; Listing folders of account <'.$username.'>...');
12 12
         //get all folder
13 13
 	$list = imap_list($m_mail, $open, "*");
14 14
 	imap_close($m_mail);
15 15
 	if (is_array($list))
16 16
 		foreach ($list as $mbox)
17
-			$return[] = explode($open,$mbox,2)[1];
17
+			$return[] = explode($open, $mbox, 2)[1];
18 18
 	else
19
-		syslog (LOG_INFO,$cf['user'] . ': imap_list failed: ' . imap_last_error() );
19
+		syslog(LOG_INFO, $cf['user'].': imap_list failed: '.imap_last_error());
20 20
 	return $return;
21 21
 }
22 22
 
23
-function imapFind ($cf, $username, $folder) {
24
-	$head=array();
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());
27
-	if ( !$m_mail ) exit(254);
23
+function imapFind($cf, $username, $folder) {
24
+	$head = array();
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());
27
+	if (!$m_mail) exit(254);
28 28
 		
29 29
 
30
-	syslog (LOG_INFO,$cf['user'].': Successfully connected to <'.$cf['mailhost'].">; Reading <$folder> messages of last ".$cf['oldestday'].' days on account <'.$username.'>...');
30
+	syslog(LOG_INFO, $cf['user'].': Successfully connected to <'.$cf['mailhost'].">; Reading <$folder> messages of last ".$cf['oldestday'].' days on account <'.$username.'>...');
31 31
 	//get all messages
32
-	$dateTh = date ( "d-M-Y", strToTime ( '-'.$cf['oldestday'].' days' ) );
33
-	$m_search=imap_search ($m_mail, "SINCE \"$dateTh\" TEXT \"Authentication-Results: \"" );
32
+	$dateTh = date("d-M-Y", strToTime('-'.$cf['oldestday'].' days'));
33
+	$m_search = imap_search($m_mail, "SINCE \"$dateTh\" TEXT \"Authentication-Results: \"");
34 34
 
35 35
 
36 36
 	// Order results starting from newest message
37
-	if ( empty($m_search) ) {
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");
45
-		imap_close( $m_mail );
37
+	if (empty($m_search)) {
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");
45
+		imap_close($m_mail);
46 46
 		return FALSE;
47 47
 	}
48
-	$nmes = count ($m_search);
49
-	syslog (LOG_INFO,$cf['user'].": Found $nmes mail in <$folder> folder.");
48
+	$nmes = count($m_search);
49
+	syslog(LOG_INFO, $cf['user'].": Found $nmes mail in <$folder> folder.");
50 50
 	if ($nmes>0) rsort($m_search);
51 51
 
52 52
         // loop for each message
53 53
 	foreach ($m_search as $onem) 
54
-		$head[] = imap_fetchheader($m_mail, $onem );
54
+		$head[] = imap_fetchheader($m_mail, $onem);
55 55
 	imap_close($m_mail);
56 56
 	return $head;
57 57
 }
@@ -59,11 +59,11 @@  discard block
 block discarded – undo
59 59
 function dspamLevel($prob, $conf) {
60 60
 /* Calculate DSPAM Level as the Spamassassin Plugin */
61 61
 	if (is_null($prob) or is_null($conf)) return '-';
62
-	$t_prob = abs((($prob - 0.5) * 2) * 100);
63
-	return round(($t_prob + ($conf*100)) / 2);
62
+	$t_prob = abs((($prob-0.5) * 2) * 100);
63
+	return round(($t_prob+($conf * 100)) / 2);
64 64
 }
65 65
 
66
-function imapInfo($user,$header,$ARhosts,$dpl=false, $learn=false) {
66
+function imapInfo($user, $header, $ARhosts, $dpl = false, $learn = false) {
67 67
 /* Get relevant Info from header's mail */
68 68
 /* Each line must end with /r/n         */
69 69
 
@@ -97,118 +97,118 @@  discard block
 block discarded – undo
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) ) {
101
-		$k=0;
102
-                for ($i = count($received[0])-1;$i>=0;$i--) {
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
+		$k = 0;
102
+                for ($i = count($received[0])-1; $i>=0; $i--) {
103 103
 	                foreach ($ARhosts as $mx) {
104 104
 				if ($mx == $received['host'][$i]) {
105 105
 					/* This is a trusted AR result */
106
-					$result['dmarc']['result']=$received['dmarc'][$i];
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
-	$received=NULL;
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) ) {
117
-		$k=0;
118
-		for ($i = count($received[0])-1;$i>=0;$i--) {
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
+		$k = 0;
118
+		for ($i = count($received[0])-1; $i>=0; $i--) {
119 119
 			foreach ($ARhosts as $mx) {
120 120
 				if ($mx == $received['host'][$i]) {
121 121
 					/* This is a trusted AR result */
122
-					$result['spf']['result']=$received['spf'][$i];
122
+					$result['spf']['result'] = $received['spf'][$i];
123 123
 					$result['spf']['dom'] = $received['SPFfrom'][$i];
124 124
 					$k++;
125 125
                         	}
126 126
                 	}
127 127
         	}
128 128
 	}
129
-	$received=NULL;
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
-	$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) ) {
134
-		for ($i = count($received[0])-1;$i>=0;$i--) {
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)) {
134
+		for ($i = count($received[0])-1; $i>=0; $i--) {
135 135
 	                foreach ($ARhosts as $mx) {
136 136
         	                if ($mx == $received['host'][$i]) {
137 137
                 	                /* This is a trusted AR result */
138
-                        	        $result['dkim']['result']=$received['dkim'][$i];
138
+                        	        $result['dkim']['result'] = $received['dkim'][$i];
139 139
                                 	$result['dkim']['dom'] = $received['DKIMdom'][$i];
140 140
 					$k++;
141 141
                         	}
142 142
                 	}
143 143
         	}
144 144
 	}
145
-	$received=NULL;
145
+	$received = NULL;
146 146
 	if ($k>1) $result['warn'][] = 'The trusted DKIM AR Headers are present more than once. Something wrong.';
147 147
 
148 148
 	if ($dpl) { /* Use Spamassassin Plugin */
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
-			$result['spam']['status']=$received['spamstatus'][0];
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
+			$result['spam']['status'] = $received['spamstatus'][0];
151 151
                 	$result['spam']['score'] = $received['score'][0];
152 152
 			$result['spam']['th'] = $received['th'][0];
153 153
 			$result['dspam']['type'] = $received['dtype'][0];
154
-			$result['dspam']['level'] =$received['dlevel'][0];
154
+			$result['dspam']['level'] = $received['dlevel'][0];
155 155
         	}
156 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
-		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];
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 161
                         $result['spam']['score'] = $received['score'][0];
162 162
                         $result['spam']['th'] = $received['th'][0];
163 163
 			if (count($received[0])>1)
164
-				$result['warn'][]= 'The Spamassassin Headers are present more than once. I consider only the last one.';
164
+				$result['warn'][] = 'The Spamassassin Headers are present more than once. I consider only the last one.';
165 165
 		}
166
-		if ( preg_match ('/\r\nX\-DSPAM\-Result:\s(?P<result>.*)\r\n/',$header,$received) != 1)
166
+		if (preg_match('/\r\nX\-DSPAM\-Result:\s(?P<result>.*)\r\n/', $header, $received) != 1)
167 167
 	                $result['warn'] = 'DSPAM Result invalid, not present or present more than once.';
168 168
 	        else
169
-                	$result['dspam']['type']=$received['result'];
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)
172
+                if (preg_match('/\r\nX\-DSPAM\-Probability:\s(?P<prob>.*)\r\n/', $header, $received) != 1)
173 173
                         $result['warn'][] = 'DSPAM Probability invalid, not present or present more than once.';
174 174
 		else
175 175
 			$prob = $received['prob'];
176
-		if ( preg_match ('/\r\nX\-DSPAM\-Confidence:\s(?P<conf>.*)\r\n/',$header,$received) != 1)
176
+		if (preg_match('/\r\nX\-DSPAM\-Confidence:\s(?P<conf>.*)\r\n/', $header, $received) != 1)
177 177
                         $result['warn'][] = 'DSPAM Confidence invalid, not present or present more than once.';
178 178
 		else
179 179
 			$conf = $received['conf'];
180
-		$result['dspam']['level'] = dspamLevel($prob,$conf);
180
+		$result['dspam']['level'] = dspamLevel($prob, $conf);
181 181
 	}
182
-	$received=NULL;
183
-	if ( preg_match ('/\r\nFrom:\s(?P<from>.*)\r\n/',$header,$received) != 1)
182
+	$received = NULL;
183
+	if (preg_match('/\r\nFrom:\s(?P<from>.*)\r\n/', $header, $received) != 1)
184 184
                 $result['warn'][] = 'From header invalid or not present';
185 185
         else
186 186
                 $result['from'] = $received['from'];
187 187
 
188
-        if ( preg_match ('/\r\nDate:\s(?P<date>.*)\r\n/',$header,$received) != 1)
188
+        if (preg_match('/\r\nDate:\s(?P<date>.*)\r\n/', $header, $received) != 1)
189 189
                 $result['warn'][] = 'Date header invalid or not present';
190 190
 	else
191 191
 		$result['date'] = $received['date'];
192 192
 
193
-	$received=NULL;
194
-        if ( preg_match ('/\r\nMessage\-I(?:D|d):\s(?P<mid>.*)\r\n/',$header,$received) != 1)
193
+	$received = NULL;
194
+        if (preg_match('/\r\nMessage\-I(?:D|d):\s(?P<mid>.*)\r\n/', $header, $received) != 1)
195 195
                 $result['warn'][] = 'Message-ID invalid, not present or present more than once.';
196 196
 	else
197
-		$result['messageid']=$received['mid'];
197
+		$result['messageid'] = $received['mid'];
198 198
 
199
-        $received=NULL;
199
+        $received = NULL;
200 200
 
201 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
-				$result['dspam']['learn']=$received['sig'];			
206
+				$result['dspam']['learn'] = $received['sig'];			
207 207
 			break;
208 208
 		case false:
209 209
 			break;
210 210
 		default:
211
-			syslog (LOG_INFO,$user.': Error in "learn" imap configuration value. Please, set "dspamc" or "false".');
211
+			syslog(LOG_INFO, $user.': Error in "learn" imap configuration value. Please, set "dspamc" or "false".');
212 212
 	}
213 213
 	
214 214
         return $result;
@@ -217,7 +217,7 @@  discard block
 block discarded – undo
217 217
 
218 218
 
219 219
 
220
-function printTableHeader($title,$content,$footer=FALSE,$fcontent) {
220
+function printTableHeader($title, $content, $footer = FALSE, $fcontent) {
221 221
         print <<<END
222 222
 	<caption>$title</caption>
223 223
 	<thead>
@@ -225,21 +225,19 @@  discard block
 block discarded – undo
225 225
 END;
226 226
 	$kcontent = array_keys($content);
227 227
         $cols = count($kcontent);
228
-        for ($i=0; $i<$cols; $i++) {
228
+        for ($i = 0; $i<$cols; $i++) {
229 229
 		$key = $kcontent[$i];
230
-                printf ('<th colspan="%d" rowspan="%d">%s</th>',
231
-			!is_array($content[$key]) ?:
232
-			count(array_keys($content[$key])) ?: '1',
233
-			!is_array($content[$key]) ?:
234
-			empty(array_keys($content[$key])) ? '2' : '1',
230
+                printf('<th colspan="%d" rowspan="%d">%s</th>',
231
+			!is_array($content[$key]) ?: count(array_keys($content[$key])) ?: '1',
232
+			!is_array($content[$key]) ?: empty(array_keys($content[$key])) ? '2' : '1',
235 233
 			$kcontent[$i]);
236 234
 	}
237 235
 	print '</tr><tr>';
238
-	for ($i=0; $i<$cols; $i++) {
236
+	for ($i = 0; $i<$cols; $i++) {
239 237
 		$key = $kcontent[$i];
240
-		if (is_array($content[$key])&&($hs = array_keys($content[$key]))) {
238
+		if (is_array($content[$key]) && ($hs = array_keys($content[$key]))) {
241 239
 			foreach ($hs as $h)
242
-				printf('<th>%s</th>',$h);
240
+				printf('<th>%s</th>', $h);
243 241
 		}
244 242
 	}
245 243
 		
@@ -255,7 +253,7 @@  discard block
 block discarded – undo
255 253
 
256 254
 function formatVal($val, $learn) {
257 255
 	foreach (array_keys($val) as $key) {
258
-		if (is_array($val["$key"]) and ($key!='warn'))
256
+		if (is_array($val["$key"]) and ($key != 'warn'))
259 257
 			$val["$key"] = formatVal($val["$key"], $learn);
260 258
 		else {
261 259
 			switch ($key) {
@@ -263,7 +261,7 @@  discard block
 block discarded – undo
263 261
 					if (empty($val["$key"]))
264 262
 						$val["$key"] = '-';
265 263
 					else 
266
-						$val["$key"] = sprintf('<div title="%s">Y</div>',implode($val["$key"],"\n"));
264
+						$val["$key"] = sprintf('<div title="%s">Y</div>', implode($val["$key"], "\n"));
267 265
 					break;
268 266
 				case 'learn':
269 267
 					$val["$key"] = formLearn($learn, $val);
@@ -285,26 +283,26 @@  discard block
 block discarded – undo
285 283
 				$par['class'] = $class;
286 284
 				$val["$class"] = sprintf('dspamc --user dspam --deliver=summary --class=%s --source=error --signature=%s',
287 285
 							strtolower($class), $par['learn']);
288
-				if (($class != $par['type'])||($par['level']<99))
286
+				if (($class != $par['type']) || ($par['level']<99))
289 287
 					$return .= sprintf(file_get_contents('formLearnDSPAM.htm'),
290
-						$class,$class,$val["$class"],base64_encode(json_encode($par)),$class);
288
+						$class, $class, $val["$class"], base64_encode(json_encode($par)), $class);
291 289
 			}
292 290
 		default:
293 291
 			return $return;
294 292
 	}
295 293
 }
296 294
 
297
-function printTableRow($row, $learn, $init=true) {
295
+function printTableRow($row, $learn, $init = true) {
298 296
 	$color = 'inherit';
299 297
 	if ($init) 
300
-		$row=formatVal($row,$learn);
301
-	foreach( $row as $key => $val) {
298
+		$row = formatVal($row, $learn);
299
+	foreach ($row as $key => $val) {
302 300
 		if (is_array($val))
303 301
 			printTableRow($val, $learn, false);
304 302
 		else {
305 303
 			/* DSPAM format */
306 304
 			if (isset($row['type']))
307
-				switch($row['type']) {
305
+				switch ($row['type']) {
308 306
 					case 'Innocent':
309 307
 					case 'HAM':
310 308
 						$color = 'rgba(0,255,0, %.1f)';
@@ -315,7 +313,7 @@  discard block
 block discarded – undo
315 313
 			}
316 314
 			/* DMARC, DKIM, SPF format */
317 315
 			if (isset($row['result']))
318
-				switch($row['result']) {
316
+				switch ($row['result']) {
319 317
 					case 'pass':
320 318
 						$color = 'rgba(0,255,0, %.1f)';
321 319
 						break;
@@ -324,7 +322,7 @@  discard block
 block discarded – undo
324 322
 				}
325 323
 			/* Spamassassin format */
326 324
 			if (isset($row['status']))
327
-	                        switch($row['status']) {
325
+	                        switch ($row['status']) {
328 326
 					case 'No':
329 327
 						$color = 'rgba(0,255,0, %.1f)';
330 328
 						break;
@@ -332,9 +330,9 @@  discard block
 block discarded – undo
332 330
 						$color = 'rgba(255,0,0,%.1f)';
333 331
 				}	
334 332
 				
335
-			$alpha = (is_numeric($val)AND($key=='type')) ? round($val/100,1) : 1.0;
333
+			$alpha = (is_numeric($val) AND ($key == 'type')) ? round($val / 100, 1) : 1.0;
336 334
 			$bg = sprintf(" style=\"background-color: $color\"", $alpha);		
337
-			printf ('<td%s>%s</td>',$bg, $val);
335
+			printf('<td%s>%s</td>', $bg, $val);
338 336
 		}
339 337
 	}
340 338
 }
Please login to merge, or discard this patch.
Braces   +106 added lines, -72 removed lines patch added patch discarded remove patch
@@ -5,18 +5,21 @@  discard block
 block discarded – undo
5 5
 	$open='{'.$cf['mailhost'].':143/imap/novalidate-cert/authuser='.$cf['authuser'].'}';
6 6
         $m_mail = imap_open($open, $username, $cf['authpassword'], OP_READONLY)
7 7
                 or syslog (LOG_EMERG, $cf['user'].': Error in IMAP connection to <'.$cf['mailhost'].'>: ' . imap_last_error());
8
-        if ( !$m_mail ) exit(254);
8
+        if ( !$m_mail ) {
9
+        	exit(254);
10
+        }
9 11
 
10 12
 
11 13
         syslog (LOG_INFO,$cf['user'].': Successfully connected to <'.$cf['mailhost'].'>; Listing folders of account <'.$username.'>...');
12 14
         //get all folder
13 15
 	$list = imap_list($m_mail, $open, "*");
14 16
 	imap_close($m_mail);
15
-	if (is_array($list))
16
-		foreach ($list as $mbox)
17
+	if (is_array($list)) {
18
+			foreach ($list as $mbox)
17 19
 			$return[] = explode($open,$mbox,2)[1];
18
-	else
19
-		syslog (LOG_INFO,$cf['user'] . ': imap_list failed: ' . imap_last_error() );
20
+	} else {
21
+			syslog (LOG_INFO,$cf['user'] . ': imap_list failed: ' . imap_last_error() );
22
+	}
20 23
 	return $return;
21 24
 }
22 25
 
@@ -24,7 +27,9 @@  discard block
 block discarded – undo
24 27
 	$head=array();
25 28
 	$m_mail = imap_open('{'.$cf['mailhost'].':143/imap/novalidate-cert/authuser='.$cf['authuser'].'}'.$folder, $username,$cf['authpassword'], OP_READONLY)
26 29
         	or syslog (LOG_EMERG, $cf['user'].': Error in IMAP connection to <'.$cf['mailhost'].'>: ' . imap_last_error());
27
-	if ( !$m_mail ) exit(254);
30
+	if ( !$m_mail ) {
31
+		exit(254);
32
+	}
28 33
 		
29 34
 
30 35
 	syslog (LOG_INFO,$cf['user'].': Successfully connected to <'.$cf['mailhost'].">; Reading <$folder> messages of last ".$cf['oldestday'].' days on account <'.$username.'>...');
@@ -36,29 +41,36 @@  discard block
 block discarded – undo
36 41
 	// Order results starting from newest message
37 42
 	if ( empty($m_search) ) {
38 43
 		syslog (LOG_INFO,$cf['user'].": No suitable mail found in <$folder> folder.");
39
-	        if ( $ierr = imap_errors() )
40
-	                foreach ( $ierr as $thiserr )
44
+	        if ( $ierr = imap_errors() ) {
45
+	        	                foreach ( $ierr as $thiserr )
41 46
 	                        syslog (LOG_ERR, $cf['user'].": IMAP Error: $thiserr");
42
-	        if ( $ierr = imap_alerts() )
43
-	                foreach ( $ierr as $thiserr )
47
+	        }
48
+	        if ( $ierr = imap_alerts() ) {
49
+	        	                foreach ( $ierr as $thiserr )
44 50
 	                        syslog (LOG_ALERT, $cf['user'].": IMAP Alert: $thiserr");
51
+	        }
45 52
 		imap_close( $m_mail );
46 53
 		return FALSE;
47 54
 	}
48 55
 	$nmes = count ($m_search);
49 56
 	syslog (LOG_INFO,$cf['user'].": Found $nmes mail in <$folder> folder.");
50
-	if ($nmes>0) rsort($m_search);
57
+	if ($nmes>0) {
58
+		rsort($m_search);
59
+	}
51 60
 
52 61
         // loop for each message
53
-	foreach ($m_search as $onem) 
54
-		$head[] = imap_fetchheader($m_mail, $onem );
62
+	foreach ($m_search as $onem) {
63
+			$head[] = imap_fetchheader($m_mail, $onem );
64
+	}
55 65
 	imap_close($m_mail);
56 66
 	return $head;
57 67
 }
58 68
 
59 69
 function dspamLevel($prob, $conf) {
60 70
 /* Calculate DSPAM Level as the Spamassassin Plugin */
61
-	if (is_null($prob) or is_null($conf)) return '-';
71
+	if (is_null($prob) or is_null($conf)) {
72
+		return '-';
73
+	}
62 74
 	$t_prob = abs((($prob - 0.5) * 2) * 100);
63 75
 	return round(($t_prob + ($conf*100)) / 2);
64 76
 }
@@ -111,7 +123,9 @@  discard block
 block discarded – undo
111 123
 		}
112 124
         }
113 125
 	$received=NULL;
114
-	if ($k>1) $result['warn'][] = 'The trusted DMARC AR Headers are present more than once. Something wrong.';
126
+	if ($k>1) {
127
+		$result['warn'][] = 'The trusted DMARC AR Headers are present more than once. Something wrong.';
128
+	}
115 129
 
116 130
         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 131
 		$k=0;
@@ -127,7 +141,9 @@  discard block
 block discarded – undo
127 141
         	}
128 142
 	}
129 143
 	$received=NULL;
130
-	if ($k>1) $result['warn'][] = 'The trusted SPF AR Headers are present more than once. Something wrong.';
144
+	if ($k>1) {
145
+		$result['warn'][] = 'The trusted SPF AR Headers are present more than once. Something wrong.';
146
+	}
131 147
 
132 148
 	$k=0;
133 149
         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) ) {
@@ -143,7 +159,9 @@  discard block
 block discarded – undo
143 159
         	}
144 160
 	}
145 161
 	$received=NULL;
146
-	if ($k>1) $result['warn'][] = 'The trusted DKIM AR Headers are present more than once. Something wrong.';
162
+	if ($k>1) {
163
+		$result['warn'][] = 'The trusted DKIM AR Headers are present more than once. Something wrong.';
164
+	}
147 165
 
148 166
 	if ($dpl) { /* Use Spamassassin Plugin */
149 167
 		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) ) {
@@ -153,57 +171,66 @@  discard block
 block discarded – undo
153 171
 			$result['dspam']['type'] = $received['dtype'][0];
154 172
 			$result['dspam']['level'] =$received['dlevel'][0];
155 173
         	}
156
-        	if (count($received[0])>1) $result['warn'][] = 'The Spamassassin Headers are present more than once. I consider only the last one.';
157
-	}
158
-	else { /* Parse apart all DSPAM Header and calculate a level */
174
+        	if (count($received[0])>1) {
175
+        		$result['warn'][] = 'The Spamassassin Headers are present more than once. I consider only the last one.';
176
+        	}
177
+	} else { /* Parse apart all DSPAM Header and calculate a level */
159 178
 		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 179
                         $result['spam']['status']=$received['spamstatus'][0];
161 180
                         $result['spam']['score'] = $received['score'][0];
162 181
                         $result['spam']['th'] = $received['th'][0];
163
-			if (count($received[0])>1)
164
-				$result['warn'][]= 'The Spamassassin Headers are present more than once. I consider only the last one.';
182
+			if (count($received[0])>1) {
183
+							$result['warn'][]= 'The Spamassassin Headers are present more than once. I consider only the last one.';
184
+			}
165 185
 		}
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'];
186
+		if ( preg_match ('/\r\nX\-DSPAM\-Result:\s(?P<result>.*)\r\n/',$header,$received) != 1) {
187
+			                $result['warn'] = 'DSPAM Result invalid, not present or present more than once.';
188
+		} else {
189
+	                        	$result['dspam']['type']=$received['result'];
190
+	        }
170 191
 		$prob = NULL;
171 192
 		$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.';
174
-		else
175
-			$prob = $received['prob'];
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.';
178
-		else
179
-			$conf = $received['conf'];
193
+                if ( preg_match ('/\r\nX\-DSPAM\-Probability:\s(?P<prob>.*)\r\n/',$header,$received) != 1) {
194
+                                        $result['warn'][] = 'DSPAM Probability invalid, not present or present more than once.';
195
+                } else {
196
+					$prob = $received['prob'];
197
+		}
198
+		if ( preg_match ('/\r\nX\-DSPAM\-Confidence:\s(?P<conf>.*)\r\n/',$header,$received) != 1) {
199
+		                        $result['warn'][] = 'DSPAM Confidence invalid, not present or present more than once.';
200
+		} else {
201
+					$conf = $received['conf'];
202
+		}
180 203
 		$result['dspam']['level'] = dspamLevel($prob,$conf);
181 204
 	}
182 205
 	$received=NULL;
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'];
206
+	if ( preg_match ('/\r\nFrom:\s(?P<from>.*)\r\n/',$header,$received) != 1) {
207
+	                $result['warn'][] = 'From header invalid or not present';
208
+	} else {
209
+                        $result['from'] = $received['from'];
210
+        }
187 211
 
188
-        if ( preg_match ('/\r\nDate:\s(?P<date>.*)\r\n/',$header,$received) != 1)
189
-                $result['warn'][] = 'Date header invalid or not present';
190
-	else
191
-		$result['date'] = $received['date'];
212
+        if ( preg_match ('/\r\nDate:\s(?P<date>.*)\r\n/',$header,$received) != 1) {
213
+                        $result['warn'][] = 'Date header invalid or not present';
214
+        } else {
215
+			$result['date'] = $received['date'];
216
+	}
192 217
 
193 218
 	$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.';
196
-	else
197
-		$result['messageid']=$received['mid'];
219
+        if ( preg_match ('/\r\nMessage\-I(?:D|d):\s(?P<mid>.*)\r\n/',$header,$received) != 1) {
220
+                        $result['warn'][] = 'Message-ID invalid, not present or present more than once.';
221
+        } else {
222
+			$result['messageid']=$received['mid'];
223
+	}
198 224
 
199 225
         $received=NULL;
200 226
 
201 227
         switch ($learn) {
202 228
 		case 'dspamc':
203
-        		if ( preg_match ('/\r\nX\-DSPAM\-Signature:\s(?P<sig>.*)\r\n/',$header,$received) != 1)
204
-				$result['warn'] = 'DSPAM Signature invalid, not present or present more than once.';
205
-			else
206
-				$result['dspam']['learn']=$received['sig'];			
229
+        		if ( preg_match ('/\r\nX\-DSPAM\-Signature:\s(?P<sig>.*)\r\n/',$header,$received) != 1) {
230
+        						$result['warn'] = 'DSPAM Signature invalid, not present or present more than once.';
231
+        		} else {
232
+							$result['dspam']['learn']=$received['sig'];
233
+			}
207 234
 			break;
208 235
 		case false:
209 236
 			break;
@@ -238,8 +265,9 @@  discard block
 block discarded – undo
238 265
 	for ($i=0; $i<$cols; $i++) {
239 266
 		$key = $kcontent[$i];
240 267
 		if (is_array($content[$key])&&($hs = array_keys($content[$key]))) {
241
-			foreach ($hs as $h)
242
-				printf('<th>%s</th>',$h);
268
+			foreach ($hs as $h) {
269
+							printf('<th>%s</th>',$h);
270
+			}
243 271
 		}
244 272
 	}
245 273
 		
@@ -255,15 +283,16 @@  discard block
 block discarded – undo
255 283
 
256 284
 function formatVal($val, $learn) {
257 285
 	foreach (array_keys($val) as $key) {
258
-		if (is_array($val["$key"]) and ($key!='warn'))
259
-			$val["$key"] = formatVal($val["$key"], $learn);
260
-		else {
286
+		if (is_array($val["$key"]) and ($key!='warn')) {
287
+					$val["$key"] = formatVal($val["$key"], $learn);
288
+		} else {
261 289
 			switch ($key) {
262 290
 				case 'warn':
263
-					if (empty($val["$key"]))
264
-						$val["$key"] = '-';
265
-					else 
266
-						$val["$key"] = sprintf('<div title="%s">Y</div>',implode($val["$key"],"\n"));
291
+					if (empty($val["$key"])) {
292
+											$val["$key"] = '-';
293
+					} else {
294
+											$val["$key"] = sprintf('<div title="%s">Y</div>',implode($val["$key"],"\n"));
295
+					}
267 296
 					break;
268 297
 				case 'learn':
269 298
 					$val["$key"] = formLearn($learn, $val);
@@ -285,9 +314,10 @@  discard block
 block discarded – undo
285 314
 				$par['class'] = $class;
286 315
 				$val["$class"] = sprintf('dspamc --user dspam --deliver=summary --class=%s --source=error --signature=%s',
287 316
 							strtolower($class), $par['learn']);
288
-				if (($class != $par['type'])||($par['level']<99))
289
-					$return .= sprintf(file_get_contents('formLearnDSPAM.htm'),
317
+				if (($class != $par['type'])||($par['level']<99)) {
318
+									$return .= sprintf(file_get_contents('formLearnDSPAM.htm'),
290 319
 						$class,$class,$val["$class"],base64_encode(json_encode($par)),$class);
320
+				}
291 321
 			}
292 322
 		default:
293 323
 			return $return;
@@ -296,37 +326,41 @@  discard block
 block discarded – undo
296 326
 
297 327
 function printTableRow($row, $learn, $init=true) {
298 328
 	$color = 'inherit';
299
-	if ($init) 
300
-		$row=formatVal($row,$learn);
329
+	if ($init) {
330
+			$row=formatVal($row,$learn);
331
+	}
301 332
 	foreach( $row as $key => $val) {
302
-		if (is_array($val))
303
-			printTableRow($val, $learn, false);
304
-		else {
333
+		if (is_array($val)) {
334
+					printTableRow($val, $learn, false);
335
+		} else {
305 336
 			/* DSPAM format */
306
-			if (isset($row['type']))
307
-				switch($row['type']) {
337
+			if (isset($row['type'])) {
338
+							switch($row['type']) {
308 339
 					case 'Innocent':
309 340
 					case 'HAM':
310 341
 						$color = 'rgba(0,255,0, %.1f)';
342
+			}
311 343
 						break;
312 344
 					case 'Spam':
313 345
 					case 'SPAM':
314 346
 						$color = 'rgba(255,0,0,%.1f)';
315 347
 			}
316 348
 			/* DMARC, DKIM, SPF format */
317
-			if (isset($row['result']))
318
-				switch($row['result']) {
349
+			if (isset($row['result'])) {
350
+							switch($row['result']) {
319 351
 					case 'pass':
320 352
 						$color = 'rgba(0,255,0, %.1f)';
353
+			}
321 354
 						break;
322 355
 					case 'fail':
323 356
 						$color = 'rgba(255,0,0,%.1f)';
324 357
 				}
325 358
 			/* Spamassassin format */
326
-			if (isset($row['status']))
327
-	                        switch($row['status']) {
359
+			if (isset($row['status'])) {
360
+				                        switch($row['status']) {
328 361
 					case 'No':
329 362
 						$color = 'rgba(0,255,0, %.1f)';
363
+			}
330 364
 						break;
331 365
 					case 'Yes':
332 366
 						$color = 'rgba(255,0,0,%.1f)';
Please login to merge, or discard this patch.
contrib/mailClassifier/result.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-$path='/var/www/html/RBL/';
2
+$path = '/var/www/html/RBL/';
3 3
 include_once($path.'config.php');
4 4
 require_once($path.'function.php');
5 5
 
@@ -14,14 +14,14 @@  discard block
 block discarded – undo
14 14
 $tag .= $conf['syslog']['tag'];
15 15
 openlog($tag, LOG_PID, $fac);
16 16
 
17
-if ( $confimap['learn']=='dspamc' ) {
17
+if ($confimap['learn'] == 'dspamc') {
18 18
 	$cmd = escapeshellcmd('which dspamc');
19 19
 	$cmd = escapeshellcmd('which ls');
20
-	exec ( $cmd, $out, $ret );
20
+	exec($cmd, $out, $ret);
21 21
 	if ($ret != 0) {
22 22
 		$err = 'No DSPAM Client found on your system. Please, force your sysadmin to install "dspamc".';
23 23
 		syslog(LOG_ERR, $username.': Error: '.$err);
24
-		exit (sprintf('<p>%s</p>',htmlentities($err)));
24
+		exit (sprintf('<p>%s</p>', htmlentities($err)));
25 25
 	}
26 26
 }
27 27
 
@@ -60,10 +60,10 @@  discard block
 block discarded – undo
60 60
 $headers = imapFind($confimap, $account, $folder);
61 61
 if (empty($headers)) exit (sprintf('<p>No suitable mail found in <b>%s</b> folder.</p>', htmlentities("<$folder>")));
62 62
 print '<table>';
63
-printTableHeader($folder,$data,TRUE,sprintf('Found %d suitable mails.',count($headers)));
63
+printTableHeader($folder, $data, TRUE, sprintf('Found %d suitable mails.', count($headers)));
64 64
 
65
-foreach ( $headers AS $header ) {
66
-	$values = imapInfo($username, $header,$conf['host']['ar'],$confimap['dspamtospamass'],$confimap['learn']);
65
+foreach ($headers AS $header) {
66
+	$values = imapInfo($username, $header, $conf['host']['ar'], $confimap['dspamtospamass'], $confimap['learn']);
67 67
 	print '<tr>';
68 68
 	printTableRow($values, $confimap['learn']);
69 69
 	print '</tr>';
Please login to merge, or discard this patch.