message-parser.c revision 7c424aa51c956c628e3512055841aa2f9eef4833
/* Copyright (C) 2002 Timo Sirainen */
#include "lib.h"
#include "istream.h"
#include "strescape.h"
#include "message-content-parser.h"
#include "message-parser.h"
#include "message-size.h"
struct message_boundary {
struct message_boundary *next;
struct message_part *part;
const char *boundary;
};
struct parser_context {
struct message_part *part;
char *last_boundary;
char *last_content_type;
struct message_boundary *boundaries;
void *context;
};
static struct message_part *
struct parser_context *parser_ctx);
static struct message_part *
struct message_size *body_size);
static struct message_part *
struct message_boundary *boundaries,
struct message_size *boundary_size);
struct message_part *part)
{
dest->physical_size +=
dest->virtual_size +=
}
static struct message_part *
{
/* set child position */
part->physical_pos =
return part;
}
void *context)
{
const char *str;
return;
}
}
}
static void
int value_quoted, void *context)
{
return;
if (value_quoted)
}
}
void *context)
{
/* call the user-defined header parser */
}
/* we need to know the boundary */
}
}
static struct message_part *
struct parser_context *parser_ctx)
{
struct message_boundary *b;
/* multipart message. add new boundary */
parser_ctx->boundaries = b;
/* reset fields */
/* skip the data before the first boundary */
&parent_part->body_size);
/* now, parse the parts */
while (next_part == parent_part) {
/* new child */
/* update our size */
if (next_part != parent_part)
break;
/* skip the boundary */
&parent_part->body_size);
}
/* remove boundary */
return next_part;
}
#define MUTEX_FLAGS \
static struct message_part *
{
/* when there's no content-type specified and we're
content-type */
} else {
}
}
headers again, this works pretty much the same as
} else {
/* normal message, read until the next boundary */
}
return next_part;
}
void *context)
{
struct message_part *part;
struct parser_context parser_ctx;
return part;
}
/* skip over to next line increasing message size */
struct message_size *msg_size)
{
const unsigned char *msg;
startpos = 0;
if (msg[i] == '\n') {
msg_size->virtual_size++;
}
break;
}
}
if (i < size) {
startpos = i+1;
break;
}
/* leave the last character, it may be \r */
startpos = 1;
}
}
}
}
struct message_size *hdr_size,
{
const unsigned char *msg;
int ret;
for (;;) {
if (ret == -2) {
/* overflow, line is too long. just skip it. */
startpos = line_start = 0;
continue;
}
/* EOF and nothing in buffer. the later check is
needed only when there's no message body */
break;
}
for (i = startpos; i < parse_size; i++) {
colon_pos = i;
continue;
}
if (msg[i] != '\n')
continue;
/* missing CR */
}
/* no headers at all */
break;
}
/* \n\n or \n\r\n - end of headers */
break;
}
/* make sure the header doesn't continue to next line */
colon_pos != line_start &&
/* we have a valid header line */
/* get length of name-field */
while (end_pos > line_start &&
end_pos--;
/* get length of value field. skip
only the initial LWSP after ':'.
some fields may want to keep
the extra spaces.. */
colon_pos++;
if (colon_pos < i &&
colon_pos++;
/* and finally call the function */
context);
}
line_start = i+1;
}
}
if (i < parse_size) {
/* end of header */
startpos = i+1;
break;
}
/* leave the last line to buffer */
colon_pos -= line_start;
startpos = i-line_start;
line_start = 0;
}
hdr_size->virtual_size +=
}
/* "end of headers" notify */
}
}
static struct message_boundary *
{
while (boundaries != NULL) {
return boundaries;
}
return NULL;
}
/* read until next boundary is found. if skip_over = FALSE, stop at the
[\r]\n before the boundary, otherwise leave it right after the known
boundary so the ending "--" can be checked. */
static struct message_boundary *
struct message_boundary *boundaries,
{
struct message_boundary *boundary;
const unsigned char *msg;
if (msg[i] != '\n')
continue;
/* possible boundary */
i - line_start - 2);
break;
}
/* missing CR */
}
line_start = i+1;
}
break;
if (i - line_start > 128 &&
/* long partial line, see if it's a boundary.
RFC-2046 says that the boundaries must be
70 chars without "--" or less. We allow
a bit larger.. */
i - line_start - 2);
break;
/* nope, we can skip over the line, just
leave the last char since it may be \r */
i--;
} else {
/* leave the last line to buffer, it may be
boundary */
i = line_start;
if (i > 2) i -= 2; /* leave the \r\n too */
line_start -= i;
}
i_stream_skip(input, i);
msg_size->physical_size += i;
msg_size->virtual_size += i;
}
if (skip_over) {
/* leave the pointer right after the boundary */
/* leave the \r\n before the boundary */
line_start--;
line_start--;
else
}
}
return boundary;
}
static struct message_part *
struct message_size *body_size)
{
struct message_boundary *boundary;
if (boundaries == NULL) {
return NULL;
} else {
}
}
/* skip data until next boundary is found. if it's end boundary,
skip the footer as well. */
static struct message_part *
struct message_boundary *boundaries,
struct message_size *boundary_size)
{
struct message_boundary *boundary;
const unsigned char *msg;
int end_boundary;
return NULL;
/* now, see if it's end boundary */
/* skip the rest of the line */
if (end_boundary) {
/* skip the footer */
}
}