From c37581f43c926e918b68aa16b12b3e6dd3a06195 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Mon, 8 Feb 2021 17:31:22 +0200 Subject: [PATCH] * EPL/mail: support SpamTitan REST API to manage spam, requires an API token --- admin/inc/class.admin_mail.inc.php | 2 +- admin/templates/default/mailaccount.xet | 4 ++++ api/src/Mail/Account.php | 12 ++++++++++++ api/src/Mail/Credentials.php | 8 +++++++- mail/inc/class.mail_ui.inc.php | 26 ++++++++++++++++--------- mail/lang/egw_de.lang | 4 ++-- mail/lang/egw_en.lang | 4 ++-- mail/lang/egw_es-es.lang | 4 ++-- mail/lang/egw_it.lang | 4 ++-- mail/lang/egw_ja.lang | 4 ++-- mail/lang/egw_sk.lang | 4 ++-- mail/lang/egw_sl.lang | 4 ++-- 12 files changed, 55 insertions(+), 25 deletions(-) diff --git a/admin/inc/class.admin_mail.inc.php b/admin/inc/class.admin_mail.inc.php index 9dabbfd094..4325d06eb2 100644 --- a/admin/inc/class.admin_mail.inc.php +++ b/admin/inc/class.admin_mail.inc.php @@ -1362,7 +1362,7 @@ class admin_mail } // If no EPL available, show that in spamtitan blur - $content['spamtitan_blur'] = $GLOBALS['egw_info']['user']['apps']['stylite'] ? '' : lang('SpamTitian integration requires EPL version'); + $content['spamtitan_blur'] = $GLOBALS['egw_info']['user']['apps']['stylite'] ? '' : lang('SpamTitan integration requires EPL version'); $tpl->exec(static::APP_CLASS.'edit', $content, $sel_options, $readonlys, $content, 2); } diff --git a/admin/templates/default/mailaccount.xet b/admin/templates/default/mailaccount.xet index 2a3f895b37..79e20d5923 100644 --- a/admin/templates/default/mailaccount.xet +++ b/admin/templates/default/mailaccount.xet @@ -234,6 +234,10 @@ + + + + diff --git a/api/src/Mail/Account.php b/api/src/Mail/Account.php index 79362af6f6..1bad097340 100644 --- a/api/src/Mail/Account.php +++ b/api/src/Mail/Account.php @@ -1274,6 +1274,18 @@ class Account implements \ArrayAccess Credentials::delete($data['acc_id'], 0, Credentials::ADMIN); } + // store or delete SpamTitan credentials + if ($data['acc_spam_api'] && $data['acc_spam_password']) + { + Credentials::write($data['acc_id'], $data['acc_spam_api'], + $data['acc_spam_password'], Credentials::SPAMTITAN, 0, + $data['acc_spam_cred_id']); + } + else + { + Credentials::delete($data['acc_id'], 0, Credentials::SPAMTITAN); + } + // store notification folders Notifications::write($data['acc_id'], $data['notify_save_default'] ? 0 : ($data['called_for'] ? $data['called_for'] : $GLOBALS['egw_info']['user']['account_id']), diff --git a/api/src/Mail/Credentials.php b/api/src/Mail/Credentials.php index 8b3e25deb3..b551293087 100644 --- a/api/src/Mail/Credentials.php +++ b/api/src/Mail/Credentials.php @@ -74,10 +74,15 @@ class Credentials */ const COLLABORA = 64; + /** + * SpamTitan API Token + */ + const SPAMTITAN = 128; + /** * All credentials */ - const ALL = self::IMAP|self::SMTP|self::ADMIN|self::SMIME|self::TWOFA; + const ALL = self::IMAP|self::SMTP|self::ADMIN|self::SMIME|self::TWOFA|self::SPAMTITAN; /** * Password in cleartext @@ -126,6 +131,7 @@ class Credentials self::ADMIN => 'acc_imap_admin_', self::SMIME => 'acc_smime_', self::TWOFA => '2fa_', + self::SPAMTITAN => 'acc_spam_', ); /** diff --git a/mail/inc/class.mail_ui.inc.php b/mail/inc/class.mail_ui.inc.php index 0d32b33b43..49900a7367 100644 --- a/mail/inc/class.mail_ui.inc.php +++ b/mail/inc/class.mail_ui.inc.php @@ -984,11 +984,23 @@ class mail_ui } if ($GLOBALS['egw_info']['apps']['stylite'] && $this->mail_bo->icServer->acc_spam_api) { - stylite_mail_spamtitan::setActionItems($_action, $_items, array( + if (strpos($user=$this->mail_bo->icServer->acc_imap_username, '@') === false) + { + if (!empty($this->mail_bo->icServer->acc_domain)) + { + $user .= '@'.$this->mail_bo->icServer->acc_domain; + } + else + { + $user = $this->mail_bo->icServer->ident_email; + } + } + stylite_mail_spamtitan::setActionItems($_action, $_items, $auth=[ + 'user' => $user, 'userpwd' => $this->mail_bo->icServer->acc_imap_password, - 'user' => $this->mail_bo->icServer->acc_imap_username, - 'api_url' => $this->mail_bo->icServer->acc_spam_api - )); + 'api_url' => $this->mail_bo->icServer->acc_spam_api, + 'api_token' => $this->mail_bo->icServer->acc_spam_password, + ]); // sync aliases to SpamTitan when the first spam action in a session is used if (Api\Mail\Account::read($this->mail_bo->profileID)->acc_smtp_type !== 'EGroupware\\Api\\Mail\\Smtp' && @@ -996,11 +1008,7 @@ class mail_ui { $data = Api\Mail\Account::read($this->mail_bo->profileID)->smtpServer()->getUserData($GLOBALS['egw_info']['user']['account_id']); if (($m = stylite_mail_spamtitan::setActionItems('sync_aliases', - array(array_merge((array)$data['mailLocalAddress'], (array)$data['mailAlternateAddress'])), array( - 'userpwd' => $this->mail_bo->icServer->acc_imap_password, - 'user' => $this->mail_bo->icServer->acc_imap_username, - 'api_url' => $this->mail_bo->icServer->acc_spam_api - )))) + array(array_merge((array)$data['mailLocalAddress'], (array)$data['mailAlternateAddress'])), $auth))) { $msg[] = $m; } diff --git a/mail/lang/egw_de.lang b/mail/lang/egw_de.lang index dd1759c158..7341174cc4 100644 --- a/mail/lang/egw_de.lang +++ b/mail/lang/egw_de.lang @@ -579,8 +579,8 @@ some clients fail to detect correct charset, if flowed lines are enabled. mail d sort order mail de Sortierreihenfolge source mail de Quelltext sources mail de HTML-Quellcode -spamtitian api url mail de SpamTitian API URL -spamtitian integration requires epl version mail de SpamTitian-Integration benötigt die EPL Version +spamtitan api url mail de SpamTitan API URL +spamtitan integration requires epl version mail de SpamTitan-Integration benötigt die EPL Version start new messages with mime type plain/text or html? mail de Sollen neue E-Mails als plain/text oder HTML Nachrichten verfasst werden? start reply messages with mime type plain/text or html or try to use the displayed format (default)? mail de Antworten auf und Inline-Weiterleiten von E-Mails im Text-, im HTML-Format oder entsprechend des Formats, in dem die E-Mail vom Sender ursprünglich verfasst wurde. step 1: imap - incoming mail mail de 1. Schritt: Posteingang (IMAP) einrichten diff --git a/mail/lang/egw_en.lang b/mail/lang/egw_en.lang index 28bee35f63..f7ed9b9902 100644 --- a/mail/lang/egw_en.lang +++ b/mail/lang/egw_en.lang @@ -579,8 +579,8 @@ some clients fail to detect correct charset, if flowed lines are enabled. mail e sort order mail en Sort order source mail en Source sources mail en Sources -spamtitian api url mail en SpamTitian API URL -spamtitian integration requires epl version mail en SpamTitian integration requires EPL version +spamtitan api url mail en SpamTitan API URL +spamtitan integration requires epl version mail en SpamTitan integration requires EPL version start new messages with mime type plain/text or html? mail en start new messages with MIME-type plain/text or HTML? start reply messages with mime type plain/text or html or try to use the displayed format (default)? mail en start reply messages with MIME-type plain/text or HTML or try to use the displayed format (default)? step 1: imap - incoming mail mail en Step 1: IMAP - incoming mail diff --git a/mail/lang/egw_es-es.lang b/mail/lang/egw_es-es.lang index 48ea0e0b67..52cc9b903d 100644 --- a/mail/lang/egw_es-es.lang +++ b/mail/lang/egw_es-es.lang @@ -483,8 +483,8 @@ some clients fail to detect correct charset, if flowed lines are enabled. mail e sort order mail es-es Orden en la página source mail es-es Fuente sources mail es-es Fuentes -spamtitian api url mail es-es URL del API SpamTitian -spamtitian integration requires epl version mail es-es La integración de SpamTitan requiere la versión EPL +spamtitan api url mail es-es URL del API SpamTitan +spamtitan integration requires epl version mail es-es La integración de SpamTitan requiere la versión EPL start new messages with mime type plain/text or html? mail es-es ¿Comenzar nuevos mensajes con el tipo MIME plain/text o html? step 1: imap - incoming mail mail es-es Paso 1: IMAP - correo entrante step 2: folder mail es-es Paso 2: Carpeta diff --git a/mail/lang/egw_it.lang b/mail/lang/egw_it.lang index 33c8ed8b91..881e0879ff 100644 --- a/mail/lang/egw_it.lang +++ b/mail/lang/egw_it.lang @@ -521,8 +521,8 @@ some clients fail to detect correct charset, if flowed lines are enabled. mail i sort order mail it Ordinamento source mail it Sorgente sources mail it Sorgenti -spamtitian api url mail it URL della API di spamTitan -spamtitian integration requires epl version mail it L'integrazione di spamTitan richiede la versione EPL +spamtitan api url mail it URL della API di spamTitan +spamtitan integration requires epl version mail it L'integrazione di spamTitan richiede la versione EPL start new messages with mime type plain/text or html? mail it Iniziare nuovi messaggi con mime type plain/test o HTML start reply messages with mime type plain/text or html or try to use the displayed format (default)? mail it Iniziare i messaggi di risposta con mime type plain/text oppure provare a usare il formato mostrato (predefinito)? step 1: imap - incoming mail mail it Primo passo: IMAP - posta in arrivo diff --git a/mail/lang/egw_ja.lang b/mail/lang/egw_ja.lang index 67b1dc1217..ef0b4e90a3 100644 --- a/mail/lang/egw_ja.lang +++ b/mail/lang/egw_ja.lang @@ -539,8 +539,8 @@ some clients fail to detect correct charset, if flowed lines are enabled. mail j sort order mail ja ソート順 source mail ja メールのソース sources mail ja メールのソース -spamtitian api url mail ja SpamTitian API URL -spamtitian integration requires epl version mail ja SpamTitian を利用するには EPL 版が必要 +spamtitan api url mail ja SpamTitan API URL +spamtitan integration requires epl version mail ja SpamTitan を利用するには EPL 版が必要 start new messages with mime type plain/text or html? mail ja 新規メッセージを plain/text で作成しますか?HTMLで作成しますか? start reply messages with mime type plain/text or html or try to use the displayed format (default)? mail ja 返信を plain/text で作成しますか?HTMLで作成しますか?表示中の形式を使用しますか(既定)? step 1: imap - incoming mail mail ja ステップ 1: IMAP - 受信メール diff --git a/mail/lang/egw_sk.lang b/mail/lang/egw_sk.lang index 0f01981b6b..f2595e9fc3 100644 --- a/mail/lang/egw_sk.lang +++ b/mail/lang/egw_sk.lang @@ -541,8 +541,8 @@ some clients fail to detect correct charset, if flowed lines are enabled. mail s sort order mail sk Usporiadať podľa source mail sk Zdroj sources mail sk Zdroje -spamtitian api url mail sk SpamTitan API URL -spamtitian integration requires epl version mail sk Integrácia so SpamTitan vyžaduje verziu EPL +spamtitan api url mail sk SpamTitan API URL +spamtitan integration requires epl version mail sk Integrácia so SpamTitan vyžaduje verziu EPL start new messages with mime type plain/text or html? mail sk Vytvárať nové správy pomocou mime typu čistý text, alebo HTML? start reply messages with mime type plain/text or html or try to use the displayed format (default)? mail sk Začínať odpovedacie správy mime typom čistý text alebo html alebo skúsiť použiť zobrazený formát (predvolené)? step 1: imap - incoming mail mail sk Krok 1: IMAP - prijatá pošta diff --git a/mail/lang/egw_sl.lang b/mail/lang/egw_sl.lang index 4c12858016..b92dd1bf3b 100644 --- a/mail/lang/egw_sl.lang +++ b/mail/lang/egw_sl.lang @@ -565,8 +565,8 @@ some clients fail to detect correct charset, if flowed lines are enabled. mail s sort order mail sl Način sortiranja source mail sl Vir sources mail sl Viri -spamtitian api url mail sl URL za SpamTitian API -spamtitian integration requires epl version mail sl Integracija SpamTitian zahteva različico EPL +spamtitan api url mail sl URL za SpamTitan API +spamtitan integration requires epl version mail sl Integracija SpamTitan zahteva različico EPL start new messages with mime type plain/text or html? mail sl Začnem novo sporočilo kot navadno besedilo ali kot HTML? start reply messages with mime type plain/text or html or try to use the displayed format (default)? mail sl začnite odgovarjati s sporočilom mime type plain / text ali html ali poskusite uporabiti prikazano obliko (privzeto)? step 1: imap - incoming mail mail sl Korak 1: IMAP - prihajajoča pošta