Passed
Push — patch_1-1-9 ( 70f5ab...f2626d )
by Spuds
21:21 queued 15:06
created
sources/ext/bad-behavior/badbehavior-plugin.php 1 patch
Braces   +57 added lines, -20 removed lines patch added patch discarded remove patch
@@ -92,27 +92,42 @@  discard block
 block discarded – undo
92 92
 	if (strpos($query, 'DATE_SUB') !== false)
93 93
 	{
94 94
 		if (!empty($modSettings['badbehavior_logging']))
95
-			$query = 'DELETE FROM {db_prefix}log_badbehavior WHERE date < ' . (bb2_db_date() - 7 * 86400);
96
-		else
97
-			return true;
95
+		{
96
+					$query = 'DELETE FROM {db_prefix}log_badbehavior WHERE date < ' . (bb2_db_date() - 7 * 86400);
97
+		}
98
+		else {
99
+					return true;
100
+		}
98 101
 	}
99 102
 
100 103
 	if (strpos($query, 'OPTIMIZE TABLE') !== false)
101
-		return true;
104
+	{
105
+			return true;
106
+	}
102 107
 	elseif (strpos($query, '@@session.wait_timeout') !== false)
103
-		return true;
108
+	{
109
+			return true;
110
+	}
104 111
 	elseif (empty($query))
105
-		return true;
112
+	{
113
+			return true;
114
+	}
106 115
 
107 116
 	// Run the query, return success, failure or the actual results
108 117
 	$result = $db->query('', $query, array());
109 118
 
110 119
 	if (!$result)
111
-		return false;
120
+	{
121
+			return false;
122
+	}
112 123
 	elseif ($result === true)
113
-		return (bb2_db_affected_rows() !== 0);
124
+	{
125
+			return (bb2_db_affected_rows() !== 0);
126
+	}
114 127
 	elseif (bb2_db_num_rows($result) === 0)
115
-		return false;
128
+	{
129
+			return false;
130
+	}
116 131
 
117 132
 	return bb2_db_rows($result);
118 133
 }
@@ -131,7 +146,9 @@  discard block
 block discarded – undo
131 146
 
132 147
 	$temp = array();
133 148
 	while ($row = $db->fetch_assoc($result))
134
-		$temp[] = $row;
149
+	{
150
+			$temp[] = $row;
151
+	}
135 152
 	$db->free_result($result);
136 153
 
137 154
 	return $temp;
@@ -164,7 +181,9 @@  discard block
 block discarded – undo
164 181
 
165 182
 	// Logging not enabled
166 183
 	if (!$settings['logging'])
167
-		return '';
184
+	{
185
+			return '';
186
+	}
168 187
 
169 188
 	// Clean the data that bb sent us
170 189
 	$ip = bb2_db_escape(substr($package['ip'], 0, 19));
@@ -204,11 +223,15 @@  discard block
 block discarded – undo
204 223
 		foreach ($package['request_entity'] as $h => $v)
205 224
 		{
206 225
 			if (is_array($v))
207
-				$v = bb2_multi_implode($v, ' | ', true);
226
+			{
227
+							$v = bb2_multi_implode($v, ' | ', true);
228
+			}
208 229
 
209 230
 			$v = trim($v);
210 231
 			if ($v !== '')
211
-				$request_entity .= bb2_db_escape("$h: $v\n");
232
+			{
233
+							$request_entity .= bb2_db_escape("$h: $v\n");
234
+			}
212 235
 		}
213 236
 
214 237
 		// Only such much space in this column, so brutally cut it
@@ -221,7 +244,9 @@  discard block
 block discarded – undo
221 244
 	{
222 245
 		$$id = trim($$id);
223 246
 		while (preg_match('~[\'\\\\]$~', substr($$id, -1)) === 1)
224
-			$$id = trim(substr($$id, 0, -1));
247
+		{
248
+					$$id = trim(substr($$id, 0, -1));
249
+		}
225 250
 
226 251
 		$$id = str_replace("'", '_', $$id);
227 252
 	}
@@ -247,16 +272,22 @@  discard block
 block discarded – undo
247 272
 function bb2_multi_implode($array, $glue = ',', $trim_all = false)
248 273
 {
249 274
 	if (!is_array($array))
250
-		$array = array($array);
275
+	{
276
+			$array = array($array);
277
+	}
251 278
 
252 279
 	foreach ($array as $key => $value)
253 280
 	{
254 281
 		if (is_array($value))
255
-			$array[$key] = bb2_multi_implode($value, $glue, $trim_all);
282
+		{
283
+					$array[$key] = bb2_multi_implode($value, $glue, $trim_all);
284
+		}
256 285
 	}
257 286
 
258 287
 	if ($trim_all)
259
-		$array = array_map('trim', $array);
288
+	{
289
+			$array = array_map('trim', $array);
290
+	}
260 291
 
261 292
 	return implode($glue, $array);
262 293
 }
@@ -285,7 +316,9 @@  discard block
 block discarded – undo
285 316
 
286 317
 	// Nothing in the whitelist
