X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/26c2b1ef1709cd7b34fe3e78995768a369e0f116..bf982b40ca8495e7a8d14513aedcc2fe15f09a93:/uip/mhfixmsg.c diff --git a/uip/mhfixmsg.c b/uip/mhfixmsg.c index f5488532..491446c3 100644 --- a/uip/mhfixmsg.c +++ b/uip/mhfixmsg.c @@ -53,7 +53,6 @@ int debugsw; /* Needed by mhparse.c. */ extern int skip_mp_cte_check; /* flag to InitMultiPart */ extern int suppress_bogus_mp_content_warning; /* flag to InitMultiPart */ extern int bogus_mp_content; /* flag from InitMultiPart */ -void reverse_parts (CT); /* mhoutsbr.c */ int output_message (CT, char *); @@ -78,7 +77,6 @@ typedef struct fix_transformations { } fix_transformations; int mhfixmsgsbr (CT *, const fix_transformations *, char *); -static void reverse_alternative_parts (CT); static int fix_boundary (CT *, int *); static int get_multipart_boundary (CT, char **); static int replace_boundary (CT, char *, char *); @@ -287,7 +285,7 @@ main (int argc, char **argv) { } } - if (! (cts = (CT *) calloc ((size_t) 2, sizeof *cts))) { + if (! (cts = (CT *) mh_xcalloc ((size_t) 2, sizeof *cts))) { adios (NULL, "out of memory"); } ctp = cts; @@ -322,7 +320,7 @@ main (int argc, char **argv) { done (1); seq_setprev (mp); /* set the previous-sequence */ - if (! (cts = (CT *) calloc ((size_t) (mp->numsel + 1), sizeof *cts))) { + if (! (cts = (CT *) mh_xcalloc ((size_t) (mp->numsel + 1), sizeof *cts))) { adios (NULL, "out of memory"); } ctp = cts; @@ -459,27 +457,6 @@ mhfixmsgsbr (CT *ctp, const fix_transformations *fx, char *outfile) { } -/* parse_mime() arranges alternates in reverse (priority) order, so - reverse them back. This will put a text/plain part at the front of - a multipart/alternative part, for example, where it belongs. */ -static void -reverse_alternative_parts (CT ct) { - if (ct->c_type == CT_MULTIPART) { - struct multipart *m = (struct multipart *) ct->c_ctparams; - struct part *part; - - if (ct->c_subtype == MULTI_ALTERNATE) { - reverse_parts (ct); - } - - /* And call recursively on each part of a multipart. */ - for (part = m->mp_parts; part; part = part->mp_next) { - reverse_alternative_parts (part->mp_part); - } - } -} - - static int fix_boundary (CT *ct, int *message_mods) { struct multipart *mp; @@ -507,9 +484,11 @@ fix_boundary (CT *ct, int *message_mods) { if ((fixed = m_mktemp2 (NULL, invo_name, NULL, &(*ct)->c_fp))) { if (replace_boundary (*ct, fixed, part_boundary) == OK) { char *filename = add ((*ct)->c_file, NULL); + CT fixed_ct; free_content (*ct); - if ((*ct = parse_mime (fixed))) { + if ((fixed_ct = parse_mime (fixed))) { + *ct = fixed_ct; (*ct)->c_unlink = 1; ++*message_mods; @@ -517,6 +496,9 @@ fix_boundary (CT *ct, int *message_mods) { report (NULL, NULL, filename, "fix multipart boundary"); } + } else { + advise (NULL, "unable to parse fixed part"); + status = NOTOK; } free (filename); } else { @@ -693,7 +675,9 @@ replace_boundary (CT ct, char *file, char *boundary) { case BODY: fputs ("\n", fpout); /* buf will have a terminating NULL, skip it. */ - fwrite (buf, 1, bufsz-1, fpout); + if ((int) fwrite (buf, 1, bufsz-1, fpout) < bufsz-1) { + advise (file, "fwrite"); + } continue; case FILEEOF: @@ -1012,7 +996,7 @@ static CT divide_part (CT ct) { CT new_part; - if ((new_part = (CT) calloc (1, sizeof *new_part)) == NULL) + if ((new_part = (CT) mh_xcalloc (1, sizeof *new_part)) == NULL) adios (NULL, "out of memory"); /* Just copy over what is needed for decoding. c_vrsn and @@ -1164,11 +1148,11 @@ build_multipart_alt (CT first_alt, CT new_part, int type, int subtype) { struct multipart *m; const struct str2init *ctinit; - if ((ct = (CT) calloc (1, sizeof *ct)) == NULL) + if ((ct = (CT) mh_xcalloc (1, sizeof *ct)) == NULL) adios (NULL, "out of memory"); /* Set up the multipart/alternative part. These fields of *ct were - initialized to 0 by calloc(): + initialized to 0 by mh_xcalloc(): c_fp, c_unlink, c_begin, c_end, c_vrsn, c_ctline, c_celine, c_id, c_descr, c_dispo, c_partno, @@ -1272,7 +1256,7 @@ build_multipart_alt (CT first_alt, CT new_part, int type, int subtype) { p->mp_next->mp_next = NULL; p->mp_next->mp_part = first_alt; - if ((m = (struct multipart *) calloc (1, sizeof (struct multipart))) == + if ((m = (struct multipart *) mh_xcalloc (1, sizeof (struct multipart))) == NULL) adios (NULL, "out of memory"); m->mp_start = concat (boundary, "\n", NULL); @@ -1669,16 +1653,16 @@ strip_crs (CT ct, int *message_mods) { } else if (last_char_was_cr) { if (*cp != '\n') { if (write (fd, "\r", 1) < 0) { - advise (tempfile, "write of CR failed"); + advise (tempfile, "CR write"); } } if (write (fd, cp, 1) < 0) { - advise (tempfile, "write failed"); + advise (tempfile, "write"); } last_char_was_cr = 0; } else { if (write (fd, cp, 1) < 0) { - advise (tempfile, "write failed"); + advise (tempfile, "write"); } last_char_was_cr = 0; }