rspamd_ftok_t parsed_data;
struct rspamd_mime_part *parent_part;
GHashTable *raw_headers;
+ GQueue *headers_order;
gchar *raw_headers_str;
gsize raw_headers_len;
enum rspamd_cte cte;
static void
rspamd_mime_header_add (struct rspamd_task *task,
- GHashTable *target, struct rspamd_mime_header *rh,
+ GHashTable *target, GQueue *order,
+ struct rspamd_mime_header *rh,
gboolean check_special)
{
GPtrArray *ar;
msg_debug_task ("add new raw header %s: %s", rh->name, rh->value);
}
+ g_queue_push_tail (order, rh);
+
if (check_special) {
rspamd_mime_header_check_special (task, rh);
}
/* Convert raw headers to a list of struct raw_header * */
void
rspamd_mime_headers_process (struct rspamd_task *task, GHashTable *target,
- const gchar *in, gsize len, gboolean check_newlines)
+ GQueue *order,
+ const gchar *in, gsize len,
+ gboolean check_newlines)
{
struct rspamd_mime_header *nh = NULL;
const gchar *p, *c, *end;
gint state = 0, l, next_state = 100, err_state = 100, t_state;
gboolean valid_folding = FALSE;
guint nlines_count[RSPAMD_TASK_NEWLINES_MAX];
- guint order = 0;
+ guint norder = 0;
p = in;
end = p + len;
/* We also validate utf8 and replace all non-valid utf8 chars */
rspamd_mime_charset_utf_enforce (nh->decoded, strlen (nh->decoded));
- rspamd_mime_header_add (task, target, nh, check_newlines);
- nh->order = order ++;
+ rspamd_mime_header_add (task, target, order, nh, check_newlines);
+ nh->order = norder ++;
state = 0;
break;
case 5:
/* Header has only name, no value */
nh->value = "";
nh->decoded = "";
- rspamd_mime_header_add (task, target, nh, check_newlines);
- nh->order = order ++;
+ rspamd_mime_header_add (task, target, order, nh, check_newlines);
+ nh->order = norder ++;
state = 0;
break;
case 99:
* @param check_newlines
*/
void rspamd_mime_headers_process (struct rspamd_task *task, GHashTable *target,
- const gchar *in, gsize len, gboolean check_newlines);
+ GQueue *order,
+ const gchar *in, gsize len,
+ gboolean check_newlines);
/**
* Perform rfc2047 decoding of a header
npart->parent_part = multipart;
npart->raw_headers = g_hash_table_new_full (rspamd_strcase_hash,
rspamd_strcase_equal, NULL, rspamd_ptr_array_free_hard);
+ npart->headers_order = g_queue_new ();
g_ptr_array_add (multipart->specific.mp.children, npart);
if (hdr_pos > 0 && hdr_pos < str.len) {
if (task->raw_headers_content.len > 0) {
rspamd_mime_headers_process (task, npart->raw_headers,
+ npart->headers_order,
npart->raw_headers_str,
npart->raw_headers_len,
FALSE);
if (task->raw_headers_content.len > 0) {
rspamd_mime_headers_process (task, task->raw_headers,
+ task->headers_order,
task->raw_headers_content.begin,
task->raw_headers_content.len,
TRUE);
if (task->raw_headers_content.len > 0) {
rspamd_mime_headers_process (task, task->raw_headers,
+ task->headers_order,
task->raw_headers_content.begin,
task->raw_headers_content.len,
TRUE);
hdr_pos = rspamd_string_find_eoh (&str, &body_pos);
npart->raw_headers = g_hash_table_new_full (rspamd_strcase_hash,
rspamd_strcase_equal, NULL, rspamd_ptr_array_free_hard);
+ npart->headers_order = g_queue_new ();
if (hdr_pos > 0 && hdr_pos < str.len) {
npart->raw_headers_str = str.str;
if (npart->raw_headers_len > 0) {
rspamd_mime_headers_process (task, npart->raw_headers,
+ npart->headers_order,
npart->raw_headers_str,
npart->raw_headers_len,
FALSE);
new_task->raw_headers = g_hash_table_new_full (rspamd_strcase_hash,
rspamd_strcase_equal, NULL, rspamd_ptr_array_free_hard);
+ new_task->headers_order = g_queue_new ();
new_task->request_headers = g_hash_table_new_full (rspamd_ftok_icase_hash,
rspamd_ftok_icase_equal, rspamd_fstring_mapped_ftok_free,
rspamd_request_header_dtor);
rspamd_ftok_icase_equal, rspamd_fstring_mapped_ftok_free,
rspamd_fstring_mapped_ftok_free);
rspamd_mempool_add_destructor (new_task->task_pool,
- (rspamd_mempool_destruct_t) g_hash_table_unref,
- new_task->reply_headers);
+ (rspamd_mempool_destruct_t) g_hash_table_unref,
+ new_task->reply_headers);
rspamd_mempool_add_destructor (new_task->task_pool,
- (rspamd_mempool_destruct_t) g_hash_table_unref,
- new_task->raw_headers);
+ (rspamd_mempool_destruct_t) g_hash_table_unref,
+ new_task->raw_headers);
+ rspamd_mempool_add_destructor (new_task->task_pool,
+ (rspamd_mempool_destruct_t) g_queue_free,
+ new_task->headers_order);
new_task->emails = g_hash_table_new (rspamd_email_hash, rspamd_emails_cmp);
rspamd_mempool_add_destructor (new_task->task_pool,
- (rspamd_mempool_destruct_t) g_hash_table_unref,
- new_task->emails);
+ (rspamd_mempool_destruct_t) g_hash_table_unref,
+ new_task->emails);
new_task->urls = g_hash_table_new (rspamd_url_hash, rspamd_urls_cmp);
rspamd_mempool_add_destructor (new_task->task_pool,
- (rspamd_mempool_destruct_t) g_hash_table_unref,
- new_task->urls);
+ (rspamd_mempool_destruct_t) g_hash_table_unref,
+ new_task->urls);
new_task->parts = g_ptr_array_sized_new (4);
rspamd_mempool_add_destructor (new_task->task_pool,
rspamd_ptr_array_free_hard, new_task->parts);
g_hash_table_unref (p->raw_headers);
}
+ g_queue_free (p->headers_order);
+
if (IS_CT_MULTIPART (p->ct)) {
if (p->specific.mp.children) {
g_ptr_array_free (p->specific.mp.children, TRUE);
GHashTable *urls; /**< list of parsed urls */
GHashTable *emails; /**< list of parsed emails */
GHashTable *raw_headers; /**< list of raw headers */
+ GQueue *headers_order; /**< order of raw headers */
GHashTable *results; /**< hash table of metric_result indexed by
* metric's name */
GHashTable *lua_cache; /**< cache of lua objects */