287 318
 	if (empty($whitelist['badbehavior_ip_wl']) && empty($whitelist['badbehavior_useragent_wl']) && empty($whitelist['badbehavior_url_wl']))
288
-		return false;
319
+	{
320
+			return false;
321
+	}
289 322
 
290 323
 	// Build up the whitelist array so badbehavior can use it
291 324
 	return array_merge(
@@ -309,7 +342,9 @@  discard block
 block discarded – undo
309 342
 
310 343
 	// Make sure that the proxy addresses are split into an array, and if it's empty - make sure reverse proxy is disabled
311 344
 	if (!empty($modSettings['badbehavior_reverse_proxy_addresses']))
312
-		$badbehavior_reverse_proxy_addresses = explode('|', trim($modSettings['badbehavior_reverse_proxy_addresses']));
345
+	{
346
+			$badbehavior_reverse_proxy_addresses = explode('|', trim($modSettings['badbehavior_reverse_proxy_addresses']));
347
+	}
313 348
 	else
314 349
 	{
315 350
 		$badbehavior_reverse_proxy_addresses = array();
@@ -377,7 +412,9 @@  discard block
 block discarded – undo
377 412
 		}
378 413
 
379 414
 		if ($bb2_blocked !== false)
380
-			return sprintf($txt['badbehavior_blocked'], $bb2_blocked[0]['COUNT(*)']);
415
+		{
416
+					return sprintf($txt['badbehavior_blocked'], $bb2_blocked[0]['COUNT(*)']);
417
+		}
381 418
 	}
382 419
 }
383 420
 
Please login to merge, or discard this patch.
sources/subs/Mail.subs.php 1 patch
Braces   +231 added lines, -88 removed lines patch added patch discarded remove patch
@@ -80,14 +80,18 @@  discard block
 block discarded – undo
80 80
 
81 81
 		// Call this function recursively for the hotmail addresses.
82 82
 		if (!empty($hotmail_to))
83
-			$mail_result = sendmail($hotmail_to, $subject, $message, $from, $message_type . $message_id, $send_html, $priority, true, $is_private, $from_wrapper, $reference);
83
+		{
84
+					$mail_result = sendmail($hotmail_to, $subject, $message, $from, $message_type . $message_id, $send_html, $priority, true, $is_private, $from_wrapper, $reference);
85
+		}
84 86
 
85 87
 		// The remaining addresses no longer need the fix.
86 88
 		$hotmail_fix = false;
87 89
 
88 90
 		// No other addresses left? Return instantly.
89 91
 		if (empty($to_array))
90
-			return $mail_result;
92
+		{
93
+					return $mail_result;
94
+		}
91 95
 	}
92 96
 
93 97
 	// Get rid of entities.
@@ -111,22 +115,29 @@  discard block
 block discarded – undo
111 115
 		// Be sure there is never an email in the from name if using maillist styles
112 116
 		$dmarc_from = $from;
113 117
 		if (filter_var($dmarc_from, FILTER_VALIDATE_EMAIL))
114
-			$dmarc_from = str_replace(strstr($dmarc_from, '@'), '', $dmarc_from);
118
+		{
119
+					$dmarc_from = str_replace(strstr($dmarc_from, '@'), '', $dmarc_from);
120
+		}
115 121
 
116 122
 		// Add in the 'via' if desired, helps prevent email clients from learning/replacing legit names/emails
117 123
 		if (!empty($modSettings['maillist_sitename']) && empty($modSettings['dmarc_spec_standard']))
118
-			// @memo (2014) "via" is still a draft, and it's not yet clear if it will be localized or not.
124
+		{
125
+					// @memo (2014) "via" is still a draft, and it's not yet clear if it will be localized or not.
119 126
 			// To play safe, we are keeping it hard-coded, but the string is available for translation.
120 127
 			$from = $dmarc_from . ' ' . /* $txt['via'] */ 'via' . ' ' . $modSettings['maillist_sitename'];
121
-		else
122
-			$from = $dmarc_from;
128
+		}
129
+		else {
130
+					$from = $dmarc_from;
131
+		}
123 132
 	}
124 133
 
125 134
 	// Take care of from / subject encodings
126 135
 	list (, $from_name, $from_encoding) = mimespecialchars(addcslashes($from !== null ? $from : (!empty($modSettings['maillist_sitename']) ? $modSettings['maillist_sitename'] : $context['forum_name']), '<>()\'\\"'), true, $hotmail_fix, $line_break);
127 136
 	list (, $subject) = mimespecialchars($subject, true, $hotmail_fix, $line_break);
128 137
 	if ($from_encoding !== 'base64')
129
-		$from_name = '"' . $from_name . '"';
138
+	{
139
+			$from_name = '"' . $from_name . '"';
140
+	}
130 141
 
131 142
 	// Construct the from / replyTo mail headers, based on if we showing a users name
132 143
 	if ($from_wrapper !== null)
@@ -136,7 +147,9 @@  discard block
 block discarded – undo
136 147
 		// If they reply where is it going to be sent?
