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

https://bitbucket.org/hamidrezas/melobit · PHP · 98 lines · 30 code · 12 blank · 56 comment · 3 complexity · efc90b079f14dfa496f3a1318841c5d4 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: Login.php 24594 2012-01-05 21:27:01Z matthew $
  21. */
  22. /**
  23. * @see Zend_Mail_Protocol_Smtp
  24. */
  25. require_once 'Zend/Mail/Protocol/Smtp.php';
  26. /**
  27. * Performs LOGIN 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_Login extends Zend_Mail_Protocol_Smtp
  36. {
  37. /**
  38. * LOGIN username
  39. *
  40. * @var string
  41. */
  42. protected $_username;
  43. /**
  44. * LOGIN 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. * @return void
  56. */
  57. public function __construct($host = '127.0.0.1', $port = null, $config = null)
  58. {
  59. if (is_array($config)) {
  60. if (isset($config['username'])) {
  61. $this->_username = $config['username'];
  62. }
  63. if (isset($config['password'])) {
  64. $this->_password = $config['password'];
  65. }
  66. }
  67. parent::__construct($host, $port, $config);
  68. }
  69. /**
  70. * Perform LOGIN authentication with supplied credentials
  71. *
  72. * @return void
  73. */
  74. public function auth()
  75. {
  76. // Ensure AUTH has not already been initiated.
  77. parent::auth();
  78. $this->_send('AUTH LOGIN');
  79. $this->_expect(334);
  80. $this->_send(base64_encode($this->_username));
  81. $this->_expect(334);
  82. $this->_send(base64_encode($this->_password));
  83. $this->_expect(235);
  84. $this->_auth = true;
  85. }
  86. }