1
0
mirror of https://github.com/mailcow/mailcow-dockerized.git synced 2024-12-02 09:02:42 +02:00

Fixed issue with subdomain senders + added TO variable and allow new lines in text using \n

This commit is contained in:
bluewalk 2022-11-19 15:32:48 +01:00
parent fd14c51f85
commit d8e314db1a
3 changed files with 21 additions and 16 deletions

View File

@ -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('/(?<name>.*?)<(?<address>.*?)>/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) {

View File

@ -275,7 +275,7 @@
</div>
<div class="col-sm-10">
<p class="help-block">{{ lang.user.pushover_info|format(mailbox)|raw }}</p>
<p class="help-block">{{ lang.edit.pushover_vars|raw }}: <code>{SUBJECT}</code>, <code>{SENDER}</code>, <code>{SENDER_ADDRESS}</code>, <code>{SENDER_NAME}</code></p>
<p class="help-block">{{ lang.edit.pushover_vars|raw }}: <code>{SUBJECT}</code>, <code>{SENDER}</code>, <code>{SENDER_ADDRESS}</code>, <code>{SENDER_NAME}</code>, <code>{TO}</code></p>
<div class="form-group">
<div class="row">
<div class="col-sm-6">

View File

@ -9,7 +9,7 @@
</div>
<div class="col-sm-10">
<p class="help-block">{{ lang.user.pushover_info|format(mailcow_cc_username)|raw }}</p>
<p class="help-block">{{ lang.user.pushover_vars|raw }}: <code>{SUBJECT}</code>, <code>{SENDER}</code>, <code>{SENDER_ADDRESS}</code>, <code>{SENDER_NAME}</code></p>
<p class="help-block">{{ lang.edit.pushover_vars|raw }}: <code>{SUBJECT}</code>, <code>{SENDER}</code>, <code>{SENDER_ADDRESS}</code>, <code>{SENDER_NAME}</code>, <code>{TO}</code></p>
<div class="form-group">
<div class="row">
<div class="col-sm-6">