gboolean is_spam = FALSE;
gchar *json_header, *json_header_encoded, *sc;
- headers_pos = rspamd_string_find_eoh (input);
+ headers_pos = rspamd_string_find_eoh (input, NULL);
if (headers_pos == -1) {
rspamd_fprintf (stderr,"cannot find end of headers position");
tmp ++;
}
+ if (p + 1 == end) {
+ new->raw_len = end - new->raw_value;
+ }
+ else {
+ new->raw_len = p - new->raw_value;
+ }
+
new->value = tmp;
- new->raw_len = p - new->raw_value;
new->decoded = g_mime_utils_header_decode_text (new->value);
if (new->decoded != NULL) {
}
}
-static inline const gchar *
-rspamd_message_find_body_start (const gchar *headers_end, const gchar *body_end)
-{
- const gchar *p = headers_end;
- enum {
- st_start = 0,
- st_cr,
- st_lf,
- } state = st_start;
-
- if (headers_end + 1 >= body_end) {
- return headers_end;
- }
-
- switch (state) {
- case st_start:
- if (*p == '\r') {
- p ++;
- state = st_cr;
- }
- else if (*p == '\n') {
- p ++;
- state = st_lf;
- }
- break;
- case st_cr:
- if (*p == '\n' && p < body_end) {
- /* CRLF */
- p ++;
- }
- break;
- case st_lf:
- break;
- }
-
- return p;
-}
-
gboolean
rspamd_message_parse (struct rspamd_task *task)
{
struct received_header *recv, *trecv;
const gchar *p;
gsize len;
- goffset hdr_pos;
+ goffset hdr_pos, body_pos;
gint i;
gdouble diff, *pdiff;
guint tw, *ptw, dw;
str.str = tmp->data;
str.len = tmp->len;
- hdr_pos = rspamd_string_find_eoh (&str);
+ hdr_pos = rspamd_string_find_eoh (&str, &body_pos);
if (hdr_pos > 0 && hdr_pos < tmp->len) {
- static const gchar *body_start;
-
- body_start = rspamd_message_find_body_start (p + hdr_pos,
- p + len);
task->raw_headers_content.begin = (gchar *) (p);
- task->raw_headers_content.len = body_start - p;
+ task->raw_headers_content.len = hdr_pos;
+ task->raw_headers_content.body_start = p + body_pos;
if (task->raw_headers_content.len > 0) {
process_raw_headers (task, task->raw_headers,
/* First of all find place of body */
p = task->msg.begin;
body_end = task->msg.begin + task->msg.len;
- body_start = task->msg.begin + task->raw_headers_content.len;
+ body_start = task->raw_headers_content.body_start;
+
+ if (!body_start) {
+ return DKIM_RECORD_ERROR;
+ }
/* Start canonization of body part */
if (!rspamd_dkim_canonize_body (&ctx->common, body_start, body_end)) {
/* First of all find place of body */
p = task->msg.begin;
body_end = task->msg.begin + task->msg.len;
- body_start = task->msg.begin + task->raw_headers_content.len;
+ body_start = task->raw_headers_content.body_start;
if (len > 0) {
ctx->common.len = len;
}
+ if (!body_start) {
+ return NULL;
+ }
+
/* Start canonization of body part */
if (!rspamd_dkim_canonize_body (&ctx->common, body_start, body_end)) {
return NULL;
GMimeMessage *message; /**< message, parsed with GMime */
GPtrArray *parts; /**< list of parsed parts */
GPtrArray *text_parts; /**< list of text parts */
- rspamd_ftok_t raw_headers_content; /**< list of raw headers */
+ struct {
+ const gchar *begin;
+ gsize len;
+ const gchar *body_start;
+ } raw_headers_content; /**< list of raw headers */
GPtrArray *received; /**< list of received headers */
GHashTable *urls; /**< list of parsed urls */
GHashTable *emails; /**< list of parsed emails */
goffset
-rspamd_string_find_eoh (GString *input)
+rspamd_string_find_eoh (GString *input, goffset *body_start)
{
const gchar *p, *c = NULL, *end;
enum {
}
else {
/* We have \r\r[^\n] */
+ if (body_start) {
+ *body_start = p - input->str + 1;
+ }
+
return p - input->str;
}
}
case got_lf:
if (*p == '\n') {
/* We have \n\n, which is obviously end of headers */
+ if (body_start) {
+ *body_start = p - input->str + 1;
+ }
return p - input->str;
}
else if (*p == '\r') {
break;
case got_linebreak_lf:
g_assert (c != NULL);
+ if (body_start) {
+ /* \r\n\r\n */
+ *body_start = p - input->str;
+ }
+
return c - input->str;
}
}
if (state == got_linebreak_lf) {
+ if (body_start) {
+ /* \r\n\r\n */
+ *body_start = p - input->str;
+ }
+
return c - input->str;
}
* Hence, to obtain the real EOH position, it is also required to skip
* space characters
*/
-goffset rspamd_string_find_eoh (GString *input);
+goffset rspamd_string_find_eoh (GString *input, goffset *body_start);
#define rspamd_ucl_emit_gstring(o, t, target) \