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

https://github.com/intypica/zf2 · PHP · 98 lines · 31 code · 10 blank · 57 comment · 3 complexity · 86b24c8c124379416aa9e7680113632e 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-2010 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. /**
  23. * @namespace
  24. */
  25. namespace Zend\Mail\Protocol\Smtp\Auth;
  26. use Zend\Mail\Protocol\Smtp;
  27. /**
  28. * Performs LOGIN authentication
  29. *
  30. * @uses \Zend\Mail\Protocol\Smtp\Smtp
  31. * @category Zend
  32. * @package Zend_Mail
  33. * @subpackage Protocol
  34. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  35. * @license http://framework.zend.com/license/new-bsd New BSD License
  36. */
  37. class Login extends Smtp\Smtp
  38. {
  39. /**
  40. * LOGIN username
  41. *
  42. * @var string
  43. */
  44. protected $_username;
  45. /**
  46. * LOGIN password
  47. *
  48. * @var string
  49. */
  50. protected $_password;
  51. /**
  52. * Constructor.
  53. *
  54. * @param string $host (Default: 127.0.0.1)
  55. * @param int $port (Default: null)
  56. * @param array $config Auth-specific parameters
  57. * @return void
  58. */
  59. public function __construct($host = '127.0.0.1', $port = null, $config = null)
  60. {
  61. if (is_array($config)) {
  62. if (isset($config['username'])) {
  63. $this->_username = $config['username'];
  64. }
  65. if (isset($config['password'])) {
  66. $this->_password = $config['password'];
  67. }
  68. }
  69. parent::__construct($host, $port, $config);
  70. }
  71. /**
  72. * Perform LOGIN authentication with supplied credentials
  73. *
  74. * @return void
  75. */
  76. public function auth()
  77. {
  78. // Ensure AUTH has not already been initiated.
  79. parent::auth();
  80. $this->_send('AUTH LOGIN');
  81. $this->_expect(334);
  82. $this->_send(base64_encode($this->_username));
  83. $this->_expect(334);
  84. $this->_send(base64_encode($this->_password));
  85. $this->_expect(235);
  86. $this->_auth = true;
  87. }
  88. }