aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2018-05-04 18:18:58 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2018-05-04 18:18:58 +0100
commitb15c4aa86e35807e89309f0a86d1497499867bb8 (patch)
tree7955cd98ec62a86fb87115f4f15366b2263ef077
parent48b8a405a13ef92007e16ec3aa84d2ae505d2717 (diff)
downloadrspamd-b15c4aa86e35807e89309f0a86d1497499867bb8.tar.gz
rspamd-b15c4aa86e35807e89309f0a86d1497499867bb8.zip
[Feature] Allow to print scores in subject and further extensions
-rw-r--r--src/libserver/protocol.c41
1 files changed, 29 insertions, 12 deletions
diff --git a/src/libserver/protocol.c b/src/libserver/protocol.c
index 83d7afdf8..51b2fa0e5 100644
--- a/src/libserver/protocol.c
+++ b/src/libserver/protocol.c
@@ -789,7 +789,7 @@ rspamd_emails_tree_ucl (GHashTable *input, struct rspamd_task *task)
/* Write new subject */
static const gchar *
-make_rewritten_subject (struct rspamd_task *task)
+rspamd_protocol_rewrite_subject (struct rspamd_task *task)
{
GString *subj_buf;
gchar *res;
@@ -816,19 +816,36 @@ make_rewritten_subject (struct rspamd_task *task)
subj_buf = g_string_sized_new (strlen (c) + slen);
while (*p) {
- if (*p == '%' && *(p + 1) == 's') {
- g_string_append_len (subj_buf, c, p - c);
+ if (*p == '%') {
+ switch (p[1]) {
+ case 's':
+ g_string_append_len (subj_buf, c, p - c);
- if (s) {
- g_string_append_len (subj_buf, s, slen);
+ if (s) {
+ g_string_append_len (subj_buf, s, slen);
+ }
+ c = p + 2;
+ p += 2;
+ break;
+ case 'd':
+ g_string_append_len (subj_buf, c, p - c);
+ rspamd_printf_gstring (subj_buf, "%.2f", task->result->score);
+ c = p + 2;
+ p += 2;
+ break;
+ case '%':
+ g_string_append_len (subj_buf, c, p - c);
+ g_string_append_c (subj_buf, '%');
+ c = p + 2;
+ p += 2;
+ default:
+ p ++; /* Just % something unknown */
+ break;
}
-
- p += 2;
- c = p;
- continue;
}
-
- p ++;
+ else {
+ p++;
+ }
}
if (p > c) {
@@ -936,7 +953,7 @@ rspamd_metric_result_ucl (struct rspamd_task *task,
"action", 0, false);
if (action == METRIC_ACTION_REWRITE_SUBJECT) {
- subject = make_rewritten_subject (task);
+ subject = rspamd_protocol_rewrite_subject (task);
if (subject) {
ucl_object_insert_key (obj, ucl_object_fromstring (subject),