137 148
 		$headers .= 'Reply-To: "' . (!empty($modSettings['maillist_sitename']) ? $modSettings['maillist_sitename'] : $context['forum_name']) . '" <' . (!empty($modSettings['maillist_sitename_address']) ? $modSettings['maillist_sitename_address'] : (empty($modSettings['maillist_mail_from']) ? $webmaster_email : $modSettings['maillist_mail_from'])) . '>' . $line_break;
138 149
 		if ($reference !== null)
139
-			$headers .= 'References: <' . $reference . strstr(empty($modSettings['maillist_mail_from']) ? $webmaster_email : $modSettings['maillist_mail_from'], '@') . '>' . $line_break;
150
+		{
151
+					$headers .= 'References: <' . $reference . strstr(empty($modSettings['maillist_mail_from']) ? $webmaster_email : $modSettings['maillist_mail_from'], '@') . '>' . $line_break;
152
+		}
140 153
 	}
141 154
 	else
142 155
 	{
@@ -150,7 +163,9 @@  discard block
 block discarded – undo
150 163
 
151 164
 	// Return path, date, mailer
152 165
 	if ($use_sendmail)
153
-		$headers .= 'Return-Path: <' . $return_path . '>' . $line_break;
166
+	{
167
+			$headers .= 'Return-Path: <' . $return_path . '>' . $line_break;
168
+	}
154 169
 	$headers .= 'Date: ' . gmdate('D, d M Y H:i:s') . ' -0000' . $line_break;
155 170
 	$headers .= 'X-Mailer: ELK' . $line_break;
156 171
 
@@ -170,7 +185,9 @@  discard block
 block discarded – undo
170 185
 
171 186
 	// Pass this to the integration before we start modifying the output -- it'll make it easier later.
172 187
 	if (in_array(false, call_integration_hook('integrate_outgoing_email', array(&$subject, &$message, &$headers)), true))
173
-		return false;
188
+	{
189
+			return false;
190
+	}
174 191
 
175 192
 	// Save the original message...
176 193
 	$orig_message = $message;
@@ -223,15 +240,20 @@  discard block
 block discarded – undo
223 240
 
224 241
 	// Are we using the mail queue, if so this is where we butt in...
225 242
 	if (!empty($modSettings['mail_queue']) && $priority != 0)
226
-		return AddMailQueue(false, $to_array, $subject, $message, $headers, $send_html, $priority, $is_private, $message_type . $message_id);
243
+	{
244
+			return AddMailQueue(false, $to_array, $subject, $message, $headers, $send_html, $priority, $is_private, $message_type . $message_id);
245
+	}
227 246
 	// If it's a priority mail, send it now - note though that this should NOT be used for sending many at once.
228 247
 	elseif (!empty($modSettings['mail_queue']) && !empty($modSettings['mail_period_limit']))
229 248
 	{
230 249
 		list ($last_mail_time, $mails_this_minute) = @explode('|', $modSettings['mail_recent']);
231 250
 		if (empty($mails_this_minute) || time() > (int) $last_mail_time + 60)
232
-			$new_queue_stat = time() . '|' . 1;
233
-		else
234
-			$new_queue_stat = $last_mail_time . '|' . ((int) $mails_this_minute + 1);
251
+		{
252
+					$new_queue_stat = time() . '|' . 1;
253
+		}
254
+		else {
255
+					$new_queue_stat = $last_mail_time . '|' . ((int) $mails_this_minute + 1);
256
+		}
235 257
 
236 258
 		updateSettings(array('mail_recent' => $new_queue_stat));
237 259
 	}
@@ -265,7 +287,9 @@  discard block
 block discarded – undo
265 287
 				$message = mail_insert_key($message, $unq_head, $line_break);
266 288
 			}
267 289
 			elseif (empty($modSettings['mail_no_message_id']))
268
-				$unq_id = ($need_break ? $line_break : '') . 'Message-ID: <' . md5($boardurl . microtime()) . '-' . $message_id . strstr(empty($modSettings['maillist_mail_from']) ? $webmaster_email : $modSettings['maillist_mail_from'], '@') . '>';
290
+			{
291
+							$unq_id = ($need_break ? $line_break : '') . 'Message-ID: <' . md5($boardurl . microtime()) . '-' . $message_id . strstr(empty($modSettings['maillist_mail_from']) ? $webmaster_email : $modSettings['maillist_mail_from'], '@') . '>';
292
+			}
269 293
 
270 294
 			// This is frequently not set, or not set according to the needs of PBE and bounce detection
271 295
 			// We have to use ini_set, since "-f <address>" doesn't work on windows systems, so we need both
@@ -287,7 +311,9 @@  discard block
 block discarded – undo
287 311
 
288 312
 				// Track total emails sent
289 313
 				if (!empty($modSettings['trackStats']))
290
-					trackStats(array('email' => '+'));
314
+				{
315
+									trackStats(array('email' => '+'));
316
+				}
291 317
 			}
292 318
 
293 319
 			// Put it back
@@ -304,9 +330,10 @@  discard block
 block discarded – undo
304 330
 			log_email($sent);
305 331
 		}
306 332
 	}
