Passed
Branch master (dcf803)
by zyt
02:12
created
smtp-validate-email.php 1 patch
Spacing   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -201,8 +201,8 @@  discard block
 block discarded – undo
201 201
         if (!$this->catchall_test) {
202 202
             return false;
203 203
         }
204
-        $test = 'catch-all-test-' . time();
205
-        $accepted = $this->rcpt($test . '@' . $domain);
204
+        $test = 'catch-all-test-'.time();
205
+        $accepted = $this->rcpt($test.'@'.$domain);
206 206
         if ($accepted) {
207 207
             // success on a non-existing address is a "catch-all"
208 208
             $this->domains_info[$domain]['catchall'] = true;
@@ -212,7 +212,7 @@  discard block
 block discarded – undo
212 212
         // while trying to perform a catchall detect
213 213
         $this->noop();
214 214
         if (!($this->connected())) {
215
-            $this->debug('Disconnected after trying a non-existing recipient on ' . $domain);
215
+            $this->debug('Disconnected after trying a non-existing recipient on '.$domain);
216 216
         }
217 217
         // nb: disconnects are considered as a non-catch-all case this way
218 218
         // this might not be true always
@@ -257,7 +257,7 @@  discard block
 block discarded – undo
257 257
             // add the hostname itself with 0 weight (RFC 2821)
258 258
             $mxs[$domain] = 0;
259 259
 
260
-            $this->debug('MX records (' . $domain . '): ' . print_r($mxs, true));
260
+            $this->debug('MX records ('.$domain.'): '.print_r($mxs, true));
261 261
             $this->domains_info[$domain] = array();
262 262
             $this->domains_info[$domain]['users'] = $users;
263 263
             $this->domains_info[$domain]['mxs'] = $mxs;
@@ -272,8 +272,8 @@  discard block
 block discarded – undo
272 272
                     }
273 273
                 } catch (SMTP_Validate_Email_Exception_No_Connection $e) {
274 274
                     // unable to connect to host, so these addresses are invalid?
275
-                    $this->debug('Unable to connect. Exception caught: ' . $e->getMessage());
276
-                    $this->set_domain_results($users, $domain, $this->no_conn_is_valid );
275
+                    $this->debug('Unable to connect. Exception caught: '.$e->getMessage());
276
+                    $this->set_domain_results($users, $domain, $this->no_conn_is_valid);
277 277
                 }
278 278
             }
279 279
 
@@ -284,7 +284,7 @@  discard block
 block discarded – undo
284 284
                     if ($this->helo()) {
285 285
 
286 286
                         // try issuing MAIL FROM
287
-                        if (!($this->mail($this->from_user . '@' . $this->from_domain))) {
287
+                        if (!($this->mail($this->from_user.'@'.$this->from_domain))) {
288 288
                             // MAIL FROM not accepted, we can't talk
289 289
                             $this->set_domain_results($users, $domain, $this->no_comm_is_valid);
290 290
                         }
@@ -316,7 +316,7 @@  discard block
 block discarded – undo
316 316
                                 $this->noop();
317 317
                                 // rcpt to for each user
318 318
                                 foreach ($users as $user) {
319
-                                    $address = $user . '@' . $domain;
319
+                                    $address = $user.'@'.$domain;
320 320
                                     $this->results[$address] = $this->rcpt($address);
321 321
                                     $this->noop();
322 322
                                 }
@@ -378,7 +378,7 @@  discard block
 block discarded – undo
378 378
             $users = (array) $users;
379 379
         }
380 380
         foreach ($users as $user) {
381
-            $this->results[$user . '@' . $domain] = $val;
381
+            $this->results[$user.'@'.$domain] = $val;
382 382
         }
383 383
     }
384 384
 
@@ -398,12 +398,12 @@  discard block
 block discarded – undo
398 398
     * @throws SMTP_Validate_Email_Exception_No_Timeout
399 399
     */
