Merge pull request #5612 from mailcow/feat/domain-wide-footer
[Rspamd] add option to skip domain wide footer on reply e-mails
This commit is contained in:
		
						commit
						89540aec28
					
				| @ -49,13 +49,14 @@ $from = $headers['From']; | |||||||
| $empty_footer = json_encode(array( | $empty_footer = json_encode(array( | ||||||
|   'html' => '', |   'html' => '', | ||||||
|   'plain' => '', |   'plain' => '', | ||||||
|  |   'skip_replies' => 0, | ||||||
|   'vars' => array() |   'vars' => array() | ||||||
| )); | )); | ||||||
| 
 | 
 | ||||||
| error_log("FOOTER: checking for domain " . $domain . ", user " . $username . " and address " . $from . PHP_EOL); | error_log("FOOTER: checking for domain " . $domain . ", user " . $username . " and address " . $from . PHP_EOL); | ||||||
| 
 | 
 | ||||||
| try { | try { | ||||||
|   $stmt = $pdo->prepare("SELECT `plain`, `html`, `mbox_exclude` FROM `domain_wide_footer` 
 |   $stmt = $pdo->prepare("SELECT `plain`, `html`, `mbox_exclude`, `skip_replies` FROM `domain_wide_footer` 
 | ||||||
|     WHERE `domain` = :domain");
 |     WHERE `domain` = :domain");
 | ||||||
|   $stmt->execute(array( |   $stmt->execute(array( | ||||||
|     ':domain' => $domain |     ':domain' => $domain | ||||||
|  | |||||||
| @ -567,6 +567,14 @@ rspamd_config:register_symbol({ | |||||||
|           if footer and type(footer) == "table" and (footer.html and footer.html ~= "" or footer.plain and footer.plain ~= "")  then |           if footer and type(footer) == "table" and (footer.html and footer.html ~= "" or footer.plain and footer.plain ~= "")  then | ||||||
|             rspamd_logger.infox(rspamd_config, "found domain wide footer for user %s: html=%s, plain=%s, vars=%s", uname, footer.html, footer.plain, footer.vars) |             rspamd_logger.infox(rspamd_config, "found domain wide footer for user %s: html=%s, plain=%s, vars=%s", uname, footer.html, footer.plain, footer.vars) | ||||||
| 
 | 
 | ||||||
|  |             if footer.skip_replies then | ||||||
|  |               in_reply_to = task:get_header_raw('in-reply-to') | ||||||
|  |               if in_reply_to then | ||||||
|  |                 rspamd_logger.infox(rspamd_config, "mail is a reply - skip footer") | ||||||
|  |                 return | ||||||
|  |               end | ||||||
|  |             end | ||||||
|  | 
 | ||||||
|             local envfrom_mime = task:get_from(2) |             local envfrom_mime = task:get_from(2) | ||||||
|             local from_name = "" |             local from_name = "" | ||||||
|             if envfrom_mime and envfrom_mime[1].name then |             if envfrom_mime and envfrom_mime[1].name then | ||||||
|  | |||||||
| @ -3411,6 +3411,7 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) { | |||||||
|           $footers = array(); |           $footers = array(); | ||||||
|           $footers['html'] = isset($_data['html']) ? $_data['html'] : ''; |           $footers['html'] = isset($_data['html']) ? $_data['html'] : ''; | ||||||
|           $footers['plain'] = isset($_data['plain']) ? $_data['plain'] : ''; |           $footers['plain'] = isset($_data['plain']) ? $_data['plain'] : ''; | ||||||
|  |           $footers['skip_replies'] = isset($_data['skip_replies']) ? (int)$_data['skip_replies'] : 0; | ||||||
|           $footers['mbox_exclude'] = array(); |           $footers['mbox_exclude'] = array(); | ||||||
|           if (isset($_data["mbox_exclude"])){ |           if (isset($_data["mbox_exclude"])){ | ||||||
|             if (!is_array($_data["mbox_exclude"])) { |             if (!is_array($_data["mbox_exclude"])) { | ||||||
| @ -3460,12 +3461,13 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) { | |||||||
|             try { |             try { | ||||||
|               $stmt = $pdo->prepare("DELETE FROM `domain_wide_footer` WHERE `domain`= :domain"); |               $stmt = $pdo->prepare("DELETE FROM `domain_wide_footer` WHERE `domain`= :domain"); | ||||||
|               $stmt->execute(array(':domain' => $domain)); |               $stmt->execute(array(':domain' => $domain)); | ||||||
|               $stmt = $pdo->prepare("INSERT INTO `domain_wide_footer` (`domain`, `html`, `plain`, `mbox_exclude`) VALUES (:domain, :html, :plain, :mbox_exclude)"); |               $stmt = $pdo->prepare("INSERT INTO `domain_wide_footer` (`domain`, `html`, `plain`, `mbox_exclude`, `skip_replies`) VALUES (:domain, :html, :plain, :mbox_exclude, :skip_replies)"); | ||||||
|               $stmt->execute(array( |               $stmt->execute(array( | ||||||
|                 ':domain' => $domain, |                 ':domain' => $domain, | ||||||
|                 ':html' => $footers['html'], |                 ':html' => $footers['html'], | ||||||
|                 ':plain' => $footers['plain'], |                 ':plain' => $footers['plain'], | ||||||
|                 ':mbox_exclude' => json_encode($footers['mbox_exclude']), |                 ':mbox_exclude' => json_encode($footers['mbox_exclude']), | ||||||
|  |                 ':skip_replies' => $footers['skip_replies'], | ||||||
|               )); |               )); | ||||||
|             } |             } | ||||||
|             catch (PDOException $e) { |             catch (PDOException $e) { | ||||||
| @ -4622,7 +4624,7 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) { | |||||||
|           } |           } | ||||||
| 
 | 
 | ||||||
|           try { |           try { | ||||||
|             $stmt = $pdo->prepare("SELECT `html`, `plain`, `mbox_exclude` FROM `domain_wide_footer`
 |             $stmt = $pdo->prepare("SELECT `html`, `plain`, `mbox_exclude`, `skip_replies` FROM `domain_wide_footer`
 | ||||||
|               WHERE `domain` = :domain");
 |               WHERE `domain` = :domain");
 | ||||||
|             $stmt->execute(array( |             $stmt->execute(array( | ||||||
|               ':domain' => $domain |               ':domain' => $domain | ||||||
|  | |||||||
| @ -3,7 +3,7 @@ function init_db_schema() { | |||||||
|   try { |   try { | ||||||
|     global $pdo; |     global $pdo; | ||||||
| 
 | 
 | ||||||
|     $db_version = "21112023_1644"; |     $db_version = "08012024_1442"; | ||||||
| 
 | 
 | ||||||
|     $stmt = $pdo->query("SHOW TABLES LIKE 'versions'"); |     $stmt = $pdo->query("SHOW TABLES LIKE 'versions'"); | ||||||
|     $num_results = count($stmt->fetchAll(PDO::FETCH_ASSOC)); |     $num_results = count($stmt->fetchAll(PDO::FETCH_ASSOC)); | ||||||
| @ -273,6 +273,7 @@ function init_db_schema() { | |||||||
|           "html" => "LONGTEXT", |           "html" => "LONGTEXT", | ||||||
|           "plain" => "LONGTEXT", |           "plain" => "LONGTEXT", | ||||||
|           "mbox_exclude" => "JSON NOT NULL DEFAULT ('[]')", |           "mbox_exclude" => "JSON NOT NULL DEFAULT ('[]')", | ||||||
|  |           "skip_replies" => "TINYINT(1) NOT NULL DEFAULT '0'" | ||||||
|         ), |         ), | ||||||
|         "keys" => array( |         "keys" => array( | ||||||
|           "primary" => array( |           "primary" => array( | ||||||
|  | |||||||
| @ -588,10 +588,19 @@ | |||||||
|         "disable_login": "Login verbieten (Mails werden weiterhin angenommen)", |         "disable_login": "Login verbieten (Mails werden weiterhin angenommen)", | ||||||
|         "domain": "Domain bearbeiten", |         "domain": "Domain bearbeiten", | ||||||
|         "domain_admin": "Domain-Administrator bearbeiten", |         "domain_admin": "Domain-Administrator bearbeiten", | ||||||
|         "domain_footer": "Domain wide footer", |         "domain_footer": "Domänenweite Fußzeile", | ||||||
|         "domain_footer_html": "HTML footer", |         "domain_footer_html": "Fußzeile im HTML Format", | ||||||
|         "domain_footer_info": "Domain wide footer werden allen ausgehenden E-Mails hinzugefügt, die einer Adresse innerhalb dieser Domain gehört.<br>Die folgenden Variablen können für den Footer benutzt werden:", |         "domain_footer_info": "Domänenweite Footer (Domain wide footer) werden allen ausgehenden E-Mails hinzugefügt, die einer Adresse innerhalb dieser Domain gehört.<br>Die folgenden Variablen können für die Fußzeile benutzt werden:", | ||||||
|         "domain_footer_plain": "PLAIN footer", |         "domain_footer_info_vars": { | ||||||
|  |             "auth_user": "{= auth_user =}   - Angemeldeter Benutzername vom MTA", | ||||||
|  |             "from_user": "{= from_user =}   - Absender Teil der E-Mail z.B. für \"moo@mailcow.tld\" wird \"moo\" zurückgeben.", | ||||||
|  |             "from_name": "{= from_name =}   - Namen des Absenders z.B. für \"Mailcow <moo@mailcow.tld>\", wird \"Mailcow\" zurückgegeben.", | ||||||
|  |             "from_addr": "{= from_addr =}   - Adresse des Absenders.", | ||||||
|  |             "from_domain": "{= from_domain =} - Domain des Absenders", | ||||||
|  |             "custom": "{= foo =}         - Wenn die Mailbox das benutzerdefinierte Attribut \"foo\" mit dem Wert \"bar\" hat, wird \"bar\" zurückgegeben." | ||||||
|  |         }, | ||||||
|  |         "domain_footer_plain": "Fußzeile im PLAIN Format", | ||||||
|  |         "domain_footer_skip_replies": "Ignoriere Footer bei Antwort E-Mails", | ||||||
|         "domain_quota": "Domain Speicherplatz gesamt (MiB)", |         "domain_quota": "Domain Speicherplatz gesamt (MiB)", | ||||||
|         "domains": "Domains", |         "domains": "Domains", | ||||||
|         "dont_check_sender_acl": "Absender für Domain %s u. Alias-Domain nicht prüfen", |         "dont_check_sender_acl": "Absender für Domain %s u. Alias-Domain nicht prüfen", | ||||||
| @ -680,11 +689,7 @@ | |||||||
|         "unchanged_if_empty": "Unverändert, wenn leer", |         "unchanged_if_empty": "Unverändert, wenn leer", | ||||||
|         "username": "Benutzername", |         "username": "Benutzername", | ||||||
|         "validate_save": "Validieren und speichern", |         "validate_save": "Validieren und speichern", | ||||||
|         "pushover_sound": "Ton", |         "pushover_sound": "Ton" | ||||||
|         "domain_footer_info_vars": { |  | ||||||
|             "auth_user": "{= auth_user =}   - Angemeldeter Benutzername vom MTA", |  | ||||||
|             "from_user": "{= from_user =}   - Von Teil des Benutzers z.B. \"moo@mailcow.tld\" wird \"moo\" zurückgeben." |  | ||||||
|         } |  | ||||||
|     }, |     }, | ||||||
|     "fido2": { |     "fido2": { | ||||||
|         "confirm": "Bestätigen", |         "confirm": "Bestätigen", | ||||||
|  | |||||||
| @ -600,6 +600,7 @@ | |||||||
|             "custom": "{= foo =}         - If mailbox has the custom attribute \"foo\" with value \"bar\" it returns \"bar\"" |             "custom": "{= foo =}         - If mailbox has the custom attribute \"foo\" with value \"bar\" it returns \"bar\"" | ||||||
|         }, |         }, | ||||||
|         "domain_footer_plain": "PLAIN footer", |         "domain_footer_plain": "PLAIN footer", | ||||||
|  |         "domain_footer_skip_replies": "Ignore footer on reply e-mails", | ||||||
|         "domain_quota": "Domain quota", |         "domain_quota": "Domain quota", | ||||||
|         "domains": "Domains", |         "domains": "Domains", | ||||||
|         "dont_check_sender_acl": "Disable sender check for domain %s (+ alias domains)", |         "dont_check_sender_acl": "Disable sender check for domain %s (+ alias domains)", | ||||||
|  | |||||||
| @ -305,6 +305,14 @@ | |||||||
|                           </select> |                           </select> | ||||||
|                         </div> |                         </div> | ||||||
|                       </div> |                       </div> | ||||||
|  |                       <div class="row mb-4"> | ||||||
|  |                         <label class="control-label col-sm-2" for="domain_footer_skip_replies">{{ lang.edit.domain_footer_skip_replies }}:</label> | ||||||
|  |                         <div class="col-sm-10"> | ||||||
|  |                           <div class="form-check"> | ||||||
|  |                             <label><input type="checkbox" class="form-check-input" value="1" id="domain_footer_skip_replies" name="skip_replies"{% if domain_footer.skip_replies == '1' %} checked{% endif %}></label> | ||||||
|  |                           </div> | ||||||
|  |                         </div> | ||||||
|  |                       </div> | ||||||
|                       <div class="row mb-2"> |                       <div class="row mb-2"> | ||||||
|                         <label class="control-label col-sm-2" for="domain_footer_html">{{ lang.edit.domain_footer_html }}:</label> |                         <label class="control-label col-sm-2" for="domain_footer_html">{{ lang.edit.domain_footer_html }}:</label> | ||||||
|                         <div class="col-sm-10"> |                         <div class="col-sm-10"> | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 Niklas Meyer
						Niklas Meyer