307
-	else
308
-		// SMTP protocol it is
333
+	else {
334
+			// SMTP protocol it is
309 335
 		$mail_result = $mail_result && smtp_mail($to_array, $subject, $message, $headers, $priority, $message_type . $message_id);
336
+	}
310 337
 
311 338
 	// Clear out the stat cache.
312 339
 	trackStats();
@@ -340,7 +367,9 @@  discard block
 block discarded – undo
340 367
 	static $cur_insert_len = 0;
341 368
 
342 369
 	if ($cur_insert_len == 0)
343
-		$cur_insert = array();
370
+	{
371
+			$cur_insert = array();
372
+	}
344 373
 
345 374
 	// If we're flushing, make the final inserts - also if we're near the MySQL length limit!
346 375
 	if (($flush || $cur_insert_len > 800000) && !empty($cur_insert))
@@ -417,7 +446,9 @@  discard block
 block discarded – undo
417 446
 
418 447
 	// If they are using SSI there is a good chance obExit will never be called.  So lets be nice and flush it for them.
419 448
 	if (ELK === 'SSI')
420
-		return AddMailQueue(true);
449
+	{
450
+			return AddMailQueue(true);
451
+	}
421 452
 
422 453
 	return true;
423 454
 }
@@ -451,12 +482,16 @@  discard block
 block discarded – undo
451 482
 		$simple = true;
452 483
 
453 484
 		foreach ($matches[1] as $entity)
454
-			if ($entity > 128)
485
+		{
486
+					if ($entity > 128)
455 487
 				$simple = false;
488
+		}
456 489
 		unset($matches);
457 490
 
458 491
 		if ($simple)
459
-			$string = preg_replace_callback('~&#(\d{3,7});~', 'mimespecialchars_callback', $string);
492
+		{
493
+					$string = preg_replace_callback('~&#(\d{3,7});~', 'mimespecialchars_callback', $string);
494
+		}
460 495
 		else
461 496
 		{
462 497
 			$string = preg_replace_callback('~&#(\d{3,7});~', 'fixchar__callback', $string);
@@ -484,17 +519,21 @@  discard block
 block discarded – undo
484 519
 
485 520
 		// Show the characterset and the transfer-encoding for header strings.
486 521
 		if ($with_charset)
487
-			$string = '=?' . $charset . '?B?' . $string . '?=';
522
+		{
523
+					$string = '=?' . $charset . '?B?' . $string . '?=';
524
+		}
488 525
 
489 526
 		// Break it up in lines (mail body).
490
-		else
491
-			$string = chunk_split($string, 76, $line_break);
527
+		else {
528
+					$string = chunk_split($string, 76, $line_break);
529
+		}
492 530
 
493 531
 		return array($charset, $string, 'base64');
494 532
 	}
495
-	else
496
-		return array($charset, $string, '7bit');
497
-}
533
+	else {
534
+			return array($charset, $string, '7bit');
535
+	}
536
+	}
498 537
 
