TYPO3  7.6
AuthHandler.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of SwiftMailer.
5  * (c) 2004-2009 Chris Corbyn
6  *
7  * For the full copyright and license information, please view the LICENSE
8  * file that was distributed with this source code.
9  */
10 
17 {
23  private $_authenticators = array();
24 
30  private $_username;
31 
37  private $_password;
38 
44  private $_auth_mode;
45 
51  private $_esmtpParams = array();
52 
58  public function __construct(array $authenticators)
59  {
60  $this->setAuthenticators($authenticators);
61  }
62 
68  public function setAuthenticators(array $authenticators)
69  {
70  $this->_authenticators = $authenticators;
71  }
72 
78  public function getAuthenticators()
79  {
81  }
82 
88  public function setUsername($username)
89  {
90  $this->_username = $username;
91  }
92 
98  public function getUsername()
99  {
100  return $this->_username;
101  }
102 
108  public function setPassword($password)
109  {
110  $this->_password = $password;
111  }
112 
118  public function getPassword()
119  {
120  return $this->_password;
121  }
122 
128  public function setAuthMode($mode)
129  {
130  $this->_auth_mode = $mode;
131  }
132 
138  public function getAuthMode()
139  {
140  return $this->_auth_mode;
141  }
142 
148  public function getHandledKeyword()
149  {
150  return 'AUTH';
151  }
152 
158  public function setKeywordParams(array $parameters)
159  {
160  $this->_esmtpParams = $parameters;
161  }
162 
168  public function afterEhlo(Swift_Transport_SmtpAgent $agent)
169  {
170  if ($this->_username) {
171  $count = 0;
172  foreach ($this->_getAuthenticatorsForAgent() as $authenticator) {
173  if (in_array(strtolower($authenticator->getAuthKeyword()),
174  array_map('strtolower', $this->_esmtpParams))) {
175  $count++;
176  if ($authenticator->authenticate($agent, $this->_username, $this->_password)) {
177  return;
178  }
179  }
180  }
181  throw new Swift_TransportException(
182  'Failed to authenticate on SMTP server with username "'.
183  $this->_username.'" using '.$count.' possible authenticators'
184  );
185  }
186  }
187 
191  public function getMailParams()
192  {
193  return array();
194  }
195 
199  public function getRcptParams()
200  {
201  return array();
202  }
203 
207  public function onCommand(Swift_Transport_SmtpAgent $agent, $command, $codes = array(), &$failedRecipients = null, &$stop = false)
208  {
209  }
210 
220  public function getPriorityOver($esmtpKeyword)
221  {
222  return 0;
223  }
224 
230  public function exposeMixinMethods()
231  {
232  return array('setUsername', 'getUsername', 'setPassword', 'getPassword', 'setAuthMode', 'getAuthMode');
233  }
234 
238  public function resetState()
239  {
240  }
241 
249  protected function _getAuthenticatorsForAgent()
250  {
251  if (!$mode = strtolower($this->_auth_mode)) {
252  return $this->_authenticators;
253  }
254 
255  foreach ($this->_authenticators as $authenticator) {
256  if (strtolower($authenticator->getAuthKeyword()) == $mode) {
257  return array($authenticator);
258  }
259  }
260 
261  throw new Swift_TransportException('Auth mode '.$mode.' is invalid');
262  }
263 }