static const guint8 gif_signature[] = {'G', 'I', 'F', '8'};
static const guint8 bmp_signature[] = {'B', 'M'};
-static void process_image (struct rspamd_task *task, struct rspamd_mime_part *part);
+static bool process_image (struct rspamd_task *task, struct rspamd_mime_part *part);
+
+
+bool
+rspamd_images_process_mime_part_maybe (struct rspamd_task *task,
+ struct rspamd_mime_part *part)
+{
+ if (part->part_type == RSPAMD_MIME_PART_UNDEFINED) {
+ if (part->detected_type &&
+ strcmp (part->detected_type, "image") == 0 &&
+ part->parsed_data.len > 0) {
+
+ return process_image (task, part);
+ }
+ }
+
+ return false;
+}
void
rspamd_images_process (struct rspamd_task *task)
struct rspamd_mime_part *part;
PTR_ARRAY_FOREACH (MESSAGE_FIELD (task, parts), i, part) {
- if (part->part_type == RSPAMD_MIME_PART_UNDEFINED) {
- if (part->detected_type &&
- strcmp (part->detected_type, "image") == 0 &&
- part->parsed_data.len > 0) {
-
- process_image (task, part);
- }
- }
+ rspamd_images_process_mime_part_maybe (task, part);
}
}
return img;
}
-static void
+static bool
process_image (struct rspamd_task *task, struct rspamd_mime_part *part)
{
struct rspamd_image *img;
part->part_type = RSPAMD_MIME_PART_IMAGE;
part->specific.img = img;
+
+ return true;
}
+
+ return false;
}
const gchar *
*/
void rspamd_images_process (struct rspamd_task *task);
+/**
+ * Process image if possible in a single mime part
+ * @param task
+ * @param part
+ * @return
+ */
+bool rspamd_images_process_mime_part_maybe (struct rspamd_task *task,
+ struct rspamd_mime_part *part);
+
/*
* Link embedded images to the HTML parts
*/
lua_settop (L, funcs_top);
}
+ /* Try to detect image before checking for text */
+ rspamd_images_process_mime_part_maybe (task, part);
+
+ /* Still no content detected, try text heuristic */
if (part->part_type == RSPAMD_MIME_PART_UNDEFINED) {
rspamd_message_process_text_part_maybe (task, part);
}
}
}
- rspamd_images_process (task);
rspamd_images_link (task);
rspamd_tokenize_meta_words (task);