From d325b95656c091b75e0520d71ac865eb7bb047eb Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Thu, 14 Oct 2021 17:57:08 +0100 Subject: [Minor] Add method to iterate through all headers --- src/libmime/mime_headers.c | 16 ++++++++++++++++ src/libmime/mime_headers.h | 10 ++++++++++ 2 files changed, 26 insertions(+) diff --git a/src/libmime/mime_headers.c b/src/libmime/mime_headers.c index 3deb26a08..76ae1770a 100644 --- a/src/libmime/mime_headers.c +++ b/src/libmime/mime_headers.c @@ -958,6 +958,22 @@ rspamd_mime_headers_count (struct rspamd_mime_headers_table *hdrs) return 0; } +bool +rspamd_mime_headers_foreach(const struct rspamd_mime_headers_table *hdrs, + rspamd_hdr_traverse_func_t func, void *ud) +{ + const gchar *name; + struct rspamd_mime_header *hdr; + + kh_foreach(&hdrs->htb, name, hdr, { + if (!func(name, hdr, ud)) { + return false; + } + }); + + return true; +} + static void rspamd_message_headers_dtor (struct rspamd_mime_headers_table *hdrs) { diff --git a/src/libmime/mime_headers.h b/src/libmime/mime_headers.h index 7174f9e8f..43dd26e87 100644 --- a/src/libmime/mime_headers.h +++ b/src/libmime/mime_headers.h @@ -167,6 +167,16 @@ struct rspamd_mime_headers_table* rspamd_message_headers_new (void); */ gsize rspamd_mime_headers_count (struct rspamd_mime_headers_table *hdrs); +typedef bool(rspamd_hdr_traverse_func_t)(const gchar *, const struct rspamd_mime_header *, void *); +/** + * Traverse all headers in a table + * @param func + * @param ud + * @return + */ +bool rspamd_mime_headers_foreach(const struct rspamd_mime_headers_table *, + rspamd_hdr_traverse_func_t func, void *ud); + /** * Strip rfc822 CFWS sequences from a string in place * @param input input -- cgit v1.2.3