/** * Try to authenticate using the username and password * Returns false on failure * @param string The username * @param string The password * @param Swift The instance of Swift this authenticator is used in * @return boolean */ public function isAuthenticated($user, $pass, Swift $swift) { $log = Swift_LogContainer::getLog(); if ($log->hasLevel(Swift_Log::LOG_EVERYTHING)) { $log->add("Trying POP3 Before SMTP authentication. Disconnecting from SMTP first."); } $swift->disconnect(); try { $this->connection->start(); $this->connection->assertOk($this->connection->read()); $this->connection->write("USER " . $user); $this->connection->assertOk($this->connection->read()); $this->connection->write("PASS " . $pass); $this->connection->assertOk($this->connection->read()); $this->connection->write("QUIT"); $this->connection->assertOk($this->connection->read()); $this->connection->stop(); } catch (Swift_ConnectionException $e) { if ($log->hasLevel(Swift_Log::LOG_ERRORS)) { $log->add($e->getMessage(),Swift_Log::ERROR); $log->add("POP3 authentication failed."); } return false; } $options = $swift->getOptions(); $swift->setOptions($options | Swift::NO_POST_CONNECT); $swift->connect(); $swift->setOptions($options); return true; }
/** * Restarts Swift forcibly. */ protected function forceRestartSwift() { //Pre-empting problems trying to issue "QUIT" to a dead connection $this->swift->connection->stop(); $this->swift->connection->start(); $this->swift->disconnect(); //Restart swift $this->swift->connect(); }
/** * Restarts Swift forcibly. */ function forceRestartSwift() { Swift_Errors::reset(); //Pre-empting problems trying to issue "QUIT" to a dead connection $this->swift->connection->stop(); $this->swift->connection->start(); $this->swift->disconnect(); //Restart swift $this->swift->connect(); $this->doRestart = false; }
/** * Connect to the MTA if not already connected */ public function connect() { if (!$this->isConnected()) { try { $this->swift->connect(); return true; } catch (Swift_ConnectionException $e) { $this->failed = true; $this->setError("Swift failed to run the connection process:<br />" . $e->getMessage()); } } return false; }
/** * Connect to the MTA if not already connected */ function connect() { if (!$this->isConnected()) { Swift_Errors::expect($e, "Swift_ConnectionException"); $this->swift->connect(); if ($e) { $this->failed = true; $this->setError("Swift failed to run the connection process:<br />" . $e->getMessage()); return false; } Swift_Errors::clear("Swift_ConnectionException"); } return true; }
public function testDisconnectListenerRunsUponDisconnect() { $conn = new FullMockConnection(); $conn->setReturnValueAt(0, "read", "220 Hello xx"); $conn->setReturnValueAt(1, "read", "250 Hello xxx"); $conn->setReturnValueAt(2, "read", "221 Bye"); $disconnect_listener = new MockDisconnectListener(); $disconnect_listener->expectCallCount("disconnectPerformed", 1); $swift = new Swift($conn); $swift->attachPlugin($disconnect_listener, "myplugin"); $swift->disconnect(); $conn = new FullMockConnection(); $conn->setReturnValueAt(0, "read", "220 Hello xx"); $conn->setReturnValueAt(1, "read", "250 Hello xxx"); $conn->setReturnValueAt(2, "read", "221 Bye"); $conn->setReturnValueAt(3, "read", "220 Hello xx"); $conn->setReturnValueAt(4, "read", "250 Hello xxx"); $conn->setReturnValueAt(5, "read", "221 Bye"); $conn->setReturnValueAt(6, "read", "220 Hello xx"); $conn->setReturnValueAt(7, "read", "250 Hello xxx"); $conn->setReturnValueAt(8, "read", "221 Bye"); $disconnect_listener = new MockDisconnectListener(); $disconnect_listener->expectCallCount("disconnectPerformed", 3); $swift = new Swift($conn); $swift->attachPlugin($disconnect_listener, "myplugin"); $swift->disconnect(); $swift->connect(); $swift->disconnect(); $swift->connect(); $swift->disconnect(); }