400 400
     protected function connect($host) {
401
-        $remote_socket = $host . ':' . $this->connect_port;
401
+        $remote_socket = $host.':'.$this->connect_port;
402 402
         $errnum = 0;
403 403
         $errstr = '';
404 404
         $this->host = $remote_socket;
405 405
         // open connection
406
-        $this->debug('Connecting to ' . $this->host);
406
+        $this->debug('Connecting to '.$this->host);
407 407
         $this->socket = @stream_socket_client(
408 408
             $this->host,
409 409
             $errnum,
@@ -414,15 +414,15 @@  discard block
 block discarded – undo
414 414
         );
415 415
         // connected?
416 416
         if (!$this->connected()) {
417
-            $this->debug('Connect failed: ' . $errstr . ', error number: ' . $errnum . ', host: ' . $this->host);
418
-            throw new SMTP_Validate_Email_Exception_No_Connection('Cannot ' .
419
-            'open a connection to remote host (' . $this->host . ')');
417
+            $this->debug('Connect failed: '.$errstr.', error number: '.$errnum.', host: '.$this->host);
418
+            throw new SMTP_Validate_Email_Exception_No_Connection('Cannot '.
419
+            'open a connection to remote host ('.$this->host.')');
420 420
         }
421 421
         $result = stream_set_timeout($this->socket, $this->connect_timeout);
422 422
         if (!$result) {
423 423
             throw new SMTP_Validate_Email_Exception_No_Timeout('Cannot set timeout');
424 424
         }
425
-        $this->debug('Connected to ' . $this->host . ' successfully');
425
+        $this->debug('Connected to '.$this->host.' successfully');
426 426
     }
427 427
 
