X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/484eb1003ae647e4b751e4d7829c7daf44fb99c9..ae9db48d6adafe3a10e6d125ff4720495cc76ee2:/uip/mhparse.c?ds=inline diff --git a/uip/mhparse.c b/uip/mhparse.c index f5a5983a..38188766 100644 --- a/uip/mhparse.c +++ b/uip/mhparse.c @@ -262,7 +262,7 @@ get_content (FILE *in, char *file, int toplevel) char *np, *vp; CT ct; HF hp; - long filepos; + m_getfld_state_t gstate = 0; /* allocate the content structure */ if (!(ct = (CT) calloc (1, sizeof(*ct)))) @@ -270,20 +270,19 @@ get_content (FILE *in, char *file, int toplevel) ct->c_fp = in; ct->c_file = add (file, NULL); - ct->c_begin = (filepos = ftell (ct->c_fp)) + 1; + ct->c_begin = ftell (ct->c_fp) + 1; /* * Parse the header fields for this * content into a linked list. */ - for (compnum = 1, state = FLD;;) { + m_getfld_track_filepos (&gstate, in); + for (compnum = 1;;) { int bufsz = sizeof buf; - switch (state = m_getfld (state, name, buf, &bufsz, in)) { + switch (state = m_getfld (&gstate, name, buf, &bufsz, in)) { case FLD: case FLDPLUS: - case FLDEOF: compnum++; - filepos += bufsz; /* get copies of the buffers */ np = add (name, NULL); @@ -292,29 +291,23 @@ get_content (FILE *in, char *file, int toplevel) /* if necessary, get rest of field */ while (state == FLDPLUS) { bufsz = sizeof buf; - state = m_getfld (state, name, buf, &bufsz, in); + state = m_getfld (&gstate, name, buf, &bufsz, in); vp = add (buf, vp); /* add to previous value */ } /* Now add the header data to the list */ add_header (ct, np, vp); - /* continue, if this isn't the last header field */ - if (state != FLDEOF) { - ct->c_begin = filepos + 1; - continue; - } - /* else fall... */ + /* continue, to see if this isn't the last header field */ + ct->c_begin = ftell (in) + 1; + continue; case BODY: - case BODYEOF: - filepos += bufsz; - ct->c_begin = filepos - strlen (buf); + ct->c_begin = ftell (in) - strlen (buf); break; case FILEEOF: - filepos += bufsz; - ct->c_begin = filepos; + ct->c_begin = ftell (in); break; case LENERR: @@ -328,6 +321,7 @@ get_content (FILE *in, char *file, int toplevel) /* break out of the loop */ break; } + m_getfld_state_destroy (&gstate); /* * Read the content headers. We will parse the @@ -1127,9 +1121,22 @@ InitMultiPart (CT ct) */ if (ct->c_encoding != CE_7BIT && ct->c_encoding != CE_8BIT && ct->c_encoding != CE_BINARY) { + /* Copy the Content-Transfer-Encoding header field body so we can + remove any trailing whitespace and leading blanks from it. */ + char *cte = add (ct->c_celine ? ct->c_celine : "(null)", NULL); + + bp = cte + strlen (cte) - 1; + while (bp >= cte && isspace (*bp)) *bp-- = '\0'; + for (bp = cte; *bp && isblank (*bp); ++bp) continue; + admonish (NULL, - "\"%s/%s\" type in message %s must be encoded in 7bit, 8bit, or binary", - ci->ci_type, ci->ci_subtype, ct->c_file); + "\"%s/%s\" type in message %s must be encoded in\n" + "7bit, 8bit, or binary, per RFC 2045 (6.4). One workaround " + "is to\nmanually edit the file and change the \"%s\"\n" + "Content-Transfer-Encoding to one of those. For now", + ci->ci_type, ci->ci_subtype, ct->c_file, bp); + free (cte); + return NOTOK; } @@ -2621,7 +2628,7 @@ openFTP (CT ct, char **file) fflush (stdout); - for (i = 0; (child_id = vfork()) == NOTOK && i < 5; i++) + for (i = 0; (child_id = fork()) == NOTOK && i < 5; i++) sleep (5); switch (child_id) { case NOTOK: @@ -2763,7 +2770,7 @@ openMail (CT ct, char **file) vec[vecp++] = e->eb_body; vec[vecp] = NULL; - for (i = 0; (child_id = vfork()) == NOTOK && i < 5; i++) + for (i = 0; (child_id = fork()) == NOTOK && i < 5; i++) sleep (5); switch (child_id) { case NOTOK: