/framework/vendor/swift/lib/classes/Swift/Transport/Esmtp/Auth/PlainAuthenticator.php

http://zoop.googlecode.com/ · PHP · 57 lines · 24 code · 6 blank · 27 comment · 0 complexity · 9ab3d1fff20a26e86ae454823b074ac4 MD5 · raw file

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