if (img) {
/* Check Content-Id */
- rh = rspamd_message_get_header_from_hash (part->raw_headers,
- "Content-Id");
+ rh = rspamd_message_get_header_from_hash(part->raw_headers,
+ "Content-Id", FALSE);
if (rh) {
cid = rh->decoded;
return FALSE;
}
- rh = rspamd_message_get_header_array (task,
- (gchar *)arg->data);
+ rh = rspamd_message_get_header_array(task,
+ (gchar *) arg->data, FALSE);
debug_task ("try to get header %s: %d", (gchar *)arg->data,
(rh != NULL));
return FALSE;
}
- return rspamd_message_get_header_array (task, arg->data) != NULL;
+ return rspamd_message_get_header_array(task, arg->data, FALSE) != NULL;
}
static gboolean
}
struct rspamd_mime_header *
-rspamd_message_get_header_from_hash (struct rspamd_mime_headers_table *headers,
- const gchar *field)
+rspamd_message_get_header_from_hash (struct rspamd_mime_headers_table *hdrs,
+ const gchar *field,
+ gboolean need_modified)
{
khiter_t k;
- khash_t(rspamd_mime_headers_htb) *htb = &headers->htb;
+ khash_t(rspamd_mime_headers_htb) *htb = &hdrs->htb;
+ struct rspamd_mime_header *hdr;
if (htb) {
k = kh_get (rspamd_mime_headers_htb, htb, (gchar *) field);
return NULL;
}
- return kh_value (htb, k);
+ hdr = kh_value (htb, k);
+
+ if (!need_modified) {
+ if (hdr->flags & RSPAMD_HEADER_NON_EXISTING) {
+ return NULL;
+ }
+
+ return hdr;
+ }
+ else {
+ if (hdr->flags & RSPAMD_HEADER_MODIFIED) {
+ return hdr->modified_chain;
+ }
+
+ return hdr;
+ }
}
return NULL;
}
struct rspamd_mime_header *
-rspamd_message_get_header_array (struct rspamd_task *task,
- const gchar *field)
+rspamd_message_get_header_array (struct rspamd_task *task, const gchar *field,
+ gboolean need_modified)
{
- return rspamd_message_get_header_from_hash (
+ return rspamd_message_get_header_from_hash(
MESSAGE_FIELD_CHECK (task, raw_headers),
- field);
+ field, need_modified);
}
static void
if (k == kh_end (htb)) {
hdr_elt = rspamd_mempool_alloc0 (task->task_pool, sizeof (*hdr_elt));
- hdr_elt->flags |= RSPAMD_HEADER_MODIFIED;
+ hdr_elt->flags |= RSPAMD_HEADER_MODIFIED|RSPAMD_HEADER_NON_EXISTING;
hdr_elt->name = rspamd_mempool_strdup (task->task_pool, hdr_name);
int r;
RSPAMD_HEADER_MODIFIED = 1u << 15u, /* Means we need to check modified chain */
RSPAMD_HEADER_ADDED = 1u << 16u, /* A header has been artificially added */
RSPAMD_HEADER_REMOVED = 1u << 17u, /* A header has been artificially removed */
+ RSPAMD_HEADER_NON_EXISTING = 1u << 18u, /* Header was not in the original message */
};
struct rspamd_mime_header {
*/
struct rspamd_mime_header *
rspamd_message_get_header_array (struct rspamd_task *task,
- const gchar *field);
+ const gchar *field,
+ gboolean need_modified);
/**
* Get an array of header's values with specified header's name using raw headers
*/
struct rspamd_mime_header *
rspamd_message_get_header_from_hash (struct rspamd_mime_headers_table *hdrs,
- const gchar *field);
+ const gchar *field,
+ gboolean need_modified);
/**
* Modifies a header (or insert one if not found)
enum rspamd_cte cte = RSPAMD_CTE_UNKNOWN;
gboolean parent_propagated = FALSE;
- hdr = rspamd_message_get_header_from_hash (hdrs, "Content-Transfer-Encoding");
+ hdr = rspamd_message_get_header_from_hash(hdrs, "Content-Transfer-Encoding", FALSE);
if (hdr == NULL) {
if (part->parent_part && part->parent_part->cte != RSPAMD_CTE_UNKNOWN &&
rspamd_ftok_t srch;
struct rspamd_content_type_param *found;
- hdr = rspamd_message_get_header_from_hash (part->raw_headers,
- "Content-Disposition");
+ hdr = rspamd_message_get_header_from_hash(part->raw_headers,
+ "Content-Disposition", FALSE);
if (hdr == NULL) {
}
}
- hdr = rspamd_message_get_header_from_hash (npart->raw_headers,
- "Content-Type");
+ hdr = rspamd_message_get_header_from_hash(npart->raw_headers,
+ "Content-Type", FALSE);
}
else {
}
}
- hdr = rspamd_message_get_header_from_hash (
+ hdr = rspamd_message_get_header_from_hash(
MESSAGE_FIELD (task, raw_headers),
- "Content-Type");
+ "Content-Type", FALSE);
}
else {
/* First apply heuristic, maybe we have just headers */
}
}
- hdr = rspamd_message_get_header_from_hash (
+ hdr = rspamd_message_get_header_from_hash(
MESSAGE_FIELD (task, raw_headers),
- "Content-Type");
+ "Content-Type", FALSE);
task->flags |= RSPAMD_TASK_FLAG_BROKEN_HEADERS;
}
else {
}
}
- hdr = rspamd_message_get_header_from_hash (npart->raw_headers,
- "Content-Type");
+ hdr = rspamd_message_get_header_from_hash(npart->raw_headers,
+ "Content-Type", FALSE);
}
else {
body_pos = 0;
}
if (dkim_header == NULL) {
- rh = rspamd_message_get_header_array (task, header_name);
+ rh = rspamd_message_get_header_array(task, header_name, FALSE);
if (rh) {
/* Check uniqueness of the header but we count from the bottom to top */
/* For signature check just use the saved dkim header */
if (ctx->header_canon_type == DKIM_CANON_SIMPLE) {
/* We need to find our own signature and use it */
- rh = rspamd_message_get_header_array (task, header_name);
+ rh = rspamd_message_get_header_array(task, header_name, FALSE);
if (rh) {
/* We need to find our own signature */
/* Do oversigning */
guint count = 0;
- rh = rspamd_message_get_header_array (task, dh->name);
+ rh = rspamd_message_get_header_array(task, dh->name, FALSE);
if (rh) {
DL_FOREACH (rh, cur) {
}
}
else {
- rh = rspamd_message_get_header_array (task, dh->name);
+ rh = rspamd_message_get_header_array(task, dh->name, FALSE);
if (rh) {
if (hstat.s.count > 0) {
case RSPAMD_RE_HEADER:
case RSPAMD_RE_RAWHEADER:
/* Get list of specified headers */
- rh = rspamd_message_get_header_array (task,
- re_class->type_data);
+ rh = rspamd_message_get_header_array(task,
+ re_class->type_data, FALSE);
if (rh) {
ret = rspamd_re_cache_process_headers_list (task, rt, re,
break;
case RSPAMD_RE_MIMEHEADER:
PTR_ARRAY_FOREACH (MESSAGE_FIELD (task, parts), i, mime_part) {
- rh = rspamd_message_get_header_from_hash (mime_part->raw_headers,
- re_class->type_data);
+ rh = rspamd_message_get_header_from_hash(mime_part->raw_headers,
+ re_class->type_data, FALSE);
if (rh) {
ret += rspamd_re_cache_process_headers_list (task, rt, re,
* of the body content.
*/
- rh = rspamd_message_get_header_array (task, "Subject");
+ rh = rspamd_message_get_header_array(task, "Subject", FALSE);
if (rh) {
scvec[0] = (guchar *)rh->decoded;
return rspamd_lua_push_header_array (L,
name,
- rspamd_message_get_header_from_hash (part->raw_headers, name),
+ rspamd_message_get_header_from_hash(part->raw_headers, name, FALSE),
how,
strong);
}
/* if has_name and not (image and Content-ID_header_present) */
if (part->cd && part->cd->filename.len > 0) {
if (part->part_type != RSPAMD_MIME_PART_IMAGE &&
- rspamd_message_get_header_from_hash (part->raw_headers,
- "Content-Id") == NULL) {
+ rspamd_message_get_header_from_hash(part->raw_headers,
+ "Content-Id", FALSE) == NULL) {
/* Filename is presented but no content id and not image */
lua_pushboolean (L, true);
}
strong = lua_toboolean (L, 3);
}
- rh = rspamd_message_get_header_array (task, name);
+ rh = rspamd_message_get_header_array(task, name, FALSE);
return rspamd_lua_push_header_array (L, name, rh, how, strong);
}
if (task) {
- rh = rspamd_message_get_header_array (task, "Reply-To");
+ rh = rspamd_message_get_header_array(task, "Reply-To", FALSE);
if (rh) {
lua_pushstring (L, rh->decoded);
}
}
else {
- h = rspamd_message_get_header_array (task, "Date");
+ h = rspamd_message_get_header_array(task, "Date", FALSE);
if (h) {
time_t tt;
rspamd_symcache_item_async_inc (task, item, M);
/* Now check if a message has its signature */
- rh = rspamd_message_get_header_array (task, RSPAMD_DKIM_SIGNHEADER);
+ rh = rspamd_message_get_header_array(task, RSPAMD_DKIM_SIGNHEADER, FALSE);
if (rh) {
msg_debug_task ("dkim signature found");