PageRenderTime 53ms CodeModel.GetById 29ms RepoModel.GetById 1ms app.codeStats 0ms

/modules/email/vendor/swift/classes/Swift/Transport/Esmtp/AuthHandler.php

https://bitbucket.org/levjke/kohanablogds
PHP | 222 lines | 90 code | 24 blank | 108 comment | 3 complexity | 0b69957c87e1183bd281437cbcd3a781 MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.1
  1. <?php
  2. /*
  3. Handles the ESMTP AUTH extension in Swift Mailer.
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. //@require 'Swift/TransportException.php';
  16. //@require 'Swift/Transport/EsmtpHandler.php';
  17. //@require 'Swift/Transport/SmtpAgent.php';
  18. /**
  19. * An ESMTP handler for AUTH support.
  20. * @package Swift
  21. * @subpackage Transport
  22. * @author Chris Corbyn
  23. */
  24. class Swift_Transport_Esmtp_AuthHandler implements Swift_Transport_EsmtpHandler
  25. {
  26. /**
  27. * Authenticators available to process the request.
  28. * @var Swift_Transport_Esmtp_Authenticator[]
  29. * @access private
  30. */
  31. private $_authenticators = array();
  32. /**
  33. * The username for authentication.
  34. * @var string
  35. * @access private
  36. */
  37. private $_username;
  38. /**
  39. * The password for authentication.
  40. * @var string
  41. * @access private
  42. */
  43. private $_password;
  44. /**
  45. * The ESMTP AUTH parameters available.
  46. * @var string[]
  47. * @access private
  48. */
  49. private $_esmtpParams = array();
  50. /**
  51. * Create a new AuthHandler with $authenticators for support.
  52. * @param Swift_Transport_Esmtp_Authenticator[] $authenticators
  53. */
  54. public function __construct(array $authenticators)
  55. {
  56. $this->setAuthenticators($authenticators);
  57. }
  58. /**
  59. * Set the Authenticators which can process a login request.
  60. * @param Swift_Transport_Esmtp_Authenticator[] $authenticators
  61. */
  62. public function setAuthenticators(array $authenticators)
  63. {
  64. $this->_authenticators = $authenticators;
  65. }
  66. /**
  67. * Get the Authenticators which can process a login request.
  68. * @return Swift_Transport_Esmtp_Authenticator[]
  69. */
  70. public function getAuthenticators()
  71. {
  72. return $this->_authenticators;
  73. }
  74. /**
  75. * Set the username to authenticate with.
  76. * @param string $username
  77. */
  78. public function setUsername($username)
  79. {
  80. $this->_username = $username;
  81. }
  82. /**
  83. * Get the username to authenticate with.
  84. * @return string
  85. */
  86. public function getUsername()
  87. {
  88. return $this->_username;
  89. }
  90. /**
  91. * Set the password to authenticate with.
  92. * @param string $password
  93. */
  94. public function setPassword($password)
  95. {
  96. $this->_password = $password;
  97. }
  98. /**
  99. * Get the password to authenticate with.
  100. * @return string
  101. */
  102. public function getPassword()
  103. {
  104. return $this->_password;
  105. }
  106. /**
  107. * Get the name of the ESMTP extension this handles.
  108. * @return boolean
  109. */
  110. public function getHandledKeyword()
  111. {
  112. return 'AUTH';
  113. }
  114. /**
  115. * Set the parameters which the EHLO greeting indicated.
  116. * @param string[] $parameters
  117. */
  118. public function setKeywordParams(array $parameters)
  119. {
  120. $this->_esmtpParams = $parameters;
  121. }
  122. /**
  123. * Runs immediately after a EHLO has been issued.
  124. * @param Swift_Transport_SmtpAgent $agent to read/write
  125. */
  126. public function afterEhlo(Swift_Transport_SmtpAgent $agent)
  127. {
  128. if ($this->_username)
  129. {
  130. $count = 0;
  131. foreach ($this->_authenticators as $authenticator)
  132. {
  133. if (in_array(strtolower($authenticator->getAuthKeyword()),
  134. array_map('strtolower', $this->_esmtpParams)))
  135. {
  136. $count++;
  137. if ($authenticator->authenticate($agent, $this->_username, $this->_password))
  138. {
  139. return;
  140. }
  141. }
  142. }
  143. throw new Swift_TransportException(
  144. 'Failed to authenticate on SMTP server with username "' .
  145. $this->_username . '" using ' . $count . ' possible authenticators'
  146. );
  147. }
  148. }
  149. /**
  150. * Not used.
  151. */
  152. public function getMailParams()
  153. {
  154. return array();
  155. }
  156. /**
  157. * Not used.
  158. */
  159. public function getRcptParams()
  160. {
  161. return array();
  162. }
  163. /**
  164. * Not used.
  165. */
  166. public function onCommand(Swift_Transport_SmtpAgent $agent,
  167. $command, $codes = array(), &$failedRecipients = null, &$stop = false)
  168. {
  169. }
  170. /**
  171. * Returns +1, -1 or 0 according to the rules for usort().
  172. * This method is called to ensure extensions can be execute in an appropriate order.
  173. * @param string $esmtpKeyword to compare with
  174. * @return int
  175. */
  176. public function getPriorityOver($esmtpKeyword)
  177. {
  178. return 0;
  179. }
  180. /**
  181. * Returns an array of method names which are exposed to the Esmtp class.
  182. * @return string[]
  183. */
  184. public function exposeMixinMethods()
  185. {
  186. return array('setUsername', 'getUsername', 'setPassword', 'getPassword');
  187. }
  188. /**
  189. * Not used.
  190. */
  191. public function resetState()
  192. {
  193. }
  194. }