/library/Zend/Mail/Protocol/Smtp/Auth/Plain.php

https://bitbucket.org/Ebozavrik/test-application · PHP · 97 lines · 28 code · 12 blank · 57 comment · 3 complexity · 3f741e7f02625c71b1dca911e271894b MD5 · raw file

  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Mail
  17. * @subpackage Protocol
  18. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id: Plain.php 24593 2012-01-05 20:35:02Z matthew $
  21. */
  22. /**
  23. * @see Zend_Mail_Protocol_Smtp
  24. */
  25. require_once 'Zend/Mail/Protocol/Smtp.php';
  26. /**
  27. * Performs PLAIN authentication
  28. *
  29. * @category Zend
  30. * @package Zend_Mail
  31. * @subpackage Protocol
  32. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  33. * @license http://framework.zend.com/license/new-bsd New BSD License
  34. */
  35. class Zend_Mail_Protocol_Smtp_Auth_Plain extends Zend_Mail_Protocol_Smtp
  36. {
  37. /**
  38. * PLAIN username
  39. *
  40. * @var string
  41. */
  42. protected $_username;
  43. /**
  44. * PLAIN password
  45. *
  46. * @var string
  47. */
  48. protected $_password;
  49. /**
  50. * Constructor.
  51. *
  52. * @param string $host (Default: 127.0.0.1)
  53. * @param int $port (Default: null)
  54. * @param array $config Auth-specific parameters
  55. *
  56. * @return void
  57. */
  58. public function __construct ($host = '127.0.0.1', $port = null, $config = null)
  59. {
  60. if (is_array($config)) {
  61. if (isset( $config['username'] )) {
  62. $this->_username = $config['username'];
  63. }
  64. if (isset( $config['password'] )) {
  65. $this->_password = $config['password'];
  66. }
  67. }
  68. parent::__construct($host, $port, $config);
  69. }
  70. /**
  71. * Perform PLAIN authentication with supplied credentials
  72. *
  73. * @return void
  74. */
  75. public function auth ()
  76. {
  77. // Ensure AUTH has not already been initiated.
  78. parent::auth();
  79. $this->_send('AUTH PLAIN');
  80. $this->_expect(334);
  81. $this->_send(base64_encode("\0" . $this->_username . "\0" . $this->_password));
  82. $this->_expect(235);
  83. $this->_auth = true;
  84. }
  85. }