From e82f3b39755d6bc20ebd0fe5c316028bf7b8f1ea Mon Sep 17 00:00:00 2001 From: bluewalk Date: Thu, 17 Nov 2022 14:30:06 +0100 Subject: [PATCH] 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}