1: <?php
2:
3: /*
4: * This file is part of SwiftMailer.
5: * (c) 2004-2009 Chris Corbyn
6: *
7: * For the full copyright and license information, please view the LICENSE
8: * file that was distributed with this source code.
9: */
10:
11: /**
12: * Handles PLAIN authentication.
13: * @package Swift
14: * @subpackage Transport
15: * @author Chris Corbyn
16: */
17: class Swift_Transport_Esmtp_Auth_PlainAuthenticator implements Swift_Transport_Esmtp_Authenticator
18: {
19: /**
20: * Get the name of the AUTH mechanism this Authenticator handles.
21: * @return string
22: */
23: public function getAuthKeyword()
24: {
25: return 'PLAIN';
26: }
27:
28: /**
29: * Try to authenticate the user with $username and $password.
30: * @param Swift_Transport_SmtpAgent $agent
31: * @param string $username
32: * @param string $password
33: * @return boolean
34: */
35: public function authenticate(Swift_Transport_SmtpAgent $agent, $username, $password)
36: {
37: try {
38: $message = base64_encode($username . chr(0) . $username . chr(0) . $password);
39: $agent->executeCommand(sprintf("AUTH PLAIN %s\r\n", $message), array(235));
40:
41: return true;
42: } catch (Swift_TransportException $e) {
43: $agent->executeCommand("RSET\r\n", array(250));
44:
45: return false;
46: }
47: }
48: }
49: