Fix handling of failed attempts to encrypt for starttls = 'may'
authorTim Düsterhus <duesterhus@woltlab.com>
Wed, 19 Jul 2017 15:41:54 +0000 (17:41 +0200)
committerTim Düsterhus <duesterhus@woltlab.com>
Wed, 19 Jul 2017 15:41:54 +0000 (17:41 +0200)
Fixes #2340

wcfsetup/install/files/lib/system/email/transport/SmtpEmailTransport.class.php

index b656d76c73c0b297b25f599c80a7184e1cb4a3e9..e19c2964b98821a2122387879fd1e516451fb0f2 100644 (file)
@@ -211,11 +211,16 @@ class SmtpEmailTransport implements IEmailTransport {
                                if (in_array('starttls', $this->features)) {
                                        try {
                                                $this->starttls();
-                                       }
-                                       catch (SystemException $e) { }
                                        
-                                       $this->write('EHLO '.Email::getHost());
-                                       $this->features = array_map('strtolower', explode("\n", StringUtil::unifyNewlines($this->read([250])[1])));
+                                               $this->write('EHLO '.Email::getHost());
+                                               $this->features = array_map('strtolower', explode("\n", StringUtil::unifyNewlines($this->read([250])[1])));
+                                       }
+                                       catch (\Exception $e) {
+                                               \wcf\functions\exception\logThrowable($e);
+                                               $this->disconnect();
+                                               $this->starttls = 'none';
+                                               $this->connect();
+                                       }
                                }
                        break;
                        case 'none':
@@ -232,8 +237,13 @@ class SmtpEmailTransport implements IEmailTransport {
                $this->write("STARTTLS");
                $this->read([220]);
                
-               if (!$this->connection->setTLS(true)) {
-                       throw new TransientFailure('enabling TLS failed');
+               try {
+                       if (!$this->connection->setTLS(true)) {
+                               throw new TransientFailure('Enabling TLS failed');
+                       }
+               }
+               catch (SystemException $e) {
+                       throw new TransientFailure('Enabling TLS failed', 0, $e);
                }
        }