diff options
author | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2011-05-10 22:52:01 +0400 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2011-05-10 22:52:01 +0400 |
commit | bc953ee7602b6a4278fc5c13a83ad570444f5cc6 (patch) | |
tree | d5f2c84460ffb9b838baccd5a315bfad04832d0f /src/protocol.c | |
parent | c29b6dc179123cdb7b47cb12b6c3bd7a2d053994 (diff) | |
download | rspamd-bc953ee7602b6a4278fc5c13a83ad570444f5cc6.tar.gz rspamd-bc953ee7602b6a4278fc5c13a83ad570444f5cc6.zip |
* Add Subject header that indicate how Subject must be rewritten in case of 'rewrite subject' action
Fix initialization order of json settings.
Diffstat (limited to 'src/protocol.c')
-rw-r--r-- | src/protocol.c | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/protocol.c b/src/protocol.c index ac8515004..4d6507652 100644 --- a/src/protocol.c +++ b/src/protocol.c @@ -909,6 +909,39 @@ show_metric_symbols_json (struct metric_result *metric_res, struct metric_callba return cd->alive; } +/* Write new subject */ +static const gchar * +make_rewritten_subject (struct metric *metric, struct worker_task *task) +{ + static gchar subj_buf[1024]; + gchar *p = subj_buf, *end, *c, *res; + const gchar *s; + + end = p + sizeof(subj_buf); + c = metric->subject; + s = g_mime_message_get_subject (task->message); + + while (p < end) { + if (*c == '\0') { + *p = '\0'; + break; + } + else if (*c == '%' && *(c + 1) == 's') { + p += rspamd_strlcpy (p, (s != NULL) ? s : "", end - p); + c += 2; + } + else { + *p = *c ++; + } + p ++; + } + res = g_mime_utils_header_encode_text (subj_buf); + + memory_pool_add_destructor (task->task_pool, (pool_destruct_func)g_free, res); + + return res; +} + /* Print a single metric line */ static gint print_metric_data_rspamc (struct worker_task *task, gchar *outbuf, gsize size, @@ -980,6 +1013,10 @@ print_metric_data_rspamc (struct worker_task *task, gchar *outbuf, gsize size, r += rspamd_snprintf (outbuf + r, size - r, "Action: %s" CRLF, str_action_metric (action)); } + if (action == METRIC_ACTION_REWRITE_SUBJECT && metric_res->metric->subject != NULL) { + r += rspamd_snprintf (outbuf + r, size - r, + "Subject: %s" CRLF, make_rewritten_subject (metric_res->metric, task)); + } } return r; @@ -1020,6 +1057,10 @@ print_metric_data_json (struct worker_task *task, gchar *outbuf, gsize size, metric_res->score, task->is_skipped ? "true" : "false", ms, rs, str_action_metric (action)); + if (action == METRIC_ACTION_REWRITE_SUBJECT && metric_res->metric->subject != NULL) { + r += rspamd_snprintf (outbuf + r, size - r, + " \"subject\": \"%s\"," CRLF, make_rewritten_subject (metric_res->metric, task)); + } } return r; |