}
}
-/* Bound per-part newline metadata; the text itself is still normalized fully */
-static const unsigned int max_part_newlines = 100000;
+/* Bound newline metadata for the whole message; the text itself is still normalized fully */
+static const unsigned int max_message_newlines = 100000;
static inline void
-rspamd_text_part_maybe_add_newline(struct rspamd_mime_text_part *part)
+rspamd_text_part_maybe_add_newline(struct rspamd_task *task,
+ struct rspamd_mime_text_part *part)
{
- if (G_LIKELY(part->newlines->len < max_part_newlines)) {
+ if (G_LIKELY(MESSAGE_FIELD(task, ntext_newlines) < max_message_newlines)) {
g_ptr_array_add(part->newlines,
(((gpointer) (goffset) (part->utf_stripped_content->len))));
+ MESSAGE_FIELD(task, ntext_newlines) += 1;
}
else {
+ if (!MESSAGE_FIELD(task, text_newlines_limit_reached)) {
+ msg_warn_task("too many newlines in message; only %ud newline "
+ "positions are recorded across all text parts",
+ max_message_newlines);
+ MESSAGE_FIELD(task, text_newlines_limit_reached) = TRUE;
+ }
+
part->flags |= RSPAMD_MIME_TEXT_PART_FLAG_NEWLINES_TRUNCATED;
}
}
g_byte_array_append(part->utf_stripped_content,
(const uint8_t *) " ", 1);
crlf_added = TRUE;
- rspamd_text_part_maybe_add_newline(part);
+ rspamd_text_part_maybe_add_newline(task, part);
}
part->nlines++;
if (IS_TEXT_PART_HTML(part) || !url_open_bracket) {
g_byte_array_append(part->utf_stripped_content,
(const uint8_t *) " ", 1);
- rspamd_text_part_maybe_add_newline(part);
+ rspamd_text_part_maybe_add_newline(task, part);
crlf_added = TRUE;
}
else {
crlf_added = TRUE;
}
- rspamd_text_part_maybe_add_newline(part);
+ rspamd_text_part_maybe_add_newline(task, part);
}
c = p + 1;
g_byte_array_append(part->utf_stripped_content,
(const uint8_t *) " ", 1);
crlf_added = TRUE;
- rspamd_text_part_maybe_add_newline(part);
+ rspamd_text_part_maybe_add_newline(task, part);
}
part->nlines++;
part->nlines++;
if (!crlf_added) {
- rspamd_text_part_maybe_add_newline(part);
+ rspamd_text_part_maybe_add_newline(task, part);
}
/* Skip initial spaces */
if (!crlf_added) {
g_byte_array_append(part->utf_stripped_content,
(const uint8_t *) " ", 1);
- rspamd_text_part_maybe_add_newline(part);
+ rspamd_text_part_maybe_add_newline(task, part);
}
part->nlines++;
rspamd_strip_newlines_parse(task, p, end, part);
- if (part->flags & RSPAMD_MIME_TEXT_PART_FLAG_NEWLINES_TRUNCATED) {
- msg_warn_task("too many newlines in text part; only %ud newline "
- "positions are recorded",
- max_part_newlines);
- }
-
for (i = 0; i < part->newlines->len; i++) {
ex = rspamd_mempool_alloc(task->task_pool, sizeof(*ex));
off = (goffset) g_ptr_array_index(part->newlines, i);