From 36e13ce62862b6dd4fd1edb70d745f7c6f3fe9b8 Mon Sep 17 00:00:00 2001 From: Sophie Herold Date: Sat, 11 Apr 2020 13:55:44 +0200 Subject: [PATCH] Default to STARTTLS --- lib/imap.php | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/imap.php b/lib/imap.php index da6089d..2b8897d 100644 --- a/lib/imap.php +++ b/lib/imap.php @@ -85,12 +85,19 @@ public function checkPassword($uid, $password) { $groups[] = $pieces[1]; } - $protocol = ($this->sslmode === "ssl") ? "imaps" : "imap"; - $url = "{$protocol}://{$this->mailbox}:{$this->port}"; $ch = curl_init(); - if ($this->sslmode === 'tls') { - curl_setopt($ch, CURLOPT_USE_SSL, CURLUSESSL_ALL); + + if ($this->sslmode !== 'tls') { + $protocol = 'imaps'; + // Use STARTTLS as default encryption mode + if ($this->sslmode) { + curl_setopt($ch, CURLOPT_USE_SSL, CURLUSESSL_ALL); + } + } else { + $protocol = 'imaps'; } + + $url = "{$protocol}://{$this->mailbox}:{$this->port}"; curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_USERPWD, $username.":".$password);