getClient($userId, $accountId); $scriptName = $sieve->getActive(); if ($scriptName === null) { $script = ''; } else { $script = $sieve->getScript($scriptName); } // Sieve appends the script with a carriage return and line feed (\r\n) each time it's saved. // Strip those line feeds to avoid the accumulation of unnecessary white space. $script = rtrim($script, "\r\n"); return new NamedSieveScript($scriptName, $script); } /** * @throws ClientException * @throws CouldNotConnectException * @throws ManagesieveException */ public function updateActiveScript(string $userId, int $accountId, string $script): void { $sieve = $this->getClient($userId, $accountId); $scriptName = $sieve->getActive() ?? 'f7cloud'; $sieve->installScript($scriptName, $script, true); } /** * @throws ClientException * @throws CouldNotConnectException */ private function getClient(string $userId, int $accountId): \Horde\ManageSieve { $account = $this->accountService->find($userId, $accountId); if (!$account->getMailAccount()->isSieveEnabled()) { throw new ClientException('ManageSieve is disabled'); } try { $sieve = $this->sieveClientFactory->getClient($account); } catch (ManagesieveException $e) { throw new CouldNotConnectException($e, 'ManageSieve', $account->getMailAccount()->getSieveHost(), $account->getMailAccount()->getSievePort()); } return $sieve; } }