From e82f3b39755d6bc20ebd0fe5c316028bf7b8f1ea Mon Sep 17 00:00:00 2001 From: bluewalk Date: Thu, 17 Nov 2022 14:30:06 +0100 Subject: [PATCH 1/6] Added SENDER_ADDRESS and SENDER_NAME as variables for messages --- data/conf/rspamd/local.d/metadata_exporter.conf | 3 +-- data/conf/rspamd/meta_exporter/pushover.php | 11 +++++++++-- data/web/templates/edit/mailbox.twig | 2 +- data/web/templates/user/Pushover.twig | 2 +- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/data/conf/rspamd/local.d/metadata_exporter.conf b/data/conf/rspamd/local.d/metadata_exporter.conf index 47373d99..daaa79b4 100644 --- a/data/conf/rspamd/local.d/metadata_exporter.conf +++ b/data/conf/rspamd/local.d/metadata_exporter.conf @@ -16,8 +16,7 @@ rules { backend = "http"; url = "http://nginx:9081/pushover.php"; selector = "mailcow_rcpt"; - # Only return msgid, do not parse the full message - formatter = "msgid"; + formatter = "json"; meta_headers = true; } } diff --git a/data/conf/rspamd/meta_exporter/pushover.php b/data/conf/rspamd/meta_exporter/pushover.php index a5e83343..974a282d 100644 --- a/data/conf/rspamd/meta_exporter/pushover.php +++ b/data/conf/rspamd/meta_exporter/pushover.php @@ -65,6 +65,13 @@ if (is_array($symbols_array)) { } } +$json = json_decode(file_get_contents('php://input')); + +$sender_address = $json->header_from ; +if (preg_match('/[a-zA-Z0-9.!#$%&’*+\/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)/i', $sender, $matches)) + $sender_address = $matches[0]; +$sender_name = trim(str_replace('<' . $email . '>', '', $from)); + $rcpt_final_mailboxes = array(); // Loop through all rcpts @@ -229,9 +236,9 @@ foreach ($rcpt_final_mailboxes as $rcpt_final) { $post_fields = array( "token" => $api_data['token'], "user" => $api_data['key'], - "title" => sprintf("%s", str_replace(array('{SUBJECT}', '{SENDER}'), array($subject, $sender), $title)), + "title" => sprintf("%s", str_replace(array('{SUBJECT}', '{SENDER}', '{SENDER_NAME}', '{SENDER_ADDRESS}'), array($subject, $sender, $sender_name, $sender_address), $title)), "priority" => $priority, - "message" => sprintf("%s", str_replace(array('{SUBJECT}', '{SENDER}'), array($subject, $sender), $text)) + "message" => sprintf("%s", str_replace(array('{SUBJECT}', '{SENDER}', '{SENDER_NAME}', '{SENDER_ADDRESS}'), array($subject, $sender, $sender_name, $sender_address), $text)) ); if ($attributes['evaluate_x_prio'] == "1" && $priority == 1) { $post_fields['expire'] = 600; diff --git a/data/web/templates/edit/mailbox.twig b/data/web/templates/edit/mailbox.twig index e1c3e883..d4154292 100644 --- a/data/web/templates/edit/mailbox.twig +++ b/data/web/templates/edit/mailbox.twig @@ -275,7 +275,7 @@

{{ lang.user.pushover_info|format(mailbox)|raw }}

-

{{ lang.edit.pushover_vars|raw }}: {SUBJECT}, {SENDER}

+

{{ lang.edit.pushover_vars|raw }}: {SUBJECT}, {SENDER}, {SENDER_ADDRESS}, {SENDER_NAME}

diff --git a/data/web/templates/user/Pushover.twig b/data/web/templates/user/Pushover.twig index 096655cb..8a6755a8 100644 --- a/data/web/templates/user/Pushover.twig +++ b/data/web/templates/user/Pushover.twig @@ -9,7 +9,7 @@

{{ lang.user.pushover_info|format(mailcow_cc_username)|raw }}

-

{{ lang.user.pushover_vars|raw }}: {SUBJECT}, {SENDER}

+

{{ lang.user.pushover_vars|raw }}: {SUBJECT}, {SENDER}, {SENDER_ADDRESS}, {SENDER_NAME}

From 65c74c75c74c1a626b8d8c60921a6dcb689e8f4a Mon Sep 17 00:00:00 2001 From: bluewalk Date: Thu, 17 Nov 2022 14:30:06 +0100 Subject: [PATCH 2/6] Added SENDER_ADDRESS and SENDER_NAME as variables for messages --- data/conf/rspamd/meta_exporter/pushover.php | 11 ++++--- data/web/api/openapi.yaml | 5 ++++ data/web/inc/functions.pushover.inc.php | 4 ++- data/web/inc/init_db.inc.php | 1 + data/web/lang/lang.en-gb.json | 2 ++ data/web/lang/lang.nl-nl.json | 2 ++ data/web/templates/edit/mailbox.twig | 30 +++++++++++++++++++ data/web/templates/user/Pushover.twig | 32 ++++++++++++++++++++- 8 files changed, 81 insertions(+), 6 deletions(-) diff --git a/data/conf/rspamd/meta_exporter/pushover.php b/data/conf/rspamd/meta_exporter/pushover.php index 974a282d..8db4d3d8 100644 --- a/data/conf/rspamd/meta_exporter/pushover.php +++ b/data/conf/rspamd/meta_exporter/pushover.php @@ -67,10 +67,12 @@ if (is_array($symbols_array)) { $json = json_decode(file_get_contents('php://input')); -$sender_address = $json->header_from ; -if (preg_match('/[a-zA-Z0-9.!#$%&’*+\/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)/i', $sender, $matches)) +$sender_address = $json->header_from[0]; +$sender_name = '-'; +if (preg_match('/[a-zA-Z0-9.!#$%&’*+\/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)/i', $sender_address, $matches)) { $sender_address = $matches[0]; -$sender_name = trim(str_replace('<' . $email . '>', '', $from)); + $sender_name = trim(str_replace('<' . $sender_address . '>', '', $json->header_from[0])); +} $rcpt_final_mailboxes = array(); @@ -238,7 +240,8 @@ foreach ($rcpt_final_mailboxes as $rcpt_final) { "user" => $api_data['key'], "title" => sprintf("%s", str_replace(array('{SUBJECT}', '{SENDER}', '{SENDER_NAME}', '{SENDER_ADDRESS}'), array($subject, $sender, $sender_name, $sender_address), $title)), "priority" => $priority, - "message" => sprintf("%s", str_replace(array('{SUBJECT}', '{SENDER}', '{SENDER_NAME}', '{SENDER_ADDRESS}'), array($subject, $sender, $sender_name, $sender_address), $text)) + "message" => sprintf("%s", str_replace(array('{SUBJECT}', '{SENDER}', '{SENDER_NAME}', '{SENDER_ADDRESS}'), array($subject, $sender, $sender_name, $sender_address), $text)), + "sound" => $attributes['sound'] ?? "pushover" ); if ($attributes['evaluate_x_prio'] == "1" && $priority == 1) { $post_fields['expire'] = 600; diff --git a/data/web/api/openapi.yaml b/data/web/api/openapi.yaml index c23380f1..6310aa58 100644 --- a/data/web/api/openapi.yaml +++ b/data/web/api/openapi.yaml @@ -3349,6 +3349,7 @@ paths: evaluate_x_prio: "0" key: 21e8918e1jksdjcpis712 only_x_prio: "0" + sound: "pushover" senders: "" senders_regex: "" text: "" @@ -3392,6 +3393,7 @@ paths: evaluate_x_prio: "0" key: 21e8918e1jksdjcpis712 only_x_prio: "0" + sound: "pushover" senders: "" senders_regex: "" text: "" @@ -3413,6 +3415,9 @@ paths: only_x_prio: description: Only send push for prio mails type: number + sound: + description: Set notification sound + type: string senders: description: Only send push for emails from these senders type: string diff --git a/data/web/inc/functions.pushover.inc.php b/data/web/inc/functions.pushover.inc.php index 74e8bb1c..5393c0d5 100644 --- a/data/web/inc/functions.pushover.inc.php +++ b/data/web/inc/functions.pushover.inc.php @@ -51,6 +51,7 @@ function pushover($_action, $_data = null) { $active = (isset($_data['active'])) ? intval($_data['active']) : $is_now['active']; $evaluate_x_prio = (isset($_data['evaluate_x_prio'])) ? intval($_data['evaluate_x_prio']) : $is_now['evaluate_x_prio']; $only_x_prio = (isset($_data['only_x_prio'])) ? intval($_data['only_x_prio']) : $is_now['only_x_prio']; + $sound = (isset($_data['sound'])) ? $_data['sound'] : $is_now['sound']; } else { $_SESSION['return'][] = array( @@ -101,7 +102,8 @@ function pushover($_action, $_data = null) { $po_attributes = json_encode( array( 'evaluate_x_prio' => strval(intval($evaluate_x_prio)), - 'only_x_prio' => strval(intval($only_x_prio)) + 'only_x_prio' => strval(intval($only_x_prio)), + 'sound' => strval($sound) ) ); $stmt = $pdo->prepare("REPLACE INTO `pushover` (`username`, `key`, `attributes`, `senders_regex`, `senders`, `token`, `title`, `text`, `active`) diff --git a/data/web/inc/init_db.inc.php b/data/web/inc/init_db.inc.php index b47bd5c2..48db1a62 100644 --- a/data/web/inc/init_db.inc.php +++ b/data/web/inc/init_db.inc.php @@ -1264,6 +1264,7 @@ function init_db_schema() { $pdo->query("UPDATE `pushover` SET `attributes` = '{}' WHERE `attributes` = '' OR `attributes` IS NULL;"); $pdo->query("UPDATE `pushover` SET `attributes` = JSON_SET(`attributes`, '$.evaluate_x_prio', \"0\") WHERE JSON_VALUE(`attributes`, '$.evaluate_x_prio') IS NULL;"); $pdo->query("UPDATE `pushover` SET `attributes` = JSON_SET(`attributes`, '$.only_x_prio', \"0\") WHERE JSON_VALUE(`attributes`, '$.only_x_prio') IS NULL;"); + $pdo->query("UPDATE `pushover` SET `attributes` = JSON_SET(`attributes`, '$.sound', \"0\") WHERE JSON_VALUE(`attributes`, '$.sound') IS NULL;"); // mailbox $pdo->query("UPDATE `mailbox` SET `attributes` = '{}' WHERE `attributes` = '' OR `attributes` IS NULL;"); $pdo->query("UPDATE `mailbox` SET `attributes` = JSON_SET(`attributes`, '$.passwd_update', \"0\") WHERE JSON_VALUE(`attributes`, '$.passwd_update') IS NULL;"); diff --git a/data/web/lang/lang.en-gb.json b/data/web/lang/lang.en-gb.json index 0a384071..260997de 100644 --- a/data/web/lang/lang.en-gb.json +++ b/data/web/lang/lang.en-gb.json @@ -574,6 +574,7 @@ "pushover_sender_regex": "Consider the following sender regex", "pushover_text": "Notification text", "pushover_title": "Notification title", + "pushover_sound": "Sound", "pushover_vars": "When no sender filter is defined, all mails will be considered.
Regex filters as well as exact sender checks can be defined individually and will be considered sequentially. They do not depend on each other.
Useable variables for text and title (please take note of data protection policies)", "pushover_verify": "Verify credentials", "quota_mb": "Quota (MiB)", @@ -1097,6 +1098,7 @@ "pushover_sender_regex": "Match senders by the following regex", "pushover_text": "Notification text", "pushover_title": "Notification title", + "pushover_sound": "Sound", "pushover_vars": "When no sender filter is defined, all mails will be considered.
Regex filters as well as exact sender checks can be defined individually and will be considered sequentially. They do not depend on each other.
Useable variables for text and title (please take note of data protection policies)", "pushover_verify": "Verify credentials", "q_add_header": "Junk folder", diff --git a/data/web/lang/lang.nl-nl.json b/data/web/lang/lang.nl-nl.json index ecfee43d..af8e9834 100644 --- a/data/web/lang/lang.nl-nl.json +++ b/data/web/lang/lang.nl-nl.json @@ -536,6 +536,7 @@ "pushover_sender_regex": "Uitsluitend een afzender met de volgende regex", "pushover_text": "Meldingstekst ({SUBJECT} zal worden vervangen door het onderwerp)", "pushover_title": "Meldingstitel", + "pushover_sound": "Geluid", "pushover_vars": "Wanneer er geen afzenders zijn uitgesloten zullen alle mails doorkomen.
Regex-filters en afzendercontroles kunnen individueel worden ingesteld en zullen in volgorde worden verwerkt. Ze zijn niet afhankelijk van elkaar.
Bruikbare variabelen voor tekst en titel (neem het gegevensbeschermingsbeleid in acht)", "pushover_verify": "Verifieer aanmeldingsgegevens", "quota_mb": "Quota (MiB)", @@ -1002,6 +1003,7 @@ "pushover_sender_regex": "Uitsluitend een afzender met de volgende regex", "pushover_text": "Meldingstekst ({SUBJECT} zal worden vervangen door het onderwerp)", "pushover_title": "Meldingstitel", + "pushover_sound": "Geluid", "pushover_vars": "Wanneer er geen afzenders zijn uitgesloten zullen alle mails doorkomen.
Regex-filters en afzendercontroles kunnen individueel worden ingesteld en zullen in volgorde worden verwerkt. Ze zijn niet afhankelijk van elkaar.
Bruikbare variabelen voor tekst en titel (let op het gegevensbeschermingsbeleid)", "pushover_verify": "Verifieer aanmeldingsgegevens", "q_add_header": "Spamfolder", diff --git a/data/web/templates/edit/mailbox.twig b/data/web/templates/edit/mailbox.twig index d4154292..f0154584 100644 --- a/data/web/templates/edit/mailbox.twig +++ b/data/web/templates/edit/mailbox.twig @@ -308,6 +308,36 @@
+
+
+
+ +
+
diff --git a/data/web/templates/user/Pushover.twig b/data/web/templates/user/Pushover.twig index 8a6755a8..a1867a8b 100644 --- a/data/web/templates/user/Pushover.twig +++ b/data/web/templates/user/Pushover.twig @@ -9,7 +9,7 @@

{{ lang.user.pushover_info|format(mailcow_cc_username)|raw }}

-

{{ lang.user.pushover_vars|raw }}: {SUBJECT}, {SENDER}, {SENDER_ADDRESS}, {SENDER_NAME}

+

{{ lang.user.pushover_vars|raw }}: {SUBJECT}, {SENDER}, {SENDER_ADDRESS}, {SENDER_NAME}

@@ -42,6 +42,36 @@
+
+
+
+ +
+
From 57a5a9baeb5758d441fbd6c80a00c9d3c94af153 Mon Sep 17 00:00:00 2001 From: bluewalk Date: Thu, 17 Nov 2022 21:14:44 +0100 Subject: [PATCH 3/6] Updated DB version and make sure default sound is "pushover" when null --- data/web/inc/init_db.inc.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/data/web/inc/init_db.inc.php b/data/web/inc/init_db.inc.php index 48db1a62..9abd4485 100644 --- a/data/web/inc/init_db.inc.php +++ b/data/web/inc/init_db.inc.php @@ -3,7 +3,7 @@ function init_db_schema() { try { global $pdo; - $db_version = "25072022_2300"; + $db_version = "17112022_2115"; $stmt = $pdo->query("SHOW TABLES LIKE 'versions'"); $num_results = count($stmt->fetchAll(PDO::FETCH_ASSOC)); @@ -1264,7 +1264,7 @@ function init_db_schema() { $pdo->query("UPDATE `pushover` SET `attributes` = '{}' WHERE `attributes` = '' OR `attributes` IS NULL;"); $pdo->query("UPDATE `pushover` SET `attributes` = JSON_SET(`attributes`, '$.evaluate_x_prio', \"0\") WHERE JSON_VALUE(`attributes`, '$.evaluate_x_prio') IS NULL;"); $pdo->query("UPDATE `pushover` SET `attributes` = JSON_SET(`attributes`, '$.only_x_prio', \"0\") WHERE JSON_VALUE(`attributes`, '$.only_x_prio') IS NULL;"); - $pdo->query("UPDATE `pushover` SET `attributes` = JSON_SET(`attributes`, '$.sound', \"0\") WHERE JSON_VALUE(`attributes`, '$.sound') IS NULL;"); + $pdo->query("UPDATE `pushover` SET `attributes` = JSON_SET(`attributes`, '$.sound', \"pushover\") WHERE JSON_VALUE(`attributes`, '$.sound') IS NULL;"); // mailbox $pdo->query("UPDATE `mailbox` SET `attributes` = '{}' WHERE `attributes` = '' OR `attributes` IS NULL;"); $pdo->query("UPDATE `mailbox` SET `attributes` = JSON_SET(`attributes`, '$.passwd_update', \"0\") WHERE JSON_VALUE(`attributes`, '$.passwd_update') IS NULL;"); From fd14c51f850beb893624808b468233f874526b84 Mon Sep 17 00:00:00 2001 From: bluewalk Date: Fri, 18 Nov 2022 17:28:10 +0100 Subject: [PATCH 4/6] Removed regex as we have the address from the header --- data/conf/rspamd/meta_exporter/pushover.php | 26 +++++++++------------ 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/data/conf/rspamd/meta_exporter/pushover.php b/data/conf/rspamd/meta_exporter/pushover.php index 8db4d3d8..ffc826a7 100644 --- a/data/conf/rspamd/meta_exporter/pushover.php +++ b/data/conf/rspamd/meta_exporter/pushover.php @@ -48,12 +48,12 @@ if (!function_exists('getallheaders')) { $headers = getallheaders(); -$qid = $headers['X-Rspamd-Qid']; -$rcpts = $headers['X-Rspamd-Rcpt']; -$sender = $headers['X-Rspamd-From']; -$ip = $headers['X-Rspamd-Ip']; -$subject = $headers['X-Rspamd-Subject']; -$priority = 0; +$qid = $headers['X-Rspamd-Qid']; +$rcpts = $headers['X-Rspamd-Rcpt']; +$sender_address = $headers['X-Rspamd-From']; +$ip = $headers['X-Rspamd-Ip']; +$subject = $headers['X-Rspamd-Subject']; +$priority = 0; $symbols_array = json_decode($headers['X-Rspamd-Symbols'], true); if (is_array($symbols_array)) { @@ -67,12 +67,8 @@ if (is_array($symbols_array)) { $json = json_decode(file_get_contents('php://input')); -$sender_address = $json->header_from[0]; -$sender_name = '-'; -if (preg_match('/[a-zA-Z0-9.!#$%&’*+\/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)/i', $sender_address, $matches)) { - $sender_address = $matches[0]; - $sender_name = trim(str_replace('<' . $sender_address . '>', '', $json->header_from[0])); -} +$sender = $json->header_from[0]; +$sender_name = trim(str_replace('<' . $sender_address . '>', '', $sender)); $rcpt_final_mailboxes = array(); @@ -217,18 +213,18 @@ foreach ($rcpt_final_mailboxes as $rcpt_final) { } else { if (!empty($senders)) { - if (in_array($sender, $senders)) { + if (in_array($sender_address, $senders)) { $sender_validated = true; } } if (!empty($senders_regex) && $sender_validated !== true) { - if (preg_match($senders_regex, $sender)) { + if (preg_match($senders_regex, $sender_address)) { $sender_validated = true; } } } if ($sender_validated === false) { - error_log("NOTIFY: pushover pipe: skipping unwanted sender " . $sender); + error_log("NOTIFY: pushover pipe: skipping unwanted sender " . $sender_address); continue; } if ($attributes['only_x_prio'] == "1" && $priority == 0) { From d8e314db1a34ef29996f7575b66df894351685e3 Mon Sep 17 00:00:00 2001 From: bluewalk Date: Sat, 19 Nov 2022 15:32:48 +0100 Subject: [PATCH 5/6] Fixed issue with subdomain senders + added TO variable and allow new lines in text using \n --- data/conf/rspamd/meta_exporter/pushover.php | 33 ++++++++++++--------- data/web/templates/edit/mailbox.twig | 2 +- data/web/templates/user/Pushover.twig | 2 +- 3 files changed, 21 insertions(+), 16 deletions(-) diff --git a/data/conf/rspamd/meta_exporter/pushover.php b/data/conf/rspamd/meta_exporter/pushover.php index ffc826a7..2f2206ea 100644 --- a/data/conf/rspamd/meta_exporter/pushover.php +++ b/data/conf/rspamd/meta_exporter/pushover.php @@ -47,13 +47,15 @@ if (!function_exists('getallheaders')) { } $headers = getallheaders(); +$json_body = json_decode(file_get_contents('php://input')); -$qid = $headers['X-Rspamd-Qid']; -$rcpts = $headers['X-Rspamd-Rcpt']; -$sender_address = $headers['X-Rspamd-From']; -$ip = $headers['X-Rspamd-Ip']; -$subject = $headers['X-Rspamd-Subject']; -$priority = 0; +$qid = $headers['X-Rspamd-Qid']; +$rcpts = $headers['X-Rspamd-Rcpt']; +$sender = $headers['X-Rspamd-From']; +$ip = $headers['X-Rspamd-Ip']; +$subject = $headers['X-Rspamd-Subject']; +$priority = 0; +$to = $json_body->header_to[0]; $symbols_array = json_decode($headers['X-Rspamd-Symbols'], true); if (is_array($symbols_array)) { @@ -65,10 +67,13 @@ if (is_array($symbols_array)) { } } -$json = json_decode(file_get_contents('php://input')); +$sender_address = $json_body->header_from[0]; +$sender_name = '-'; -$sender = $json->header_from[0]; -$sender_name = trim(str_replace('<' . $sender_address . '>', '', $sender)); +if (preg_match('/(?.*?)<(?
.*?)>/i', $sender_address, $matches)) { + $sender_address = $matches['address']; + $sender_name = trim(trim($matches['name']), '"\' '); +} $rcpt_final_mailboxes = array(); @@ -213,18 +218,18 @@ foreach ($rcpt_final_mailboxes as $rcpt_final) { } else { if (!empty($senders)) { - if (in_array($sender_address, $senders)) { + if (in_array($sender, $senders)) { $sender_validated = true; } } if (!empty($senders_regex) && $sender_validated !== true) { - if (preg_match($senders_regex, $sender_address)) { + if (preg_match($senders_regex, $sender)) { $sender_validated = true; } } } if ($sender_validated === false) { - error_log("NOTIFY: pushover pipe: skipping unwanted sender " . $sender_address); + error_log("NOTIFY: pushover pipe: skipping unwanted sender " . $sender); continue; } if ($attributes['only_x_prio'] == "1" && $priority == 0) { @@ -234,9 +239,9 @@ foreach ($rcpt_final_mailboxes as $rcpt_final) { $post_fields = array( "token" => $api_data['token'], "user" => $api_data['key'], - "title" => sprintf("%s", str_replace(array('{SUBJECT}', '{SENDER}', '{SENDER_NAME}', '{SENDER_ADDRESS}'), array($subject, $sender, $sender_name, $sender_address), $title)), + "title" => sprintf("%s", str_replace(array('{SUBJECT}', '{SENDER}', '{SENDER_NAME}', '{SENDER_ADDRESS}', '{TO}'), array($subject, $sender, $sender_name, $sender_address, $to), $title)), "priority" => $priority, - "message" => sprintf("%s", str_replace(array('{SUBJECT}', '{SENDER}', '{SENDER_NAME}', '{SENDER_ADDRESS}'), array($subject, $sender, $sender_name, $sender_address), $text)), + "message" => sprintf("%s", str_replace(array('{SUBJECT}', '{SENDER}', '{SENDER_NAME}', '{SENDER_ADDRESS}', '{TO}', '\n'), array($subject, $sender, $sender_name, $sender_address, $to, PHP_EOL), $text)), "sound" => $attributes['sound'] ?? "pushover" ); if ($attributes['evaluate_x_prio'] == "1" && $priority == 1) { diff --git a/data/web/templates/edit/mailbox.twig b/data/web/templates/edit/mailbox.twig index f0154584..f2e80c96 100644 --- a/data/web/templates/edit/mailbox.twig +++ b/data/web/templates/edit/mailbox.twig @@ -275,7 +275,7 @@

{{ lang.user.pushover_info|format(mailbox)|raw }}

-

{{ lang.edit.pushover_vars|raw }}: {SUBJECT}, {SENDER}, {SENDER_ADDRESS}, {SENDER_NAME}

+

{{ lang.edit.pushover_vars|raw }}: {SUBJECT}, {SENDER}, {SENDER_ADDRESS}, {SENDER_NAME}, {TO}

diff --git a/data/web/templates/user/Pushover.twig b/data/web/templates/user/Pushover.twig index a1867a8b..ea1d2c16 100644 --- a/data/web/templates/user/Pushover.twig +++ b/data/web/templates/user/Pushover.twig @@ -9,7 +9,7 @@

{{ lang.user.pushover_info|format(mailcow_cc_username)|raw }}

-

{{ lang.user.pushover_vars|raw }}: {SUBJECT}, {SENDER}, {SENDER_ADDRESS}, {SENDER_NAME}

+

{{ lang.edit.pushover_vars|raw }}: {SUBJECT}, {SENDER}, {SENDER_ADDRESS}, {SENDER_NAME}, {TO}

From 360bb6f30603f9bf3104e3fdc575159cc7729805 Mon Sep 17 00:00:00 2001 From: bluewalk Date: Sun, 20 Nov 2022 10:42:44 +0100 Subject: [PATCH 6/6] Split name and address for TO-variables --- data/conf/rspamd/meta_exporter/pushover.php | 21 ++++++++++++++++----- data/web/templates/edit/mailbox.twig | 2 +- data/web/templates/user/Pushover.twig | 2 +- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/data/conf/rspamd/meta_exporter/pushover.php b/data/conf/rspamd/meta_exporter/pushover.php index 2f2206ea..4c8092d1 100644 --- a/data/conf/rspamd/meta_exporter/pushover.php +++ b/data/conf/rspamd/meta_exporter/pushover.php @@ -55,7 +55,6 @@ $sender = $headers['X-Rspamd-From']; $ip = $headers['X-Rspamd-Ip']; $subject = $headers['X-Rspamd-Subject']; $priority = 0; -$to = $json_body->header_to[0]; $symbols_array = json_decode($headers['X-Rspamd-Symbols'], true); if (is_array($symbols_array)) { @@ -69,10 +68,16 @@ if (is_array($symbols_array)) { $sender_address = $json_body->header_from[0]; $sender_name = '-'; - if (preg_match('/(?.*?)<(?
.*?)>/i', $sender_address, $matches)) { $sender_address = $matches['address']; - $sender_name = trim(trim($matches['name']), '"\' '); + $sender_name = trim($matches['name'], '"\' '); +} + +$to_address = $json_body->header_to[0]; +$to_name = '-'; +if (preg_match('/(?.*?)<(?
.*?)>/i', $to_address, $matches)) { + $to_address = $matches['address']; + $to_name = trim($matches['name'], '"\' '); } $rcpt_final_mailboxes = array(); @@ -239,9 +244,15 @@ foreach ($rcpt_final_mailboxes as $rcpt_final) { $post_fields = array( "token" => $api_data['token'], "user" => $api_data['key'], - "title" => sprintf("%s", str_replace(array('{SUBJECT}', '{SENDER}', '{SENDER_NAME}', '{SENDER_ADDRESS}', '{TO}'), array($subject, $sender, $sender_name, $sender_address, $to), $title)), + "title" => sprintf("%s", str_replace( + array('{SUBJECT}', '{SENDER}', '{SENDER_NAME}', '{SENDER_ADDRESS}', '{TO_NAME}', '{TO_ADDRESS}'), + array($subject, $sender, $sender_name, $sender_address, $to_name, $to_address), $title) + ), "priority" => $priority, - "message" => sprintf("%s", str_replace(array('{SUBJECT}', '{SENDER}', '{SENDER_NAME}', '{SENDER_ADDRESS}', '{TO}', '\n'), array($subject, $sender, $sender_name, $sender_address, $to, PHP_EOL), $text)), + "message" => sprintf("%s", str_replace( + array('{SUBJECT}', '{SENDER}', '{SENDER_NAME}', '{SENDER_ADDRESS}', '{TO_NAME}', '{TO_ADDRESS}', '\n'), + array($subject, $sender, $sender_name, $sender_address, $to_name, $to_address, PHP_EOL), $text) + ), "sound" => $attributes['sound'] ?? "pushover" ); if ($attributes['evaluate_x_prio'] == "1" && $priority == 1) { diff --git a/data/web/templates/edit/mailbox.twig b/data/web/templates/edit/mailbox.twig index f2e80c96..9eb7c951 100644 --- a/data/web/templates/edit/mailbox.twig +++ b/data/web/templates/edit/mailbox.twig @@ -275,7 +275,7 @@

{{ lang.user.pushover_info|format(mailbox)|raw }}

-

{{ lang.edit.pushover_vars|raw }}: {SUBJECT}, {SENDER}, {SENDER_ADDRESS}, {SENDER_NAME}, {TO}

+

{{ lang.edit.pushover_vars|raw }}: {SUBJECT}, {SENDER}, {SENDER_ADDRESS}, {SENDER_NAME}, {TO_NAME}, {TO_ADDRESS}

diff --git a/data/web/templates/user/Pushover.twig b/data/web/templates/user/Pushover.twig index ea1d2c16..5bd6b1a4 100644 --- a/data/web/templates/user/Pushover.twig +++ b/data/web/templates/user/Pushover.twig @@ -9,7 +9,7 @@

{{ lang.user.pushover_info|format(mailcow_cc_username)|raw }}

-

{{ lang.edit.pushover_vars|raw }}: {SUBJECT}, {SENDER}, {SENDER_ADDRESS}, {SENDER_NAME}, {TO}

+

{{ lang.edit.pushover_vars|raw }}: {SUBJECT}, {SENDER}, {SENDER_ADDRESS}, {SENDER_NAME}, {TO_NAME}, {TO_ADDRESS}