X-Git-Url: http://git.marmaro.de/?p=mmh;a=blobdiff_plain;f=uip%2Fmhbuild.c;h=c4b1c607e8df3d18cabda2c759f3151c85c3a55a;hp=01acdb77e030120f951812faafd9efb8fa411ae9;hb=a87df3543d3bc128ba4079d1f95638476ba5ca50;hpb=4dc39c08f07428ff5f39acd7b0ddee30e0a004f6 diff --git a/uip/mhbuild.c b/uip/mhbuild.c index 01acdb7..c4b1c60 100644 --- a/uip/mhbuild.c +++ b/uip/mhbuild.c @@ -312,8 +312,10 @@ unlink_done() static CT build_mime(char *infile) { - int compnum, state; - char buf[BUFSIZ], name[NAMESZ]; + enum state state; + struct field f = free_field; + int compnum; + char buf[BUFSIZ]; char *cp, *np, *vp; struct multipart *m; struct part **pp; @@ -324,14 +326,14 @@ build_mime(char *infile) umask(~m_gmprot()); /* open the composition draft */ - if ((in = fopen(infile, "r")) == NULL) + if ((in = fopen(infile, "r")) == NULL) { adios(EX_IOERR, infile, "unable to open for reading"); + } /* ** Allocate space for primary (outside) content */ - if ((ct = (CT) mh_xcalloc(1, sizeof(*ct))) == NULL) - adios(EX_OSERR, NULL, "out of memory"); + ct = (CT) mh_xcalloc(1, sizeof(*ct)); /* ** Allocate structure for handling decoded content @@ -345,57 +347,45 @@ build_mime(char *infile) ** draft into the linked list of header fields for ** the new MIME message. */ - for (compnum = 1, state = FLD;;) { - switch (state = m_getfld(state, name, buf, sizeof(buf), in)) { - case FLD: - case FLDPLUS: + for (compnum = 1, state = FLD2;;) { + switch (state = m_getfld2(state, &f, in)) { + case FLD2: compnum++; /* abort if draft has Mime-Version header field */ - if (!mh_strcasecmp(name, VRSN_FIELD)) + if (!mh_strcasecmp(f.name, VRSN_FIELD)) { adios(EX_CONFIG, NULL, "draft shouldn't contain %s: field", VRSN_FIELD); + } /* ** abort if draft has Content-Transfer-Encoding ** header field */ - if (!mh_strcasecmp(name, ENCODING_FIELD)) + if (!mh_strcasecmp(f.name, ENCODING_FIELD)) { adios(EX_CONFIG, NULL, "draft shouldn't contain %s: field", ENCODING_FIELD); + } /* ignore any Content-Type fields in the header */ - if (!mh_strcasecmp(name, TYPE_FIELD)) { - while (state == FLDPLUS) - state = m_getfld(state, name, buf, - sizeof(buf), in); + if (!mh_strcasecmp(f.name, TYPE_FIELD)) { continue; } - /* get copies of the buffers */ - np = getcpy(name); - vp = getcpy(buf); - - /* if necessary, get rest of field */ - while (state == FLDPLUS) { - state = m_getfld(state, name, buf, - sizeof(buf), in); - vp = add(buf, vp); /* add to prev value */ - } - - /* Now add the header data to the list */ - add_header(ct, np, vp); + /* add the header data to the list */ + add_header(ct, getcpy(f.name), getcpy(f.value)); continue; - case FILEEOF: + case BODY2: + fseek(in, (long) (-strlen(f.value)), SEEK_CUR); + break; + + case FILEEOF2: adios(EX_CONFIG, NULL, "draft has empty body -- no directives!"); /* NOTREACHED */ - case BODY: - fseek(in, (long) (-strlen(buf)), SEEK_CUR); - break; - - case LENERR: - case FMTERR: + case LENERR2: + case FMTERR2: + case IOERR2: adios(EX_CONFIG, NULL, "message format error in component #%d", compnum); @@ -435,8 +425,7 @@ build_mime(char *infile) ct->c_subtype = MULTI_MIXED; ct->c_file = getcpy(infile); - if ((m = (struct multipart *) mh_xcalloc(1, sizeof(*m))) == NULL) - adios(EX_OSERR, NULL, "out of memory"); + m = (struct multipart *) mh_xcalloc(1, sizeof(*m)); ct->c_ctparams = (void *) m; pp = &m->mp_parts; @@ -455,8 +444,7 @@ build_mime(char *infile) if (!p) continue; - if ((part = (struct part *) mh_xcalloc(1, sizeof(*part))) == NULL) - adios(EX_OSERR, NULL, "out of memory"); + part = (struct part *) mh_xcalloc(1, sizeof(*part)); *pp = part; pp = &part->mp_next; part->mp_part = p; @@ -536,8 +524,7 @@ init_decoded_content(CT ct) { CE ce; - if ((ce = (CE) mh_xcalloc(1, sizeof(*ce))) == NULL) - adios(EX_OSERR, NULL, "out of memory"); + ce = (CE) mh_xcalloc(1, sizeof(*ce)); ct->c_cefile = ce; ct->c_ceopenfnx = open7Bit; /* since unencoded */ @@ -597,8 +584,7 @@ user_content(FILE *in, char *file, char *buf, CT *ctp) } /* allocate basic Content structure */ - if ((ct = (CT) mh_xcalloc(1, sizeof(*ct))) == NULL) - adios(EX_OSERR, NULL, "out of memory"); + ct = (CT) mh_xcalloc(1, sizeof(*ct)); *ctp = ct; /* allocate basic structure for handling decoded content */ @@ -906,9 +892,7 @@ use_forw: ct->c_type = CT_MULTIPART; ct->c_subtype = MULTI_DIGEST; - if ((m = (struct multipart *) - mh_xcalloc(1, sizeof(*m))) == NULL) - adios(EX_OSERR, NULL, "out of memory"); + m = (struct multipart *) mh_xcalloc(1, sizeof(*m)); ct->c_ctparams = (void *) m; pp = &m->mp_parts; @@ -918,9 +902,7 @@ use_forw: CT p; CE pe; - if ((p = (CT) mh_xcalloc(1, sizeof(*p))) - == NULL) - adios(EX_OSERR, NULL, "out of memory"); + p = (CT) mh_xcalloc(1, sizeof(*p)); init_decoded_content(p); pe = p->c_cefile; if (get_ctinfo("message/rfc822", p, 0) @@ -934,8 +916,7 @@ use_forw: msgnum); pe->ce_file = getcpy(buffer); - if ((part = (struct part *) mh_xcalloc(1, sizeof(*part))) == NULL) - adios(EX_OSERR, NULL, "out of memory"); + part = (struct part *) mh_xcalloc(1, sizeof(*part)); *pp = part; pp = &part->mp_next; part->mp_part = p; @@ -994,8 +975,7 @@ use_forw: ct->c_type = CT_MULTIPART; ct->c_subtype = vrsn; - if ((m = (struct multipart *) mh_xcalloc(1, sizeof(*m))) == NULL) - adios(EX_OSERR, NULL, "out of memory"); + m = (struct multipart *) mh_xcalloc(1, sizeof(*m)); ct->c_ctparams = (void *) m; pp = &m->mp_parts; @@ -1011,9 +991,7 @@ use_forw: if (!p) continue; - if ((part = (struct part *) - mh_xcalloc(1, sizeof(*part))) == NULL) - adios(EX_OSERR, NULL, "out of memory"); + part = (struct part *) mh_xcalloc(1, sizeof(*part)); *pp = part; pp = &part->mp_next; part->mp_part = p;