499 538
 /**
500 539
  * Converts out of ascii range characters in to HTML entities
@@ -512,16 +551,25 @@  discard block
 block discarded – undo
512 551
 	$c_ord = ord($c[0]);
513 552
 
514 553
 	if ($c_strlen === 1 && $c_ord <= 0x7F)
515
-		return $c;
554
+	{
555
+			return $c;
556
+	}
516 557
 	elseif ($c_strlen === 2 && $c_ord >= 0xC0 && $c_ord <= 0xDF)
517
-		return '&#' . ((($c_ord ^ 0xC0) << 6) + (ord($c[1]) ^ 0x80)) . ';';
558
+	{
559
+			return '&#' . ((($c_ord ^ 0xC0) << 6) + (ord($c[1]) ^ 0x80)) . ';';
560
+	}
518 561
 	elseif ($c_strlen === 3 && $c_ord >= 0xE0 && $c_ord <= 0xEF)
519
-		return '&#' . ((($c_ord ^ 0xE0) << 12) + ((ord($c[1]) ^ 0x80) << 6) + (ord($c[2]) ^ 0x80)) . ';';
562
+	{
563
+			return '&#' . ((($c_ord ^ 0xE0) << 12) + ((ord($c[1]) ^ 0x80) << 6) + (ord($c[2]) ^ 0x80)) . ';';
564
+	}
520 565
 	elseif ($c_strlen === 4 && $c_ord >= 0xF0 && $c_ord <= 0xF7)
521
-		return '&#' . ((($c_ord ^ 0xF0) << 18) + ((ord($c[1]) ^ 0x80) << 12) + ((ord($c[2]) ^ 0x80) << 6) + (ord($c[3]) ^ 0x80)) . ';';
522
-	else
523
-		return '';
524
-}
566
+	{
567
+			return '&#' . ((($c_ord ^ 0xF0) << 18) + ((ord($c[1]) ^ 0x80) << 12) + ((ord($c[2]) ^ 0x80) << 6) + (ord($c[3]) ^ 0x80)) . ';';
568
+	}
569
+	else {
570
+			return '';
571
+	}
572
+	}
525 573
 
526 574
 /**
527 575
  * Callback for the preg_replace in mimespecialchars
@@ -571,7 +619,9 @@  discard block
 block discarded – undo
571 619
 	{
572 620
 		$socket = fsockopen($modSettings['smtp_host'], 110, $errno, $errstr, 2);
573 621
 		if (!$socket && (substr($modSettings['smtp_host'], 0, 5) == 'smtp.' || substr($modSettings['smtp_host'], 0, 11) == 'ssl://smtp.'))
574
-			$socket = fsockopen(strtr($modSettings['smtp_host'], array('smtp.' => 'pop.')), 110, $errno, $errstr, 2);
622
+		{
623
+					$socket = fsockopen(strtr($modSettings['smtp_host'], array('smtp.' => 'pop.')), 110, $errno, $errstr, 2);
624
+		}
575 625
 
576 626
 		if ($socket)
577 627
 		{
@@ -593,7 +643,9 @@  discard block
 block discarded – undo
593 643
 		if (substr($modSettings['smtp_host'], 0, 4) == 'ssl:' && (empty($modSettings['smtp_port']) || $modSettings['smtp_port'] == 25))
594 644
 		{
595 645
 			if ($socket = @fsockopen($modSettings['smtp_host'], 465, $errno, $errstr, 3))
596
-				Errors::instance()->log_error($txt['smtp_port_ssl']);
646
+			{
647
+							Errors::instance()->log_error($txt['smtp_port_ssl']);
648
+			}
597 649
 		}
598 650
 
599 651
 		// Unable to connect!  Don't show any error message, but just log one and try to continue anyway.
@@ -606,7 +658,9 @@  discard block
 block discarded – undo
606 658
 
607 659
 	// Wait for a response of 220, without "-" continue.
608 660
 	if (!server_parse(null, $socket, '220'))
609
-		return false;
661
+	{
662
+			return false;
663
+	}
610 664
 
611 665
 	// This should be set in the ACP
612 666
 	if (empty($modSettings['smtp_client']))
@@ -628,22 +682,32 @@  discard block
 block discarded – undo
628 682
 			}
629 683
 
630 684
 			if (!server_parse('AUTH LOGIN', $socket, '334'))
631
-				return false;
685
+			{
686
+							return false;
687
+			}
632 688
 			// Send the username and password, encoded.
633 689
 			if (!server_parse(base64_encode($modSettings['smtp_username']), $socket, '334'))
634
-				return false;
690
+			{
691
+							return false;
692
+			}
635 693
 			// The password is already encoded ;)
636 694
 			if (!server_parse($modSettings['smtp_password'], $socket, '235'))
637
-				return false;
695
+			{
696
+							return false;
697
+			}
638 698
 		}
639 699
 		elseif (!server_parse('HELO ' . $modSettings['smtp_client'], $socket, '250'))
640
-			return false;
700
+		{
701
+					return false;
702
+		}
641 703
 	}
642 704
 	else
643 705
 	{
644 706
 		// Just say "helo".
645 707
 		if (!server_parse('HELO ' . $modSettings['smtp_client'], $socket, '250'))
646
-			return false;
708
+		{
709
+					return false;
710
+		}
647 711
 	}
648 712
 
649 713
 	// Fix the message for any lines beginning with a period! (the first is ignored, you see.)
@@ -683,30 +747,44 @@  discard block
 block discarded – undo
683 747
 		if ($i != 0)
684 748
 		{
685 749
 			if (!server_parse('RSET', $socket, '250'))
686
-				return false;
750
+			{
751
+							return false;
752
+			}
687 753
 		}
688 754
 
689 755
 		// From, to, and then start the data...
690 756
 		if (!server_parse('MAIL FROM: <' . $return_path . '>', $socket, '250'))
691
-			return false;
757
+		{
758
+					return false;
759
+		}
692 760
 		if (!server_parse('RCPT TO: <' . $mail_to . '>', $socket, '250'))
693
-			return false;
761
+		{
762
+					return false;
763
+		}
694 764
 		if (!server_parse('DATA', $socket, '354'))
695
-			return false;
765
+		{
766
+					return false;
767
+		}
696 768
 
697 769
 		fputs($socket, 'Subject: ' . $subject . $line_break);
698 770
 		if (strlen($mail_to) > 0)
699
-			fputs($socket, 'To: <' . $mail_to . '>' . $line_break);
771
+		{
772
+					fputs($socket, 'To: <' . $mail_to . '>' . $line_break);
773
+		}
700 774
 		fputs($socket, $headers . $line_break . $line_break);
701 775
 		fputs($socket, $message . $line_break);
702 776
 
703 777
 		// Send a ., or in other words "end of data".
704 778
 		if (!server_parse('.', $socket, '250'))
705
-			return false;
779
+		{
780
+					return false;
781
+		}
706 782
 
707 783
 		// track the number of emails sent
708 784
 		if (!empty($modSettings['trackStats']))
709
-			trackStats(array('email' => '+'));
785
+		{
786
+					trackStats(array('email' => '+'));
787
+		}
710 788
 
711 789
 		// Keep our post via email log
712 790
 		if (!empty($unq_head))
@@ -751,21 +829,27 @@  discard block
 block discarded – undo
751 829
 	global $txt;
752 830
 
753 831
 	if ($message !== null)
754
-		fputs($socket, $message . "\r\n");
832
+	{
833
+			fputs($socket, $message . "\r\n");
834
+	}
755 835
 
756 836
 	// No response yet.
757 837
 	$server_response = '';
758 838
 
759 839
 	while (substr($server_response, 3, 1) != ' ')
760
-		if (!($server_response = fgets($socket, 256)))
840
+	{
841
+			if (!($server_response = fgets($socket, 256)))
761 842
 		{
762 843
 			// @todo Change this message to reflect that it may mean bad user/password/server issues/etc.
763 844
 			Errors::instance()->log_error($txt['smtp_bad_response']);
845
+	}
764 846
 			return false;
765 847
 		}
766 848
 
767 849
 	if ($response === null)
768
-		return substr($server_response, 0, 3);
850
+	{
851
+			return substr($server_response, 0, 3);
852
+	}
769 853
 
770 854
 	if (substr($server_response, 0, 3) != $response)
771 855
 	{
@@ -833,17 +917,23 @@  discard block
 block discarded – undo
833 917
 	{
834 918
 		loadLanguage('EmailTemplates', $lang);
835 919
 		if (!empty($modSettings['maillist_enabled']))
836
-			loadLanguage('MaillistTemplates', $lang);
920
+		{
921
+					loadLanguage('MaillistTemplates', $lang);
922
+		}
837 923
 
838 924
 		if (!empty($additional_files))
839 925
 		{
840 926
 			foreach ($additional_files as $file)
841
-				loadLanguage($file, $lang);
927
+			{
928
+							loadLanguage($file, $lang);
929
+			}
842 930
 		}
843 931
 	}
844 932
 
845 933
 	if (!isset($txt[$template . '_subject']) || !isset($txt[$template . '_body']))
846
-		throw new Elk_Exception('email_no_template', 'template', array($template));
934
+	{
935
+			throw new Elk_Exception('email_no_template', 'template', array($template));
936
+	}
847 937
 
848 938
 	$ret = array(
849 939
 		'subject' => $txt[$template . '_subject'],
@@ -852,7 +942,9 @@  discard block
 block discarded – undo
852 942
 	if (!empty($suffixes))
853 943
 	{
854 944
 		foreach ($suffixes as $key)
855
-			$ret[$key] = $txt[$template . '_' . $key];
945
+		{
946
+					$ret[$key] = $txt[$template . '_' . $key];
947
+		}
856 948
 	}
857 949
 
858 950
 	// Add in the default replacements.
@@ -932,9 +1024,13 @@  discard block
 block discarded – undo
932 1024
 		$context[$key] = !empty($_REQUEST[$post]) ? $_REQUEST[$post] : '';
933 1025
 
934 1026
 		if (empty($context[$key]) && empty($_REQUEST['xml']))
935
-			$context['post_error']['messages'][] = $txt['error_no_' . $post];
1027
+		{
1028
+					$context['post_error']['messages'][] = $txt['error_no_' . $post];
1029
+		}
936 1030
 		elseif (!empty($_REQUEST['xml']))
937
-			continue;
1031
+		{
1032
+					continue;
1033
+		}
938 1034
 
939 1035
 		preparsecode($context[$key]);
940 1036
 
@@ -972,7 +1068,9 @@  discard block
 block discarded – undo
972 1068
 	global $user_info;
973 1069
 
974 1070
 	if (empty($matches[1]))
975
-		return '';
1071
+	{
1072
+			return '';
1073
+	}
976 1074
 
977 1075
 	$use_ref = true;
978 1076
 	$ref = &$user_info;
@@ -980,7 +1078,9 @@  discard block
 block discarded – undo
980 1078
 	foreach (explode('.', $matches[1]) as $index)
981 1079
 	{
982 1080
 		if ($use_ref && isset($ref[$index]))
983
-			$ref = &$ref[$index];
1081
+		{
1082
+					$ref = &$ref[$index];
1083
+		}
984 1084
 		else
985 1085
 		{
986 1086
 			$use_ref = false;
@@ -1021,7 +1121,9 @@  discard block
 block discarded – undo
1021 1121
 		{
1022 1122
 			// Private PM/email subjects and similar shouldn't be shown in the mailbox area.
1023 1123
 			if (!empty($row['private']))
1024
-				$row['subject'] = $txt['personal_message'];
1124
+			{
1125
+							$row['subject'] = $txt['personal_message'];
1126
+			}
1025 1127
 
1026 1128
 			return $row;
1027 1129
 		}
@@ -1118,7 +1220,8 @@  discard block
 block discarded – undo
1118 1220
 
1119 1221
 	// If we have failed to many times, tell mail to wait a bit and try again.
1120 1222
 	if ($modSettings['mail_failed_attempts'] > 5)
1121
-		$db->query('', '
1223
+	{
1224
+			$db->query('', '
1122 1225
 			UPDATE {db_prefix}settings
1123 1226
 			SET value = {string:next_mail_send}
1124 1227
 			WHERE variable = {string:mail_next_send}
@@ -1129,6 +1232,7 @@  discard block
 block discarded – undo
1129 1232
 				'last_send' => $modSettings['mail_next_send'],
1130 1233
 			)
1131 1234
 		);
1235
+	}
1132 1236
 
1133 1237
 	// Add our email back to the queue, manually.
1134 1238
 	$db->insert('insert',
@@ -1215,7 +1319,9 @@  discard block
 block discarded – undo
1215 1319
 		)
1216 1320
 	);
1217 1321
 	if ($db->affected_rows() == 0)
1218
-		return false;
1322
+	{
1323
+			return false;
1324
+	}
1219 1325
 
1220 1326
 	return $delay;
1221 1327
 }
@@ -1280,17 +1386,23 @@  discard block
 block discarded – undo
1280 1386
 
1281 1387
 	// Do we have another script to send out the queue?
1282 1388
 	if (!empty($modSettings['mail_queue_use_cron']) && empty($force_send))
1283
-		return false;
1389
+	{
1390
+			return false;
1391
+	}
1284 1392
 
1285 1393
 	// How many emails can we send each time we are called in a period
1286 1394
 	if (!$batch_size)
1287 1395
 	{
1288 1396
 		// Batch size has been set in the ACP, use it
1289 1397
 		if (!empty($modSettings['mail_batch_size']))
1290
-			$batch_size = $modSettings['mail_batch_size'];
1398
+		{
1399
+					$batch_size = $modSettings['mail_batch_size'];
1400
+		}
1291 1401
 		// No per period setting or batch size, set to send 5 every 5 seconds, or 60 per minute
1292 1402
 		elseif (empty($modSettings['mail_period_limit']))
1293
-			$batch_size = 5;
1403
+		{
1404
+					$batch_size = 5;
1405
+		}
1294 1406
 		// A per period limit but no defined batch size, set a batch size
1295 1407
 		else
1296 1408
 		{
@@ -1303,7 +1415,9 @@  discard block
 block discarded – undo
1303 1415
 
1304 1416
 	// If we came with a timestamp, and that doesn't match the next event, then someone else has beaten us.
1305 1417
 	if (isset($_GET['ts']) && $_GET['ts'] != $modSettings['mail_next_send'] && empty($force_send))
1306
-		return false;
1418
+	{
1419
+			return false;
1420
+	}
1307 1421
 
1308 1422
 	// Prepare to send each email, and log that for future proof.
1309 1423
 	require_once(SUBSDIR . '/Maillist.subs.php');
@@ -1315,7 +1429,9 @@  discard block
 block discarded – undo
1315 1429
 		// Update next send time for our mail queue, if there was something to update. Otherwise bail out :P
1316 1430
 		$delay = updateNextSendTime();
1317 1431
 		if ($delay === false)
1318
-			return false;
1432
+		{
1433
+					return false;
1434
+		}
1319 1435
 
1320 1436
 		$modSettings['mail_next_send'] = time() + $delay;
1321 1437
 	}
@@ -1337,16 +1453,21 @@  discard block
 block discarded – undo
1337 1453
 		{
1338 1454
 			// If this is likely one of the last cycles for this period, then send any remaining quota
1339 1455
 			if (($mail_time - (time() - 60)) < $delay * 2)
1340
-				$batch_size = $modSettings['mail_period_limit'] - $mail_number;
1456
+			{
1457
+							$batch_size = $modSettings['mail_period_limit'] - $mail_number;
1458
+			}
1341 1459
 			// Some batch sizes may need to be adjusted to fit as we approach the end
1342 1460
 			elseif ($mail_number + $batch_size > $modSettings['mail_period_limit'])
1343
-				$batch_size = $modSettings['mail_period_limit'] - $mail_number;
1461
+			{
1462
+							$batch_size = $modSettings['mail_period_limit'] - $mail_number;
1463
+			}
1344 1464
 
1345 1465
 			$mail_number += $batch_size;
1346 1466
 		}
1347 1467
 		// No more I'm afraid, return!
1348
-		else
1349
-			return false;
1468
+		else {
1469
+					return false;
1470
+		}
1350 1471
 
1351 1472
 		// Reflect that we're about to send some, do it now to be safe.
1352 1473
 		updateSettings(array('mail_recent' => $mail_time . '|' . $mail_number));
@@ -1357,14 +1478,20 @@  discard block
 block discarded – undo
1357 1478
 
1358 1479
 	// Delete, delete, delete!!!
1359 1480
 	if (!empty($ids))
1360
-		deleteMailQueueItems($ids);
1481
+	{
1482
+			deleteMailQueueItems($ids);
1483
+	}
1361 1484
 
1362 1485
 	// Don't believe we have any left after this batch?
1363 1486
 	if (count($ids) < $batch_size)
1364
-		resetNextSendTime();
1487
+	{
1488
+			resetNextSendTime();
1489
+	}
1365 1490
 
1366 1491
 	if (empty($ids))
1367
-		return false;
1492
+	{
1493
+			return false;
1494
+	}
1368 1495
 
1369 1496
 	// We have some to send, lets send them!
1370 1497
 	$sent = array();
@@ -1420,28 +1547,37 @@  discard block
 block discarded – undo
1420 1547
 				$email['body'] = mail_insert_key($email['body'], $unq_head, $line_break);
1421 1548
 			}
1422 1549
 			elseif ($email['message_id'] !== null && empty($modSettings['mail_no_message_id']))
1423
-				$unq_id = ($need_break ? $line_break : '') . 'Message-ID: <' . md5($scripturl . microtime()) . '-' . $email['message_id'] . strstr(empty($modSettings['maillist_mail_from']) ? $webmaster_email : $modSettings['maillist_mail_from'], '@') . '>';
1550
+			{
1551
+							$unq_id = ($need_break ? $line_break : '') . 'Message-ID: <' . md5($scripturl . microtime()) . '-' . $email['message_id'] . strstr(empty($modSettings['maillist_mail_from']) ? $webmaster_email : $modSettings['maillist_mail_from'], '@') . '>';
1552
+			}
1424 1553
 
1425 1554
 			// No point logging a specific error here, as we have no language. PHP error is helpful anyway...
1426 1555
 			$result = mail(strtr($email['to'], array("\r" => '', "\n" => '')), $email['subject'], $email['body'], $email['headers'] . $unq_id);
1427 1556
 
1428 1557
 			// If it sent, keep a record so we can save it in our allowed to reply log
1429 1558
 			if (!empty($unq_head) && $result)
1430
-				$sent[] = array_merge($unq_head_array, array(time(),$email['to']));
1559
+			{
1560
+							$sent[] = array_merge($unq_head_array, array(time(),$email['to']));
1561
+			}
1431 1562
 
1432 1563
 			// Track total emails sent
1433 1564
 			if ($result && !empty($modSettings['trackStats']))
1434
-				trackStats(array('email' => '+'));
1565
+			{
1566
+							trackStats(array('email' => '+'));
1567
+			}
1435 1568
 
1436 1569
 			// Try to stop a timeout, this would be bad...
1437 1570
 			detectServer()->setTimeLimit(300);
1438 1571
 		}
1439
-		else
1440
-			$result = smtp_mail(array($email['to']), $email['subject'], $email['body'], $email['headers'], $email['priority'], $email['message_type'] . $email['message_id']);
1572
+		else {
1573
+					$result = smtp_mail(array($email['to']), $email['subject'], $email['body'], $email['headers'], $email['priority'], $email['message_type'] . $email['message_id']);
1574
+		}
1441 1575
 
1442 1576
 		// Hopefully it sent?
1443 1577
 		if (!$result)
1444
-			$failed_emails[] = array(time(), $email['to'], $email['body_fail'], $email['subject'], $email['headers'], $email['send_html'], $email['priority'], $email['private'], $email['message_id']);
1578
+		{
1579
+					$failed_emails[] = array(time(), $email['to'], $email['body_fail'], $email['subject'], $email['headers'], $email['send_html'], $email['priority'], $email['private'], $email['message_id']);
1580
+		}
1445 1581
 	}
1446 1582
 
1447 1583
 	// Clear out the stat cache.
@@ -1449,7 +1585,9 @@  discard block
 block discarded – undo
1449 1585
 
1450 1586
 	// Log each of the sent emails.
1451 1587
 	if (!empty($sent))
1452
-		log_email($sent);
1588
+	{
1589
+			log_email($sent);
1590
+	}
1453 1591
 
1454 1592
 	// Any emails that didn't send?
1455 1593
 	if (!empty($failed_emails))
@@ -1460,7 +1598,9 @@  discard block
 block discarded – undo
1460 1598
 	}
1461 1599
 	// We were able to send the email, clear our failed attempts.
1462 1600
 	elseif (!empty($modSettings['mail_failed_attempts']))
1463
-		updateSuccessQueue();
1601
+	{
1602
+			updateSuccessQueue();
1603
+	}
1464 1604
 
1465 1605
 	// Had something to send...
1466 1606
 	return true;
@@ -1511,7 +1651,9 @@  discard block
 block discarded – undo
1511 1651
 	global $txt;
1512 1652
 
1513 1653
 	if ($time_diff < 0)
1514
-		$time_diff = 0;
1654
+	{
1655
+			$time_diff = 0;
1656
+	}
1515 1657
 
1516 1658
 	// Just do a bit of an if fest...
1517 1659
 	if ($time_diff > 86400)
@@ -1532,6 +1674,7 @@  discard block
 block discarded – undo
1532 1674
 		return sprintf($minutes == 1 ? $txt['mq_minute'] : $txt['mq_minutes'], $minutes);
1533 1675
 	}
1534 1676
 	// Otherwise must be second
1535
-	else
1536
-		return sprintf($time_diff == 1 ? $txt['mq_second'] : $txt['mq_seconds'], $time_diff);
1537
-}
1677
+	else {
1678
+			return sprintf($time_diff == 1 ? $txt['mq_second'] : $txt['mq_seconds'], $time_diff);
1679
+	}
1680
+	}
Please login to merge, or discard this patch.