[Rspamd] More pushover options
This commit is contained in:
@@ -51,8 +51,20 @@ $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;
|
||||
|
||||
$symbols_array = json_decode($headers['X-Rspamd-Symbols'], true);
|
||||
if (is_array($symbols_array)) {
|
||||
foreach ($symbols_array as $symbol) {
|
||||
if ($symbol['name'] == 'HAS_X_PRIO_ONE') {
|
||||
$priority = 2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$rcpt_final_mailboxes = array();
|
||||
|
||||
@@ -177,7 +189,7 @@ foreach (json_decode($rcpts, true) as $rcpt) {
|
||||
|
||||
|
||||
foreach ($rcpt_final_mailboxes as $rcpt_final) {
|
||||
error_log("NOTIFY: pushover pipe: processing pushover message for rcpt " . $rcpt_final . PHP_EOL);
|
||||
error_log("NOTIFY: pushover pipe: processing pushover message for rcpt " . $rcpt_final . " with priority " . $priority . PHP_EOL);
|
||||
$stmt = $pdo->prepare("SELECT * FROM `pushover`
|
||||
WHERE `username` = :username AND `active` = '1'");
|
||||
$stmt->execute(array(
|
||||
@@ -187,14 +199,30 @@ foreach ($rcpt_final_mailboxes as $rcpt_final) {
|
||||
if (isset($api_data['key']) && isset($api_data['token'])) {
|
||||
$title = (!empty($api_data['title'])) ? $api_data['title'] : 'Mail';
|
||||
$text = (!empty($api_data['text'])) ? $api_data['text'] : 'You\'ve got mail 📧';
|
||||
$attributes = json_decode($api_data['attributes'], true);
|
||||
$senders = explode(',', $api_data['senders']);
|
||||
if (!empty($senders) && !in_array($sender, $senders)) {
|
||||
error_log("NOTIFY: pushover pipe: skipping unwanted sender " . $sender);
|
||||
continue;
|
||||
}
|
||||
if ($attributes['only_x_prio'] == "1" && $priority == 0) {
|
||||
error_log("NOTIFY: pushover pipe: mail has no X-Priority: 1 header, skipping");
|
||||
continue;
|
||||
}
|
||||
$post_fields = array(
|
||||
"token" => $api_data['token'],
|
||||
"user" => $api_data['key'],
|
||||
"title" => sprintf("%s", str_replace(array('{SUBJECT}', '{SENDER}'), array($subject, $sender), $title)),
|
||||
"priority" => $priority,
|
||||
"message" => sprintf("%s", str_replace(array('{SUBJECT}', '{SENDER}'), array($subject, $sender), $text))
|
||||
);
|
||||
if ($attributes['evaluate_x_prio'] == "1" && $priority == 2) {
|
||||
$post_fields['expire'] = 600;
|
||||
$post_fields['retry'] = 120;
|
||||
}
|
||||
curl_setopt_array($ch = curl_init(), array(
|
||||
CURLOPT_URL => "https://api.pushover.net/1/messages.json",
|
||||
CURLOPT_POSTFIELDS => array(
|
||||
"token" => $api_data['token'],
|
||||
"user" => $api_data['key'],
|
||||
"title" => $title,
|
||||
"message" => sprintf("%s", str_replace('{SUBJECT}', $subject, $text))
|
||||
),
|
||||
CURLOPT_POSTFIELDS => $post_fields,
|
||||
CURLOPT_SAFE_UPLOAD => true,
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
));
|
||||
|
Reference in New Issue
Block a user