XOOPS RMCommon Utilities  2.1.8.91RC
 All Classes Namespaces Files Functions Variables
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 
11 //@require 'Swift/TransportException.php';
12 //@require 'Swift/Transport/EsmtpHandler.php';
13 //@require 'Swift/Transport/SmtpAgent.php';
14 
22 {
23 
29  private $_authenticators = array();
30 
36  private $_username;
37 
43  private $_password;
44 
50  private $_auth_mode;
51 
57  private $_esmtpParams = array();
58 
63  public function __construct(array $authenticators)
64  {
65  $this->setAuthenticators($authenticators);
66  }
67 
72  public function setAuthenticators(array $authenticators)
73  {
74  $this->_authenticators = $authenticators;
75  }
76 
81  public function getAuthenticators()
82  {
84  }
85 
90  public function setUsername($username)
91  {
92  $this->_username = $username;
93  }
94 
99  public function getUsername()
100  {
101  return $this->_username;
102  }
103 
108  public function setPassword($password)
109  {
110  $this->_password = $password;
111  }
112 
117  public function getPassword()
118  {
119  return $this->_password;
120  }
121 
126  public function setAuthMode($mode)
127  {
128  $this->_auth_mode = $mode;
129  }
130 
135  public function getAuthMode()
136  {
137  return $this->_auth_mode;
138  }
139 
144  public function getHandledKeyword()
145  {
146  return 'AUTH';
147  }
148 
153  public function setKeywordParams(array $parameters)
154  {
155  $this->_esmtpParams = $parameters;
156  }
157 
162  public function afterEhlo(Swift_Transport_SmtpAgent $agent)
163  {
164  if ($this->_username)
165  {
166  $count = 0;
167  foreach ($this->_getAuthenticatorsForAgent() as $authenticator)
168  {
169  if (in_array(strtolower($authenticator->getAuthKeyword()),
170  array_map('strtolower', $this->_esmtpParams)))
171  {
172  $count++;
173  if ($authenticator->authenticate($agent, $this->_username, $this->_password))
174  {
175  return;
176  }
177  }
178  }
179  throw new Swift_TransportException(
180  'Failed to authenticate on SMTP server with username "' .
181  $this->_username . '" using ' . $count . ' possible authenticators'
182  );
183  }
184  }
185 
189  public function getMailParams()
190  {
191  return array();
192  }
193 
197  public function getRcptParams()
198  {
199  return array();
200  }
201 
205  public function onCommand(Swift_Transport_SmtpAgent $agent,
206  $command, $codes = array(), &$failedRecipients = null, &$stop = false)
207  {
208  }
209 
216  public function getPriorityOver($esmtpKeyword)
217  {
218  return 0;
219  }
220 
225  public function exposeMixinMethods()
226  {
227  return array('setUsername', 'getUsername', 'setPassword', 'getPassword', 'setAuthMode', 'getAuthMode');
228  }
229 
233  public function resetState()
234  {
235  }
236 
237  // -- Protected methods
238 
245  protected function _getAuthenticatorsForAgent()
246  {
247  if (!$mode = strtolower($this->_auth_mode))
248  {
249  return $this->_authenticators;
250  }
251 
252  foreach ($this->_authenticators as $authenticator)
253  {
254  if (strtolower($authenticator->getAuthKeyword()) == $mode)
255  {
256  return array($authenticator);
257  }
258  }
259 
260  throw new Swift_TransportException('Auth mode '.$mode.' is invalid');
261  }
262 }