X-Git-Url: http://git.marmaro.de/?p=mmh;a=blobdiff_plain;f=uip%2Fmhparse.c;h=fc24f5e13e8c30a832c6929a0bc45585ab6038fe;hp=1839a15ddd544b78a204e254fee8ff2e3668f80e;hb=d2da15ecabb03fb2de72863abdf5f21e52fdf329;hpb=1691e80890e5d8ba258c51c214a3e91880e1db2b diff --git a/uip/mhparse.c b/uip/mhparse.c index 1839a15..fc24f5e 100644 --- a/uip/mhparse.c +++ b/uip/mhparse.c @@ -3,6 +3,10 @@ * mhparse.c -- routines to parse the contents of MIME messages * * $Id$ + * + * This code is Copyright (c) 2002, by the authors of nmh. See the + * COPYRIGHT file in the root directory of the nmh distribution for + * complete copyright information. */ #include @@ -12,17 +16,17 @@ #include #include #include -#include -#include +#include +#include #include #include +#include #ifdef HAVE_SYS_WAIT_H # include #endif -extern int errno; extern int debugsw; extern int endian; /* mhmisc.c */ @@ -177,7 +181,7 @@ static struct str2init str2ces[] = { { "quoted-printable", CE_QUOTED, InitQuoted }, { "8bit", CE_8BIT, Init7Bit }, { "7bit", CE_7BIT, Init7Bit }, - { "binary", CE_BINARY, NULL }, + { "binary", CE_BINARY, Init7Bit }, { NULL, CE_EXTENSION, NULL }, /* these two must be last! */ { NULL, CE_UNKNOWN, NULL }, }; @@ -205,8 +209,7 @@ pidcheck (int status) fflush (stdout); fflush (stderr); - done (1); - /* NOTREACHED */ + return done (1); } @@ -257,7 +260,6 @@ parse_mime (char *file) if (!(ct = get_content (fp, file, 1))) { if (is_stdin) unlink (file); - fclose (fp); advise (NULL, "unable to decode %s", file); return NULL; } @@ -291,6 +293,7 @@ parse_mime (char *file) * toplevel = 0 # we are inside message type or multipart type * # other than multipart/digest * toplevel = -1 # we are inside multipart/digest + * NB: on failure we will fclose(in)! */ static CT @@ -582,8 +585,7 @@ add_header (CT ct, char *name, char *value) HF hp; /* allocate header field structure */ - if (!(hp = malloc (sizeof(*hp)))) - adios (NULL, "out of memory"); + hp = mh_xmalloc (sizeof(*hp)); /* link data into header structure */ hp->name = name; @@ -985,6 +987,7 @@ InitMultiPart (CT ct) * Check for "boundary" parameter, which is * required for multipart messages. */ + bp = 0; for (ap = ci->ci_attrs, ep = ci->ci_values; *ap; ap++, ep++) { if (!strcasecmp (*ap, "boundary")) { bp = *ep; @@ -1053,7 +1056,6 @@ next_part: if (!(p = get_content (fp, ct->c_file, ct->c_subtype == MULTI_DIGEST ? -1 : 0))) { - fclose (ct->c_fp); ct->c_fp = NULL; return NOTOK; } @@ -1194,9 +1196,9 @@ InitMessage (CT ct) struct k2v *kv; CI ci = &ct->c_ctinfo; - if (ct->c_encoding != CE_7BIT) { + if ((ct->c_encoding != CE_7BIT) && (ct->c_encoding != CE_8BIT)) { admonish (NULL, - "\"%s/%s\" type in message %s should be encoded in 7bit", + "\"%s/%s\" type in message %s should be encoded in 7bit or 8bit", ci->ci_type, ci->ci_subtype, ct->c_file); return NOTOK; } @@ -1282,7 +1284,6 @@ invalid_param: fseek (fp = ct->c_fp, ct->c_begin, SEEK_SET); if (!(p = get_content (fp, ct->c_file, 0))) { - fclose (ct->c_fp); ct->c_fp = NULL; return NOTOK; } @@ -1302,8 +1303,7 @@ invalid_param: goto no_body; } - if ((e->eb_body = bp = malloc ((unsigned) size)) == NULL) - adios (NULL, "out of memory"); + e->eb_body = bp = mh_xmalloc ((unsigned) size); fseek (p->c_fp, p->c_begin, SEEK_SET); while (size > 0) switch (cc = fread (bp, sizeof(*bp), size, p->c_fp)) { @@ -1569,6 +1569,8 @@ openBase64 (CT ct, char **file) unsigned long bits; unsigned char value, *b, *b1, *b2, *b3; char *cp, *ep, buffer[BUFSIZ]; + /* sbeck -- handle prefixes */ + CI ci; CE ce; MD5_CTX mdContext; @@ -1599,6 +1601,19 @@ openBase64 (CT ct, char **file) ce->ce_unlink = 0; } + /* sbeck@cise.ufl.edu -- handle suffixes */ + ci = &ct->c_ctinfo; + snprintf (buffer, sizeof(buffer), "%s-suffix-%s/%s", + invo_name, ci->ci_type, ci->ci_subtype); + cp = context_find (buffer); + if (cp == NULL || *cp == '\0') { + snprintf (buffer, sizeof(buffer), "%s-suffix-%s", invo_name, + ci->ci_type); + cp = context_find (buffer); + } + if (cp != NULL && *cp != '\0') + ce->ce_file = add (cp, ce->ce_file); + if ((ce->ce_fp = fopen (ce->ce_file, "w+")) == NULL) { content_error (ce->ce_file, ct, "unable to fopen for reading/writing"); return NOTOK; @@ -1768,6 +1783,8 @@ openQuoted (CT ct, char **file) char buffer[BUFSIZ]; unsigned char mask; CE ce; + /* sbeck -- handle prefixes */ + CI ci; MD5_CTX mdContext; ce = ct->c_cefile; @@ -1792,6 +1809,24 @@ openQuoted (CT ct, char **file) ce->ce_unlink = 0; } + /* sbeck@cise.ufl.edu -- handle suffixes */ + ci = &ct->c_ctinfo; + snprintf (buffer, sizeof(buffer), "%s-suffix-%s/%s", + invo_name, ci->ci_type, ci->ci_subtype); + cp = context_find (buffer); + if (cp == NULL || *cp == '\0') { + snprintf (buffer, sizeof(buffer), "%s-suffix-%s", invo_name, + ci->ci_type); + cp = context_find (buffer); + } + if (cp != NULL && *cp != '\0') + ce->ce_file = add (cp, ce->ce_file); + + if ((ce->ce_fp = fopen (ce->ce_file, "w+")) == NULL) { + content_error (ce->ce_file, ct, "unable to fopen for reading/writing"); + return NOTOK; + } + if ((ce->ce_fp = fopen (ce->ce_file, "w+")) == NULL) { content_error (ce->ce_file, ct, "unable to fopen for reading/writing"); return NOTOK; @@ -1966,6 +2001,9 @@ open7Bit (CT ct, char **file) { int cc, fd, len; char buffer[BUFSIZ]; + /* sbeck -- handle prefixes */ + char *cp; + CI ci; CE ce; ce = ct->c_cefile; @@ -1990,6 +2028,19 @@ open7Bit (CT ct, char **file) ce->ce_unlink = 0; } + /* sbeck@cise.ufl.edu -- handle suffixes */ + ci = &ct->c_ctinfo; + snprintf (buffer, sizeof(buffer), "%s-suffix-%s/%s", + invo_name, ci->ci_type, ci->ci_subtype); + cp = context_find (buffer); + if (cp == NULL || *cp == '\0') { + snprintf (buffer, sizeof(buffer), "%s-suffix-%s", invo_name, + ci->ci_type); + cp = context_find (buffer); + } + if (cp != NULL && *cp != '\0') + ce->ce_file = add (cp, ce->ce_file); + if ((ce->ce_fp = fopen (ce->ce_file, "w+")) == NULL) { content_error (ce->ce_file, ct, "unable to fopen for reading/writing"); return NOTOK; @@ -2400,7 +2451,7 @@ losing_ftp: goto losing_ftp; #endif - if (cachefile[0]) + if (cachefile[0]) { if (caching) chmod (cachefile, cachetype ? m_gmprot () : 0444); else { @@ -2414,7 +2465,7 @@ losing_ftp: fseek (gp, 0L, SEEK_SET); - while ((cc = fread (buffer, sizeof(*buffer), sizeof(buffer), gp)) + while ((cc= fread (buffer, sizeof(*buffer), sizeof(buffer), gp)) > 0) fwrite (buffer, sizeof(*buffer), cc, fp); fflush (fp); @@ -2432,6 +2483,7 @@ losing_ftp: } umask (mask); } + } fseek (ce->ce_fp, 0L, SEEK_SET); *file = ce->ce_file;