/**************** * Note: For program supplied (and therefore syntactically correct) * header lines, rfc822_add_header() may be used. */ int insert_header( RFC822 msg, char *line, size_t length ) { HDR_LINE hdr; if( !length ) { msg->in_body = 1; return transition_to_body(msg); } trim_trailing_spaces(line); /* Hmmm: should we check for invalid header data here? */ hdr = malloc( sizeof( *hdr ) + strlen(line) ); if( !hdr ) return RFC822ERR_NOMEM; hdr->next = NULL; hdr->cont = (*line == ' ' || *line == '\t'); strcpy(hdr->line, line ); *msg->hdr_lines_head = hdr; msg->hdr_lines_head = &hdr->next; /* lets help the caller to prevent mail loops * It is okay to use length here, also this value * not correct due to the space trimming */ if( length >= 9 && !memicmp(line, "Received:", 9) ) do_callback( msg, RFC822EVT_RCVD_SEEN ); return 0; }
static int insert_header (rfc822parse_t msg, const unsigned char *line, size_t length) { HDR_LINE hdr; assert (msg->current_part); if (!length) { msg->in_body = 1; return transition_to_body (msg); } if (!msg->current_part->hdr_lines) do_callback (msg, RFC822PARSE_BEGIN_HEADER); length = length_sans_trailing_ws (line, length); hdr = malloc (sizeof (*hdr) + length); if (!hdr) return -1; hdr->next = NULL; hdr->cont = (*line == ' ' || *line == '\t'); memcpy (hdr->line, line, length); hdr->line[length] = 0; /* Make it a string. */ /* Transform a field name into canonical format. */ if (!hdr->cont && strchr (line, ':')) capitalize_header_name (hdr->line); *msg->current_part->hdr_lines_tail = hdr; msg->current_part->hdr_lines_tail = &hdr->next; /* Lets help the caller to prevent mail loops and issue an event for * every Received header. */ if (length >= 9 && !memcmp (line, "Received:", 9)) do_callback (msg, RFC822PARSE_RCVD_SEEN); return 0; }