PageRenderTime 43ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/app/protected/extensions/swiftmailer/lib/classes/Swift/Transport/Esmtp/Auth/PlainAuthenticator.php

https://bitbucket.org/kwangchin/zurmo
PHP | 54 lines | 24 code | 6 blank | 24 comment | 0 complexity | 01e8eaa565f1fb6638096cda02fc60ee MD5 | raw file
Possible License(s): LGPL-2.1, BSD-2-Clause, GPL-2.0, GPL-3.0, BSD-3-Clause, LGPL-3.0
  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. /**
  10. * Handles PLAIN authentication.
  11. * @package Swift
  12. * @subpackage Transport
  13. * @author Chris Corbyn
  14. */
  15. class Swift_Transport_Esmtp_Auth_PlainAuthenticator
  16. implements Swift_Transport_Esmtp_Authenticator
  17. {
  18. /**
  19. * Get the name of the AUTH mechanism this Authenticator handles.
  20. * @return string
  21. */
  22. public function getAuthKeyword()
  23. {
  24. return 'PLAIN';
  25. }
  26. /**
  27. * Try to authenticate the user with $username and $password.
  28. * @param Swift_Transport_SmtpAgent $agent
  29. * @param string $username
  30. * @param string $password
  31. * @return boolean
  32. */
  33. public function authenticate(Swift_Transport_SmtpAgent $agent,
  34. $username, $password)
  35. {
  36. try
  37. {
  38. $message = base64_encode($username . chr(0) . $username . chr(0) . $password);
  39. $agent->executeCommand(sprintf("AUTH PLAIN %s\r\n", $message), array(235));
  40. return true;
  41. }
  42. catch (Swift_TransportException $e)
  43. {
  44. $agent->executeCommand("RSET\r\n", array(250));
  45. return false;
  46. }
  47. }
  48. }