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 1 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.