cd += fname_len + comment_len + extra_len + cd_basic_len;
}
- part->flags |= RSPAMD_MIME_PART_ARCHIVE;
+ part->part_type = RSPAMD_MIME_PART_ARCHIVE;
part->specific.arch = arch;
if (part->cd) {
}
end:
- part->flags |= RSPAMD_MIME_PART_ARCHIVE;
+ part->part_type = RSPAMD_MIME_PART_ARCHIVE;
part->specific.arch = arch;
arch->archive_name = &part->cd->filename;
arch->size = part->parsed_data.len;
}
end:
-part->flags |= RSPAMD_MIME_PART_ARCHIVE;
+ part->part_type = RSPAMD_MIME_PART_ARCHIVE;
part->specific.arch = arch;
if (part->cd != NULL) {
arch->archive_name = &part->cd->filename;
while ((p = rspamd_7zip_read_next_section (task, p, end, arch)) != NULL);
- part->flags |= RSPAMD_MIME_PART_ARCHIVE;
+ part->part_type = RSPAMD_MIME_PART_ARCHIVE;
part->specific.arch = arch;
if (part->cd != NULL) {
arch->archive_name = &part->cd->filename;
set:
/* Set archive data */
- part->flags |= RSPAMD_MIME_PART_ARCHIVE;
+ part->part_type = RSPAMD_MIME_PART_ARCHIVE;
part->specific.arch = arch;
if (part->cd) {
const guchar gz_magic[] = {0x1F, 0x8B};
PTR_ARRAY_FOREACH (MESSAGE_FIELD (task, parts), i, part) {
- if (!(part->flags & (RSPAMD_MIME_PART_TEXT|RSPAMD_MIME_PART_IMAGE))) {
+ if (part->part_type == RSPAMD_MIME_PART_UNDEFINED) {
if (part->parsed_data.len > 0) {
if (rspamd_archive_cheat_detect (part, "zip",
zip_magic, sizeof (zip_magic))) {
gz_magic, sizeof (gz_magic))) {
rspamd_archive_process_gzip (task, part);
}
-
- if (IS_CT_TEXT (part->ct) &&
- (part->flags & RSPAMD_MIME_PART_ARCHIVE) &&
- part->specific.arch) {
- struct rspamd_archive *arch = part->specific.arch;
-
- msg_info_task ("found %s archive with incorrect content-type: %T/%T",
- rspamd_archive_type_str (arch->type),
- &part->ct->type, &part->ct->subtype);
- part->ct->flags |= RSPAMD_CONTENT_TYPE_BROKEN;
- }
}
}
}
RSPAMD_CONTENT_TYPE_MISSING = 1 << 5,
};
-#define IS_CT_MULTIPART(ct) ((ct) && ((ct)->flags & RSPAMD_CONTENT_TYPE_MULTIPART))
-#define IS_CT_TEXT(ct) ((ct) && ((ct)->flags & RSPAMD_CONTENT_TYPE_TEXT))
-#define IS_CT_MESSAGE(ct) ((ct) &&((ct)->flags & RSPAMD_CONTENT_TYPE_MESSAGE))
-
enum rspamd_content_param_flags {
RSPAMD_CONTENT_PARAM_NORMAL = 0,
RSPAMD_CONTENT_PARAM_RFC2231 = (1 << 0),
struct rspamd_mime_part *part;
PTR_ARRAY_FOREACH (MESSAGE_FIELD (task, parts), i, part) {
- if (!(part->flags & (RSPAMD_MIME_PART_TEXT|RSPAMD_MIME_PART_ARCHIVE))) {
+ if (part->part_type == RSPAMD_MIME_PART_UNDEFINED) {
if (part->detected_type &&
strcmp (part->detected_type, "image") == 0 &&
part->parsed_data.len > 0) {
img->parent = part;
- part->flags |= RSPAMD_MIME_PART_IMAGE;
+ part->part_type = RSPAMD_MIME_PART_IMAGE;
part->specific.img = img;
}
}
guint i;
PTR_ARRAY_FOREACH (MESSAGE_FIELD (task, parts), i, part) {
- if (part->flags & RSPAMD_MIME_PART_IMAGE) {
+ if (part->part_type == RSPAMD_MIME_PART_IMAGE) {
rspamd_image_process_part (task, part);
}
}
gboolean found_html = FALSE, found_txt = FALSE, straight_ct = FALSE;
enum rspamd_action_type act;
- if ((IS_CT_TEXT (mime_part->ct) && (straight_ct = TRUE)) ||
- (mime_part->detected_type &&
- strcmp (mime_part->detected_type, "text") == 0)) {
+ if (((mime_part->ct && (mime_part->ct->flags & RSPAMD_CONTENT_TYPE_TEXT)) &&
+ (straight_ct = TRUE)) ||
+ (mime_part->detected_type &&
+ strcmp (mime_part->detected_type, "text") == 0)) {
found_txt = TRUE;
html_tok.begin = "html";
}
g_ptr_array_add (MESSAGE_FIELD (task, text_parts), text_part);
- mime_part->flags |= RSPAMD_MIME_PART_TEXT;
+ mime_part->part_type = RSPAMD_MIME_PART_TEXT;
mime_part->specific.txt = text_part;
act = rspamd_check_gtube (task, text_part);
}
else {
/* Check sanity */
- if (IS_CT_TEXT (part->ct)) {
+ if (part->ct && (part->ct->flags & RSPAMD_CONTENT_TYPE_TEXT)) {
RSPAMD_FTOK_FROM_STR (&srch, "application");
if (rspamd_ftok_cmp (&ct->type, &srch) == 0) {
rspamd_message_headers_unref (p->raw_headers);
}
- if (IS_CT_MULTIPART (p->ct)) {
+ if (IS_PART_MULTIPART (p)) {
if (p->specific.mp->children) {
g_ptr_array_free (p->specific.mp->children, TRUE);
}
}
+
+ if (p->part_type == RSPAMD_MIME_PART_CUSTOM_LUA && p->specific.lua_ref != -1) {
+ luaL_unref (msg->task->cfg->lua_state,
+ LUA_REGISTRYINDEX,
+ p->specific.lua_ref);
+ }
}
PTR_ARRAY_FOREACH (msg->text_parts, i, tp) {
msg->parts = g_ptr_array_sized_new (4);
msg->text_parts = g_ptr_array_sized_new (2);
+ msg->task = task;
REF_INIT_RETAIN (msg, rspamd_message_dtor);
lua_settop (L, func_pos);
}
- if (!(part->flags & (RSPAMD_MIME_PART_IMAGE|RSPAMD_MIME_PART_ARCHIVE)) &&
- (!part->ct || !(part->ct->flags & (RSPAMD_CONTENT_TYPE_MULTIPART|RSPAMD_CONTENT_TYPE_MESSAGE)))) {
+ if (part->part_type == RSPAMD_MIME_PART_UNDEFINED) {
rspamd_message_process_text_part_maybe (task, part);
}
}
struct rspamd_archive;
enum rspamd_mime_part_flags {
- RSPAMD_MIME_PART_TEXT = (1 << 0),
RSPAMD_MIME_PART_ATTACHEMENT = (1 << 1),
- RSPAMD_MIME_PART_IMAGE = (1 << 2),
- RSPAMD_MIME_PART_ARCHIVE = (1 << 3),
RSPAMD_MIME_PART_BAD_CTE = (1 << 4),
- RSPAMD_MIME_PART_MISSING_CTE = (1 << 5)
+ RSPAMD_MIME_PART_MISSING_CTE = (1 << 5),
};
+enum rspamd_mime_part_type {
+ RSPAMD_MIME_PART_UNDEFINED = 0,
+ RSPAMD_MIME_PART_MULTIPART,
+ RSPAMD_MIME_PART_MESSAGE,
+ RSPAMD_MIME_PART_TEXT,
+ RSPAMD_MIME_PART_ARCHIVE,
+ RSPAMD_MIME_PART_IMAGE,
+ RSPAMD_MIME_PART_CUSTOM_LUA
+};
+
+#define IS_PART_MULTIPART(part) ((part) && ((part)->part_type == RSPAMD_MIME_PART_MULTIPART))
+#define IS_PART_TEXT(part) ((part) && ((part)->part_type == RSPAMD_MIME_PART_TEXT))
+#define IS_PART_MESSAGE(part) ((part) &&((part)->part_type == RSPAMD_MIME_PART_MESSAGE))
+
enum rspamd_cte {
RSPAMD_CTE_UNKNOWN = 0,
RSPAMD_CTE_7BIT = 1,
enum rspamd_cte cte;
guint flags;
+ enum rspamd_mime_part_type part_type;
guint id;
union {
struct rspamd_mime_text_part *txt;
struct rspamd_image *img;
struct rspamd_archive *arch;
+ gint lua_ref;
} specific;
guchar digest[rspamd_cryptobox_HASHBYTES];
GHashTable *emails; /**< list of parsed emails */
struct rspamd_mime_headers_table *raw_headers; /**< list of raw headers */
struct rspamd_mime_header *headers_order; /**< order of raw headers */
+ struct rspamd_task *task;
GPtrArray *rcpt_mime;
GPtrArray *from_mime;
guchar digest[16];
}
PTR_ARRAY_FOREACH (MESSAGE_FIELD (task, parts), i, part) {
- if (IS_CT_TEXT (part->ct)) {
+ if (IS_PART_TEXT (part)) {
if (part->cte == cte) {
return TRUE;
}
* If user did not specify argument, let's assume that he wants
* recursive search if mime part is multipart/mixed
*/
- if (IS_CT_MULTIPART (cur_part->ct)) {
+ if (IS_PART_MULTIPART (cur_part)) {
recursive = TRUE;
}
}
* If user did not specify argument, let's assume that he wants
* recursive search if mime part is multipart/mixed
*/
- if (IS_CT_MULTIPART (cur_part->ct)) {
+ if (IS_PART_MULTIPART (cur_part)) {
recursive = TRUE;
}
}
* If user did not specify argument, let's assume that he wants
* recursive search if mime part is multipart/mixed
*/
- if (IS_CT_MULTIPART (ct)) {
+ if (IS_PART_MULTIPART (cur_part)) {
recursive = TRUE;
}
}
}
}
- if (IS_CT_TEXT (part->ct)) {
+ if (part->ct && (part->ct->flags & RSPAMD_CONTENT_TYPE_TEXT)) {
/* Need to copy text as we have couple of in-place change functions */
parsed = rspamd_fstring_sized_new (part->raw_data.len);
parsed->len = part->raw_data.len;
if (sel->flags & RSPAMD_CONTENT_TYPE_MULTIPART) {
st->nesting ++;
g_ptr_array_add (st->stack, npart);
+ npart->part_type = RSPAMD_MIME_PART_MULTIPART;
npart->specific.mp = rspamd_mempool_alloc0 (task->task_pool,
sizeof (struct rspamd_mime_multipart));
memcpy (&npart->specific.mp->boundary, &sel->orig_boundary,
else if (sel->flags & RSPAMD_CONTENT_TYPE_MESSAGE) {
st->nesting ++;
g_ptr_array_add (st->stack, npart);
+ npart->part_type = RSPAMD_MIME_PART_MESSAGE;
if ((ret = rspamd_mime_parse_normal_part (task, npart, st, err))
== RSPAMD_MIME_PARSE_OK) {
if (sel->flags & RSPAMD_CONTENT_TYPE_MULTIPART) {
g_ptr_array_add (nst->stack, npart);
nst->nesting ++;
+ npart->part_type = RSPAMD_MIME_PART_MULTIPART;
npart->specific.mp = rspamd_mempool_alloc0 (task->task_pool,
sizeof (struct rspamd_mime_multipart));
memcpy (&npart->specific.mp->boundary, &sel->orig_boundary,
else if (sel->flags & RSPAMD_CONTENT_TYPE_MESSAGE) {
if ((ret = rspamd_mime_parse_normal_part (task, npart, nst, err))
== RSPAMD_MIME_PARSE_OK) {
+ npart->part_type = RSPAMD_MIME_PART_MESSAGE;
ret = rspamd_mime_parse_message (task, npart, nst, err);
}
}
return luaL_error (L, "invalid arguments");
}
- if (IS_CT_MULTIPART (part->ct)) {
+ if (IS_PART_MULTIPART (part)) {
lua_pushlstring (L, part->specific.mp->boundary.begin,
part->specific.mp->boundary.len);
}
else {
parent = part->parent_part;
- if (!parent || !IS_CT_MULTIPART (parent->ct)) {
+ if (!parent || !IS_PART_MULTIPART (parent)) {
lua_pushnil (L);
}
else {
return luaL_error (L, "invalid arguments");
}
- lua_pushboolean (L, (part->flags & RSPAMD_MIME_PART_IMAGE) ? true : false);
+ lua_pushboolean (L, part->part_type == RSPAMD_MIME_PART_IMAGE);
return 1;
}
return luaL_error (L, "invalid arguments");
}
- lua_pushboolean (L, (part->flags & RSPAMD_MIME_PART_ARCHIVE) ? true : false);
+ lua_pushboolean (L, part->part_type == RSPAMD_MIME_PART_ARCHIVE);
return 1;
}
return luaL_error (L, "invalid arguments");
}
- lua_pushboolean (L, IS_CT_MULTIPART (part->ct) ? true : false);
+ lua_pushboolean (L, IS_PART_MULTIPART (part) ? true : false);
return 1;
}
return luaL_error (L, "invalid arguments");
}
- lua_pushboolean (L, IS_CT_MESSAGE (part->ct) ? true : false);
+ lua_pushboolean (L, IS_PART_MESSAGE (part) ? true : false);
return 1;
}
return luaL_error (L, "invalid arguments");
}
- if (!(part->flags & (RSPAMD_MIME_PART_IMAGE))) {
+ if (part->part_type != RSPAMD_MIME_PART_IMAGE) {
if (part->cd && part->cd->type == RSPAMD_CT_ATTACHMENT) {
lua_pushboolean (L, true);
}
return luaL_error (L, "invalid arguments");
}
- lua_pushboolean (L, (part->flags & RSPAMD_MIME_PART_TEXT) ? true : false);
+ lua_pushboolean (L, part->part_type == RSPAMD_MIME_PART_TEXT);
return 1;
}
return luaL_error (L, "invalid arguments");
}
- if (!(part->flags & RSPAMD_MIME_PART_IMAGE) || part->specific.img == NULL) {
+ if (part->part_type != RSPAMD_MIME_PART_IMAGE || part->specific.img == NULL) {
lua_pushnil (L);
}
else {
return luaL_error (L, "invalid arguments");
}
- if (!(part->flags & RSPAMD_MIME_PART_ARCHIVE) || part->specific.arch == NULL) {
+ if (part->part_type != RSPAMD_MIME_PART_ARCHIVE || part->specific.arch == NULL) {
lua_pushnil (L);
}
else {
return luaL_error (L, "invalid arguments");
}
- if (!IS_CT_MULTIPART (part->ct) || part->specific.mp->children == NULL) {
+ if (!IS_PART_MULTIPART (part) || part->specific.mp->children == NULL) {
lua_pushnil (L);
}
else {
return luaL_error (L, "invalid arguments");
}
- if (!(part->flags & RSPAMD_MIME_PART_TEXT) || part->specific.txt == NULL) {
+ if (part->part_type != RSPAMD_MIME_PART_TEXT || part->specific.txt == NULL) {
lua_pushnil (L);
}
else {
lua_createtable (L, MESSAGE_FIELD (task, parts)->len, 0);
PTR_ARRAY_FOREACH (MESSAGE_FIELD (task, parts), i, part) {
- if (part->flags & RSPAMD_MIME_PART_IMAGE) {
+ if (part->part_type == RSPAMD_MIME_PART_IMAGE) {
pimg = lua_newuserdata (L, sizeof (struct rspamd_image *));
rspamd_lua_setclass (L, "rspamd{image}", -1);
*pimg = part->specific.img;
lua_createtable (L, MESSAGE_FIELD (task, parts)->len, 0);
PTR_ARRAY_FOREACH (MESSAGE_FIELD (task, parts), i, part) {
- if (part->flags & RSPAMD_MIME_PART_ARCHIVE) {
+ if (part->part_type == RSPAMD_MIME_PART_ARCHIVE) {
parch = lua_newuserdata (L, sizeof (struct rspamd_archive *));
rspamd_lua_setclass (L, "rspamd{archive}", -1);
*parch = part->specific.arch;
io = NULL;
if (check_part) {
- if (mime_part->flags & RSPAMD_MIME_PART_TEXT &&
+ if (mime_part->part_type == RSPAMD_MIME_PART_TEXT &&
!(flags & FUZZY_CHECK_FLAG_NOTEXT)) {
part = mime_part->specific.txt;
part,
mime_part);
}
- else if (mime_part->flags & RSPAMD_MIME_PART_IMAGE &&
+ else if (mime_part->part_type == RSPAMD_MIME_PART_IMAGE &&
!(flags & FUZZY_CHECK_FLAG_NOIMAGES)) {
image = mime_part->specific.img;