Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Zend\Mail\Protocol\Smtp does not reset protected $auth after disconnect #4690

Merged
merged 2 commits into from
Jun 20, 2013
Merged

Zend\Mail\Protocol\Smtp does not reset protected $auth after disconnect #4690

merged 2 commits into from
Jun 20, 2013

Conversation

mwillbanks
Copy link
Contributor

I use an offline worker process to process sending out of emails, as such keeping a connection open too long can cause issues with timeouts. Therefore I have my worker disconnect when it hits an internal timeout. Example:

    public function wait()
    {   
        if ($this->isConnected) {
            $this->log('disconnecting');
            $this->mail->disconnect();
            $this->isConnected = false;
        }   

        return parent::wait();
    } 

When it re-connects and attempts to send out an email, it fatally errors: Fatal error: Already authenticated for this session in /var/www/vendor/zendframework/zendframework/library/Zend/Mail/Protocol/Smtp.php on line 368

This is due to when the disconnect portion of the mail code is hit, it does not actually reset the $auth flag. As you can see from a greg command there is no place in where the flag is set back to false and is always true if you keep the same instance around and reuse it.

This change does 2 things:

  1. The SmtpProtocolSpy test asset has to have methods to set and get the protected members ($auth and $sess).
    We need both of these for simple reasons; $auth because we need to manually set it since we actually never really call any of the methods and secondly $sess because otherwise the ->quit() method would never actually make it into the block.
  2. Changes the quit() method to contain $this->auth = false (since this is indeed where most of the cleanup methods are for disconnect().

@mwillbanks
Copy link
Contributor Author

Since travis is having some fun issues lately... Here is the output from tests under Zend\Mail:

mwillbanks:tests mwillbanks$ phpunit ZendTest/Mail/
PHPUnit 3.7.12 by Sebastian Bergmann.

Configuration read from /Users/mwillbanks/Projects/zf2/tests/phpunit.xml.dist

............................................................II.  63 / 468 ( 13%)
............................................................... 126 / 468 ( 26%)
..........................................SSSSSSSSSSSSSSSSSSSSS 189 / 468 ( 40%)
SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS 252 / 468 ( 53%)
SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS 315 / 468 ( 67%)
SSS............................................................ 378 / 468 ( 80%)
..........................................SSSSSSSSSSSSSSSSSSSSS 441 / 468 ( 94%)
SSSSSSS......SS............

Time: 1 second, Memory: 13.75Mb

OK, but incomplete or skipped tests!
Tests: 468, Assertions: 620, Incomplete: 2, Skipped: 180.

public function setAuth($status)
{
$this->auth = (bool) $status;
return $this;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

newline

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants