Skip to content

Commit

Permalink
Fix usage of novalidatecert IMAP/POP3 param; fixes #7693
Browse files Browse the repository at this point in the history
  • Loading branch information
cedric-anne authored and trasher committed Aug 4, 2020
1 parent eea25c2 commit f0e14f1
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 60 deletions.
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -30,7 +30,7 @@
"iamcal/lib_autolink": "^1.7",
"laminas/laminas-cache": "^2.8",
"laminas/laminas-i18n": "^2.10",
"laminas/laminas-mail": "^2.10",
"laminas/laminas-mail": "^2.12",
"laminas/laminas-mime": "^2.7",
"laminas/laminas-serializer": "^2.8",
"mexitek/phpcolors": "^0.4.0",
Expand Down
70 changes: 11 additions & 59 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions inc/auth.class.php
Expand Up @@ -188,6 +188,9 @@ function connection_imap($host, $login, $pass) {
if ($protocol === null) {
throw new \RuntimeException(sprintf(__('Unsupported mail server type:%s.'), $config['type']));
}
if ($config['validate-cert'] === false) {
$protocol->setNoValidateCert(true);
}
$protocol->connect(
$config['address'],
$config['port'],
Expand Down
9 changes: 9 additions & 0 deletions inc/mail/protocol/protocolinterface.class.php
Expand Up @@ -38,6 +38,15 @@

interface ProtocolInterface {

/**
* Do not validate SSL certificate
*
* @param bool $novalidatecert Set to true to disable certificate validation
*
* @return self
*/
public function setNoValidateCert(bool $novalidatecert);

/**
* Open connection to server.
*
Expand Down
4 changes: 4 additions & 0 deletions inc/mailcollector.class.php
Expand Up @@ -1310,6 +1310,10 @@ function connect() {
$params['folder'] = $config['mailbox'];
}

if ($config['validate-cert'] === false) {
$params['novalidatecert'] = true;
}

try {
$storage = Toolbox::getMailServerStorageInstance($config['type'], $params);
if ($storage === null) {
Expand Down
1 change: 1 addition & 0 deletions tests/imap/Toolbox.php
Expand Up @@ -113,6 +113,7 @@ protected function mailServerProtocolsHookProvider() {
// Create valid classes
eval(<<<CLASS
class PluginTesterFakeProtocol implements Glpi\Mail\Protocol\ProtocolInterface {
public function setNoValidateCert(bool \$novalidatecert) {}
public function connect(\$host, \$port = null, \$ssl = false) {}
public function login(\$user, \$password) {}
}
Expand Down

0 comments on commit f0e14f1

Please sign in to comment.