/**
  * @param $fromUser
  * @param $fromDomain
  * @return bool
  * @throws \SmtpValidatorEmail\Exception\ExceptionNoMailFrom
  */
 public function rcptEachUser($fromUser, $fromDomain)
 {
     $this->transport->getSmtp()->noop();
     // rcpt to for each user
     // var_dump("user list :");
     // var_dump($this->users);
     $iterator = 0;
     $dynamicTimeout = 0;
     if (count($this->users) >= $this->options['sameDomainLimit']) {
         $dynamicTimeout = count($this->users);
     }
     foreach ($this->users as $user) {
         // var_dump("Checking user :"******"Connection lost. Reconnect.");
             $this->establishConnection();
         }
         $address = $user . '@' . $this->dom->getDomain();
         // Sets the results to an integer 0 ( failure ) or 1 ( success )
         $result = $this->transport->getSmtp()->rcpt($address);
         // var_dump("The adress $address, was checked , result: $result");
         $this->statusManager->updateStatus($address, $result);
         if ($iterator == count($this->users)) {
             // stop the loop
             return 1;
         }
         $this->transport->getSmtp()->noop();
         //            if( $iterator > 0 && $iterator % 4 == 0 ){
         //                $this->transport->disconnect();
         //                sleep($dynamicTimeout);
         //            }
         $iterator++;
     }
 }
 /**
  * @param $fromUser
  * @param $fromDomain
  * @return bool
  * @throws \SmtpValidatorEmail\Exception\ExceptionNoMailFrom
  */
 public function rcptEachUser($fromUser, $fromDomain)
 {
     $this->transport->getSmtp()->noop();
     $iterator = 0;
     $dynamicTimeout = 0;
     if (count($this->users) >= $this->options['sameDomainLimit']) {
         $dynamicTimeout = count($this->users);
     }
     foreach ($this->users as $user) {
         if (!$this->transport->getSmtp()->isConnect()) {
             $this->establishConnection();
         }
         $address = $user . '@' . $this->dom->getDomain();
         // Sets the results to an integer 0 ( failure ) or 1 ( success )
         $result = $this->transport->getSmtp()->rcpt($address);
         if ($this->options['detailResults'] === false) {
             $this->statusManager->updateStatus($address, $result);
         }
         if ($iterator == count($this->users)) {
             // stop the loop
             return 1;
         }
         $this->transport->getSmtp()->noop();
         //            if( $iterator > 0 && $iterator % 4 == 0 ){
         //                $this->transport->disconnect();
         //                sleep($dynamicTimeout);
         //            }
         $iterator++;
     }
 }
 /**
  * Receives lines from the remote host and looks for expected response codes.
  *
  * @param string|array $codes     A list of one or more expected response codes
  * @param int          $timeout   The timeout for this individual command, if any
  *
  * @return string        The last text message received
  * @throws Exception\ExceptionUnexpectedResponse
  */
 public function expect($codes, $timeout = null)
 {
     if (!is_array($codes)) {
         $codes = (array) $codes;
     }
     $code = null;
     $text = '';
     try {
         $text = $line = $this->recv($timeout);
         while (preg_match("/^[0-9]+-/", $line)) {
             $line = $this->recv($timeout);
             $text .= $line;
         }
         sscanf($line, '%d%s', $code, $text);
         if ($code === null || !in_array($code, $codes)) {
             $this->statusManager->setStatus($this->users, new Domain($this->domain), 0, 'UnexpectedResponse: ' . $line);
             //throw new Exception\ExceptionUnexpectedResponse($line);
         }
     } catch (Exception\ExceptionNoResponse $e) {
         // no response in expect() probably means that the
         // remote server forcibly closed the connection so
         // lets clean up on our end as well?
         $this->disconnect(false);
     }
     return $text;
 }
Example #4
0
 /**
  * Sends a command to the remote host.
  *
  * @param string $cmd    The cmd to send
  *
  * @return int|bool      Number of bytes written to the stream
  * @throws Exception\ExceptionNoConnection
  * @throws Exception\ExceptionSendFailed
  */
 public function send($cmd)
 {
     // must be connected
     if (!$this->isConnect()) {
         $this->statusManager->setStatus($this->users, new Domain($this->domain), 0, 'No connection');
         return false;
     }
     $result = false;
     // write the cmd to the connection stream
     try {
         if ($this->validationOptions['debug'] === true) {
             $this->debug[] = ["timestamp" => microtime(true), "message" => "send> {$cmd}"];
         }
         $result = fwrite($this->socket, $cmd . self::CRLF);
     } catch (\Exception $e) {
         // did the send work?
         if ($result === false) {
             $this->statusManager->setStatus($this->users, new Domain($this->domain), 0, 'Send failed on: ' . $this->host);
             return $result;
         }
     }
     return $result;
 }