Skip to content

EspoCRM – Open Source CRM Application

Ref

Yurii910291c0ea3c
diff --git a/application/Espo/Core/Mail/Account/GroupAccount/Service.php b/application/Espo/Core/Mail/Account/GroupAccount/Service.php
index 9c2b14f79c..c11fb6c34b 100644
--- a/application/Espo/Core/Mail/Account/GroupAccount/Service.php
+++ b/application/Espo/Core/Mail/Account/GroupAccount/Service.php
@@ -86,25 +86,21 @@ class Service
*/
public function getFolderList(Params $params): array
{
- if (
- $params->getHost() &&
- !$this->addressUtil->isAllowedAddress($params) &&
- !$this->hostCheck->isHostAndNotInternal($params->getHost())
- ) {
- throw new Forbidden("Not allowed internal host.");
- }
+ $params = $this->connectPreProcess($params);
- if ($params->getId()) {
- $account = $this->accountFactory->create($params->getId());
+ try {
+ $storage = $this->storageFactory->createWithParams($params);
- $params = $params
- ->withPassword($this->getPassword($params, $account))
- ->withImapHandlerClassName($account->getImapHandlerClassName());
- }
+ return $storage->getFolderNames();
+ } catch (Exception $e) {
+ $this->log->warning("IMAP get folder list failed.", [
+ 'exception' => $e,
+ ]);
- $storage = $this->storageFactory->createWithParams($params);
+ $message = $e instanceof ImapError ? $e->getMessage() : '';
- return $storage->getFolderNames();
+ throw new ErrorSilent($message);
+ }
}
/**
@@ -113,21 +109,7 @@ class Service
*/
public function testConnection(Params $params): void
{
- if ($params->getId()) {
- $account = $this->accountFactory->create($params->getId());
-
- $params = $params
- ->withPassword($this->getPassword($params, $account))
- ->withImapHandlerClassName($account->getImapHandlerClassName());
- }
-
- if (
- $params->getHost() &&
- !$this->addressUtil->isAllowedAddress($params) &&
- !$this->hostCheck->isHostAndNotInternal($params->getHost())
- ) {
- throw new Forbidden("Not allowed internal host.");
- }
+ $params = $this->connectPreProcess($params);
try {
$storage = $this->storageFactory->createWithParams($params);
@@ -137,8 +119,7 @@ class Service
'exception' => $e,
]);
- $message = $e instanceof ImapError ?
- $e->getMessage() : '';
+ $message = $e instanceof ImapError ? $e->getMessage() : '';
throw new ErrorSilent($message, previous: $e);
}
@@ -177,4 +158,29 @@ class Service
$storage->appendMessage($message->toString(), $folder);
}
+
+ /**
+ * @throws Error
+ * @throws Forbidden
+ */
+ private function connectPreProcess(Params $params): Params
+ {
+ if (
+ $params->getHost() &&
+ !$this->addressUtil->isAllowedAddress($params) &&
+ !$this->hostCheck->isHostAndNotInternal($params->getHost())
+ ) {
+ throw new Forbidden("Not allowed internal host.");
+ }
+
+ if ($params->getId()) {
+ $account = $this->accountFactory->create($params->getId());
+
+ $params = $params
+ ->withPassword($this->getPassword($params, $account))
+ ->withImapHandlerClassName($account->getImapHandlerClassName());
+ }
+
+ return $params;
+ }
}
diff --git a/application/Espo/Core/Mail/Account/PersonalAccount/Service.php b/application/Espo/Core/Mail/Account/PersonalAccount/Service.php
index 837858a899..b0bdea9701 100644
--- a/application/Espo/Core/Mail/Account/PersonalAccount/Service.php
+++ b/application/Espo/Core/Mail/Account/PersonalAccount/Service.php
@@ -100,8 +100,7 @@ class Service
'exception' => $e,
]);
- $message = $e instanceof ImapError ?
- $e->getMessage() : '';
+ $message = $e instanceof ImapError ? $e->getMessage() : '';
throw new ErrorSilent($message);
}
@@ -124,8 +123,7 @@ class Service
'exception' => $e,
]);
- $message = $e instanceof ImapError ?
- $e->getMessage() : '';
+ $message = $e instanceof ImapError ? $e->getMessage() : '';
throw new ErrorSilent($message);
}
@@ -166,8 +164,6 @@ class Service
}
/**
- * @param Params $params
- * @return Params
* @throws Error
* @throws Forbidden
*/