428 428
     /**
@@ -435,7 +435,7 @@  discard block
 block discarded – undo
435 435
             $this->quit();
436 436
         }
437 437
         if ($this->connected()) {
438
-            $this->debug('Closing socket to ' . $this->host);
438
+            $this->debug('Closing socket to '.$this->host);
439 439
             fclose($this->socket);
440 440
         }
441 441
         $this->host = null;
@@ -482,7 +482,7 @@  discard block
 block discarded – undo
482 482
             return true;
483 483
         } catch (SMTP_Validate_Email_Exception_Unexpected_Response $e) {
484 484
             // connected, but recieved an unexpected response, so disconnect
485
-            $this->debug('Unexpected response after connecting: ' . $e->getMessage());
485
+            $this->debug('Unexpected response after connecting: '.$e->getMessage());
486 486
             $this->disconnect(false);
487 487
             return false;
488 488
         }
@@ -495,11 +495,11 @@  discard block
 block discarded – undo
495 495
     protected function ehlo() {
496 496
         try {
497 497
             // modern
498
-            $this->send('EHLO ' . $this->from_domain);
498
+            $this->send('EHLO '.$this->from_domain);
499 499
             $this->expect(self::SMTP_GENERIC_SUCCESS, $this->command_timeouts['ehlo']);
500 500
         } catch (SMTP_Validate_Email_Exception_Unexpected_Response $e) {
501 501
             // legacy
502
-            $this->send('HELO ' . $this->from_domain);
502
+            $this->send('HELO '.$this->from_domain);
503 503
             $this->expect(self::SMTP_GENERIC_SUCCESS, $this->command_timeouts['helo']);
504 504
         }
505 505
     }
@@ -515,7 +515,7 @@  discard block
 block discarded – undo
515 515
             throw new SMTP_Validate_Email_Exception_No_Helo('Need HELO before MAIL FROM');
516 516
         }
517 517
         // issue MAIL FROM, 5 minute timeout
518
-        $this->send('MAIL FROM:<' . $from . '>');
518
+        $this->send('MAIL FROM:<'.$from.'>');
519 519
         try {
520 520
             $this->expect(self::SMTP_GENERIC_SUCCESS, $this->command_timeouts['mail']);
521 521
             // set state flags
@@ -524,7 +524,7 @@  discard block
 block discarded – undo
524 524
             return true;
525 525
         } catch (SMTP_Validate_Email_Exception_Unexpected_Response $e) {
526 526
             // got something unexpected in response to MAIL FROM
527
-            $this->debug("Unexpected response to MAIL FROM\n:" . $e->getMessage());
527
+            $this->debug("Unexpected response to MAIL FROM\n:".$e->getMessage());
528 528
             // hotmail has been known to do this + was closing the connection
529 529
             // forcibly on their end, so we're killing the socket here too
530 530
             $this->disconnect(false);
@@ -553,17 +553,17 @@  discard block
 block discarded – undo
553 553
         }
554 554
         // issue RCPT TO, 5 minute timeout
555 555
         try {
556
-            $this->send('RCPT TO:<' . $to . '>');
556
+            $this->send('RCPT TO:<'.$to.'>');
557 557
             // process the response
558 558
             try {
559 559
                 $this->expect($expected_codes, $this->command_timeouts['rcpt']);
560 560
                 $this->state['rcpt'] = true;
561 561
                 $is_valid = true;
562 562
             } catch (SMTP_Validate_Email_Exception_Unexpected_Response $e) {
563
-                $this->debug('Unexpected response to RCPT TO: ' . $e->getMessage());
563
+                $this->debug('Unexpected response to RCPT TO: '.$e->getMessage());
564 564
             }
565 565
         } catch (SMTP_Validate_Email_Exception $e) {
566
-            $this->debug('Sending RCPT TO failed: ' . $e->getMessage());
566
+            $this->debug('Sending RCPT TO failed: '.$e->getMessage());
567 567
         }
568 568
         return $is_valid;
569 569
     }
@@ -595,7 +595,7 @@  discard block
 block discarded – undo
595 595
         // although RFC says QUIT can be issued at any time, we won't
596 596
         if ($this->state['helo']) {
597 597
             $this->send('QUIT');
598
-            $this->expect(array(self::SMTP_GENERIC_SUCCESS,self::SMTP_QUIT_SUCCESS), $this->command_timeouts['quit'], true);
598
+            $this->expect(array(self::SMTP_GENERIC_SUCCESS, self::SMTP_QUIT_SUCCESS), $this->command_timeouts['quit'], true);
599 599
         }
600 600
     }
601 601
 
@@ -631,13 +631,13 @@  discard block
 block discarded – undo
631 631
         if (!$this->connected()) {
632 632
             throw new SMTP_Validate_Email_Exception_No_Connection('No connection');
633 633
         }
634
-        $this->debug('send>>>: ' . $cmd);
634
+        $this->debug('send>>>: '.$cmd);
635 635
         // write the cmd to the connection stream
636
-        $result = fwrite($this->socket, $cmd . self::CRLF);
636
+        $result = fwrite($this->socket, $cmd.self::CRLF);
637 637
         // did the send work?
638 638
         if ($result === false) {
639
-            throw new SMTP_Validate_Email_Exception_Send_Failed('Send failed ' .
640
-            'on: ' . $this->host);
639
+            throw new SMTP_Validate_Email_Exception_Send_Failed('Send failed '.
640
+            'on: '.$this->host);
641 641
         }
642 642
         return $result;
643 643
     }
@@ -660,7 +660,7 @@  discard block
 block discarded – undo
660 660
         }
661 661
         // retrieve response
662 662
         $line = fgets($this->socket, 1024);
663
-        $this->debug('<<<recv: ' . $line);
663
+        $this->debug('<<<recv: '.$line);
664 664
         // have we timed out?
665 665
         $info = stream_get_meta_data($this->socket);
666 666
         if (!empty($info['timed_out'])) {
@@ -704,7 +704,7 @@  discard block
 block discarded – undo
704 704
             // no response in expect() probably means that the
705 705
             // remote server forcibly closed the connection so
706 706
             // lets clean up on our end as well?
707
-            $this->debug('No response in expect(): ' . $e->getMessage());
707
+            $this->debug('No response in expect(): '.$e->getMessage());
708 708
             $this->disconnect(false);
709 709
 
710 710
         }
@@ -720,7 +720,7 @@  discard block
 block discarded – undo
720 720
     protected function parse_email($email) {
721 721
         $parts = explode('@', $email);
722 722
         $domain = array_pop($parts);
723
-        $user= implode('@', $parts);
723
+        $user = implode('@', $parts);
724 724
         return array($user, $domain);
725 725
     }
726 726
 
@@ -789,9 +789,9 @@  discard block
 block discarded – undo
789 789
         if (empty($hostname)) {
790 790
             return null;
791 791
         }
792
-        $cmd = 'nslookup -type=MX ' . escapeshellarg($hostname);
792
+        $cmd = 'nslookup -type=MX '.escapeshellarg($hostname);
793 793
         if (!empty($this->mx_query_ns)) {
794
-            $cmd .= ' ' . escapeshellarg($this->mx_query_ns);
794
+            $cmd .= ' '.escapeshellarg($this->mx_query_ns);
795 795
         }
796 796
         exec($cmd, $output);
797 797
         if (empty($output)) {
@@ -823,9 +823,9 @@  discard block
 block discarded – undo
823 823
         $this->log($str);
824 824
         if ($this->debug == true) {
825 825
             if (PHP_SAPI != 'cli') {
826
-                $str = '<br/><pre>' . htmlspecialchars($str) . '</pre>';
826
+                $str = '<br/><pre>'.htmlspecialchars($str).'</pre>';
827 827
             }
828
-            echo "\n" . $str;
828
+            echo "\n".$str;
829 829
         }
830 830
     }
831 831
 
@@ -846,7 +846,7 @@  discard block
 block discarded – undo
846 846
      */
847 847
     private function stamp($msg) {
848 848
         $date = \DateTime::createFromFormat('U.u', sprintf('%.f', microtime(true)))->format('Y-m-d\TH:i:s.uO');
849
-        $line = '[' . $date . '] ' . $msg;
849
+        $line = '['.$date.'] '.$msg;
850 850
 
851 851
         return $line;
852 852
     }
Please login to merge, or discard this patch.