@@ -29,12 +29,12 @@ class EsmtpTransport extends SmtpTransport
2929 private $ authenticators = [];
3030 private $ username = '' ;
3131 private $ password = '' ;
32- private $ authMode ;
3332
34- public function __construct (string $ host = 'localhost ' , int $ port = 0 , bool $ tls = null , string $ authMode = null , EventDispatcherInterface $ dispatcher = null , LoggerInterface $ logger = null )
33+ public function __construct (string $ host = 'localhost ' , int $ port = 0 , bool $ tls = null , EventDispatcherInterface $ dispatcher = null , LoggerInterface $ logger = null )
3534 {
3635 parent ::__construct (null , $ dispatcher , $ logger );
3736
37+ // order is important here (roughly most secure and popular first)
3838 $ this ->authenticators = [
3939 new Auth \CramMd5Authenticator (),
4040 new Auth \LoginAuthenticator (),
@@ -61,9 +61,6 @@ public function __construct(string $host = 'localhost', int $port = 0, bool $tls
6161
6262 $ stream ->setHost ($ host );
6363 $ stream ->setPort ($ port );
64- if (null !== $ authMode ) {
65- $ this ->setAuthMode ($ authMode );
66- }
6764 }
6865
6966 public function setUsername (string $ username ): self
@@ -90,18 +87,6 @@ public function getPassword(): string
9087 return $ this ->password ;
9188 }
9289
93- public function setAuthMode (string $ mode ): self
94- {
95- $ this ->authMode = $ mode ;
96-
97- return $ this ;
98- }
99-
100- public function getAuthMode (): string
101- {
102- return $ this ->authMode ;
103- }
104-
10590 public function addAuthenticator (AuthenticatorInterface $ authenticator ): void
10691 {
10792 $ this ->authenticators [] = $ authenticator ;
@@ -166,7 +151,7 @@ private function handleAuth(array $modes): void
166151 $ authNames = [];
167152 $ errors = [];
168153 $ modes = array_map ('strtolower ' , $ modes );
169- foreach ($ this ->getActiveAuthenticators () as $ authenticator ) {
154+ foreach ($ this ->authenticators as $ authenticator ) {
170155 if (!\in_array (strtolower ($ authenticator ->getAuthKeyword ()), $ modes , true )) {
171156 continue ;
172157 }
@@ -195,22 +180,4 @@ private function handleAuth(array $modes): void
195180
196181 throw new TransportException ($ message );
197182 }
198-
199- /**
200- * @return AuthenticatorInterface[]
201- */
202- private function getActiveAuthenticators (): array
203- {
204- if (!$ mode = strtolower ($ this ->authMode )) {
205- return $ this ->authenticators ;
206- }
207-
208- foreach ($ this ->authenticators as $ authenticator ) {
209- if (strtolower ($ authenticator ->getAuthKeyword ()) === $ mode ) {
210- return [$ authenticator ];
211- }
212- }
213-
214- throw new TransportException (sprintf ('Auth mode "%s" is invalid. ' , $ mode ));
215- }
216183}
0 commit comments