#include "rfc822hdrs.h"
-void mutt_parse_rfc822_line(ENVELOPE *e, HEADER *hdr, char *line, char *p,
- short user_hdrs, short weed, short do_2047,
- LIST **lastp)
+LIST **mutt_parse_rfc822_line(ENVELOPE *e, HEADER *hdr, char *line, char *p,
+ short weed, short do_2047, LIST **user_hdrs)
{
switch (rfc822_well_known(line)) {
case HDR_APPARENTLY_FROM:
break;
default:
- if (!user_hdrs) {
- return;
- }
+ if (!user_hdrs)
+ break;
+
/* restore the original line */
line[m_strlen(line)] = ':';
if (weed && option(OPTWEED) && mutt_matches_ignore(line, Ignore)
&& !mutt_matches_ignore(line, UnIgnore)) {
- return;
- }
-
- if (*lastp) {
- (*lastp)->next = mutt_new_list();
- (*lastp) = (*lastp)->next;
- } else {
- (*lastp) = e->userhdrs = mutt_new_list ();
+ break;
}
- (*lastp)->data = m_strdup(line);
+ *user_hdrs = mutt_new_list();
+ (*user_hdrs)->data = m_strdup(line);
if (do_2047)
- rfc2047_decode(&(*lastp)->data);
+ rfc2047_decode(&(*user_hdrs)->data);
+ (*user_hdrs)->next = mutt_new_list();
+ return &(*user_hdrs)->next;
}
-}
-
-/*** XXX: MC READ MARK ***/
-
+ return user_hdrs;
+}
/* mutt_read_rfc822_header() -- parses a RFC822 header
*
* Returns: newly allocated envelope structure. You should free it by
* envelope_delete() when envelope stay unneeded.
*/
-ENVELOPE *mutt_read_rfc822_header (FILE * f, HEADER * hdr, short user_hdrs,
- short weed)
+ENVELOPE *
+mutt_read_rfc822_header(FILE *f, HEADER *hdr, short user_hdrs, short weed)
{
- ENVELOPE *e = envelope_new();
- LIST *last = NULL;
- char *line = p_new(char, LONG_STRING);
- char *p;
- off_t loc;
- ssize_t linelen = LONG_STRING;
- char buf[LONG_STRING + 1];
-
- if (hdr) {
- if (hdr->content == NULL) {
- hdr->content = mutt_new_body ();
-
- /* set the defaults from RFC1521 */
- hdr->content->type = TYPETEXT;
- hdr->content->subtype = m_strdup("plain");
- hdr->content->encoding = ENC7BIT;
- hdr->content->length = -1;
-
- /* RFC 2183 says this is arbitrary */
- hdr->content->disposition = DISPINLINE;
- }
- }
+ ENVELOPE *e = envelope_new();
+ LIST **last = user_hdrs ? &e->userhdrs : NULL;
- while ((loc = ftello (f)),
- mutt_read_rfc822_line (f, &line, &linelen))
- {
- if ((p = strpbrk (line, ": \t")) == NULL || *p != ':') {
- char return_path[LONG_STRING];
- time_t t;
-
- /* some bogus MTAs will quote the original "From " line */
- if (m_strncmp(">From ", line, 6) == 0)
- continue; /* just ignore */
- else if (is_from (line, return_path, sizeof (return_path), &t)) {
- /* MH somtimes has the From_ line in the middle of the header! */
- if (hdr && !hdr->received)
- hdr->received = t - mutt_local_tz (t);
- continue;
- }
+ char *line = p_new(char, LONG_STRING);
+ ssize_t linelen = LONG_STRING;
+ off_t loc;
- fseeko (f, loc, 0);
- break; /* end of header */
+ if (hdr && !hdr->content) {
+ hdr->content = mutt_new_body ();
+
+ /* set the defaults from RFC1521 */
+ hdr->content->type = TYPETEXT;
+ hdr->content->subtype = m_strdup("plain");
+ hdr->content->encoding = ENC7BIT;
+ hdr->content->length = -1;
+
+ /* RFC 2183 says this is arbitrary */
+ hdr->content->disposition = DISPINLINE;
}
- *buf = '\0';
-
- if (mutt_match_spam_list (line, SpamList, buf, sizeof (buf))) {
- if (!rx_list_match (NoSpamList, line)) {
-
- /* if spam tag already exists, figure out how to amend it */
- if (e->spam && *buf) {
- /* If SpamSep defined, append with separator */
- if (SpamSep) {
- mutt_buffer_addstr (e->spam, SpamSep);
- mutt_buffer_addstr (e->spam, buf);
- }
-
- /* else overwrite */
- else {
- e->spam->dptr = e->spam->data;
- *e->spam->dptr = '\0';
- mutt_buffer_addstr (e->spam, buf);
- }
- }
+ while ((loc = ftello(f)),
+ mutt_read_rfc822_line(f, &line, &linelen))
+ {
+ char buf[LONG_STRING + 1] = "";
+ char *p;
+
+ p = strpbrk(line, ": \t");
+ if (!p || *p != ':') {
+ char return_path[LONG_STRING];
+ time_t t;
+
+ /* some bogus MTAs will quote the original "From " line */
+ if (!m_strncmp(">From ", line, 6))
+ continue; /* just ignore */
+
+ if (is_from(line, return_path, sizeof(return_path), &t)) {
+ /* MH somtimes has the From_ line in the middle of the header! */
+ if (hdr && !hdr->received)
+ hdr->received = t - mutt_local_tz(t);
+ continue;
+ }
- /* spam tag is new, and match expr is non-empty; copy */
- else if (!e->spam && *buf) {
- e->spam = mutt_buffer_from (NULL, buf);
+ fseeko(f, loc, 0);
+ break; /* end of header */
}
- /* match expr is empty; plug in null string if no existing tag */
- else if (!e->spam) {
- e->spam = mutt_buffer_from (NULL, "");
+ if (mutt_match_spam_list(line, SpamList, buf, sizeof(buf))) {
+ if (!rx_list_match(NoSpamList, line)) {
+ /* if spam tag already exists, figure out how to amend it */
+ if (e->spam && *buf) {
+ if (SpamSep) {
+ /* If SpamSep defined, append with separator */
+ mutt_buffer_addstr(e->spam, SpamSep);
+ mutt_buffer_addstr(e->spam, buf);
+ } else {
+ /* else overwrite */
+ mutt_buffer_reset(e->spam);
+ mutt_buffer_addstr(e->spam, buf);
+ }
+ }
+ else if (!e->spam && *buf) {
+ /* spam tag is new, and match expr is non-empty; copy */
+ e->spam = mutt_buffer_from(NULL, buf);
+ }
+ else if (!e->spam) {
+ /* match expr is empty; plug in null string if no existing tag */
+ e->spam = mutt_buffer_from(NULL, "");
+ }
+ }
}
- if (e->spam && e->spam->data)
- debug_print (5, ("spam = %s\n", e->spam->data));
- }
- }
-
- *p++ = 0;
- p = vskipspaces(p);
- if (!*p)
- continue; /* skip empty header fields */
-
- mutt_parse_rfc822_line (e, hdr, line, p, user_hdrs, weed, 1, &last);
- }
+ *p++ = '\0';
+ p = vskipspaces(p);
+ if (!*p)
+ continue; /* skip empty header fields */
- p_delete(&line);
-
- if (hdr) {
- hdr->content->hdr_offset = hdr->offset;
- hdr->content->offset = ftello (f);
- rfc2047_decode_envelope(e);
- /* check for missing or invalid date */
- if (hdr->date_sent <= 0) {
- debug_print (1, ("no date found, using received "
- "time from msg separator\n"));
- hdr->date_sent = hdr->received;
+ last = mutt_parse_rfc822_line(e, hdr, line, p, weed, 1, last);
}
- }
- return (e);
-}
+ p_delete(&line);
-address_t *mutt_parse_adrlist (address_t * p, const char *s)
-{
- const char *q;
-
- /* check for a simple whitespace separated list of addresses */
- if ((q = strpbrk (s, "\"<>():;,\\")) == NULL) {
- char tmp[HUGE_STRING];
- char *r;
-
- m_strcpy(tmp, sizeof(tmp), s);
- r = tmp;
- while ((r = strtok (r, " \t")) != NULL) {
- p = rfc822_parse_adrlist (p, r);
- r = NULL;
+ if (hdr) {
+ hdr->content->hdr_offset = hdr->offset;
+ hdr->content->offset = ftello(f);
+ rfc2047_decode_envelope(e);
+ /* check for missing or invalid date */
+ if (hdr->date_sent <= 0) {
+ debug_print(1, ("no date found, using received "
+ "time from msg separator\n"));
+ hdr->date_sent = hdr->received;
+ }
}
- }
- else
- p = rfc822_parse_adrlist (p, s);
- return p;
+ return e;
}
+/* -------------------- XXX: MC READ MARK ------------- */
/* Compares mime types to the ok and except lists */
-int count_body_parts_check(LIST **checklist, BODY *b, int dflt) {
- LIST *type;
- ATTACH_MATCH *a;
-
- /* If list is null, use default behavior. */
- if (! *checklist) {
- /*return dflt;*/
- return 0;
- }
-
- for (type = *checklist; type; type = type->next) {
- a = (ATTACH_MATCH *)type->data;
- debug_print(5, ("cbpc: %s %d/%s ?? %s/%s [%d]... ",
- dflt ? "[OK] " : "[EXCL] ",
- b->type, b->subtype, a->major, a->minor, a->major_int));
- if ((a->major_int == TYPEANY || a->major_int == b->type) &&
- !regexec(&a->minor_rx, b->subtype, 0, NULL, 0)) {
- debug_print(5, ("yes\n"));
- return 1;
- } else {
- debug_print(5, ("no\n"));
+static int count_body_parts_check(LIST **checklist, BODY *b, int dflt)
+{
+ LIST *type;
+ ATTACH_MATCH *a;
+
+ /* If list is null, use default behavior. */
+ if (!*checklist)
+ return 0;
+
+ for (type = *checklist; type; type = type->next) {
+ a = (ATTACH_MATCH *)type->data;
+ debug_print(5, ("cbpc: %s %d/%s ?? %s/%s [%d]... ",
+ dflt ? "[OK] " : "[EXCL] ",
+ b->type, b->subtype, a->major, a->minor, a->major_int));
+ if ((a->major_int == TYPEANY || a->major_int == b->type) &&
+ !regexec(&a->minor_rx, b->subtype, 0, NULL, 0)) {
+ debug_print(5, ("yes\n"));
+ return 1;
+ } else {
+ debug_print(5, ("no\n"));
+ }
}
- }
- return 0;
+ return 0;
}
#define AT_COUNT(why) { shallcount = 1; }