Skip to content

Commit

Permalink
Merge pull request #11 from rubenCodeforges/patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
ddtraceweb committed Dec 3, 2014
2 parents 620514a + 16cfb70 commit f81435f
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions lib/SmtpValidatorEmail/ValidatorEmail.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use SmtpValidatorEmail\Mx\Mx;
use SmtpValidatorEmail\Smtp\Smtp;


/**
* Class ValidatorEmail
* @package SmtpValidatorEmail
Expand Down Expand Up @@ -87,7 +88,6 @@ public function __construct($emails = array(), $sender = '', $options = array())
$emailBag->add((array)$emails);
$domainBag = $this->setEmailsDomains($emailBag);
$this->domains = $domainBag->all();

}

if (!empty($sender)) {
Expand Down Expand Up @@ -131,7 +131,7 @@ public function __construct($emails = array(), $sender = '', $options = array())

} catch (ExceptionNoConnection $e) {
// unable to connect to host, so these addresses are invalid?
$this->setDomainResults($users, $dom, 0);
$this->setDomainResults($users, $dom, 0,'unable to connect to host');
}
}

Expand All @@ -147,29 +147,34 @@ public function __construct($emails = array(), $sender = '', $options = array())
// try issuing MAIL FROM
if (!($smtp->mail($this->fromUser . '@' . $this->fromDomain))) {
// MAIL FROM not accepted, we can't talk
$this->setDomainResults($users, $dom, $options['noCommIsValid']);
$this->setDomainResults($users, $dom, $options['noCommIsValid'],'MAIL FROM not accepted');
}

/**
* if we're still connected, proceed (cause we might get
* disconnected, or banned, or greylisted temporarily etc.)
* see mail() for more
*/
if ($smtp->isConnect()) {
if ( $smtp->isConnect()) {

$smtp->noop();

// Do a catch-all test for the domain always.
// This increases checking time for a domain slightly,
// but doesn't confuse users.
$isCatchallDomain = $smtp->acceptsAnyRecipient($dom);
try{
$isCatchallDomain = $smtp->acceptsAnyRecipient($dom);
}catch (\Exception $e) {
$this->setDomainResults($users, $dom, $options['catchAllIsValid'], 'error while on CatchAll test: '.$e );
}


// if a catchall domain is detected, and we consider
// accounts on such domains as invalid, mark all the
// users as invalid and move on
if ($isCatchallDomain) {
if (!$options['catchAllIsValid']) {
$this->setDomainResults($users, $dom, $options['catchAllIsValid']);
$this->setDomainResults($users, $dom, $options['catchAllIsValid'],'catch all detected');
continue;
}
}
Expand All @@ -182,8 +187,7 @@ public function __construct($emails = array(), $sender = '', $options = array())
$address = $user . '@' . $dom->getDomain();
$this->results[$address] = $smtp->rcpt($address);

if($this->results[$address] == 1)
{
if ($this->results[$address] == 1) {
$loopStop = 1;
}
$smtp->noop();
Expand All @@ -201,12 +205,11 @@ public function __construct($emails = array(), $sender = '', $options = array())
}

} else {

// we didn't get a good response to helo and should be disconnected already
$this->setDomainResults($users, $dom, $options['noCommIsValid']);

$this->setDomainResults($users, $dom, $options['noCommIsValid'],'bad response on helo');
}

} else {
$this->setDomainResults($users, $dom, 0,'no connection ');
}

if ($options['domainMoreInfo']) {
Expand Down Expand Up @@ -279,15 +282,19 @@ public function setSender($email)
* @param array $users Array of users (usernames)
* @param Domain $domain The domain
* @param int $val Value to set
* @param String $info Optional , can be used to give additional information about the result
*/
private function setDomainResults($users, Domain $domain, $val)
private function setDomainResults($users, Domain $domain, $val, $info='')
{
if (!is_array($users)) {
$users = (array)$users;
}

foreach ($users as $user) {
$this->results[$user . '@' . $domain->getDomain()] = $val;
$this->results[$user . '@' . $domain->getDomain()] = [
'result' => $val,
'info' => $info
];
}
}
}

0 comments on commit f81435f

Please sign in to comment.