static int InitGeneric (CT);
static int InitText (CT);
static int InitMultiPart (CT);
-void reverse_parts (CT);
+static void reverse_parts (CT);
static int InitMessage (CT);
static int InitApplication (CT);
static int init_encoding (CT, OpenCEFunc);
m_getfld_state_t gstate = 0;
/* allocate the content structure */
- if (!(ct = (CT) calloc (1, sizeof(*ct))))
+ if (!(ct = (CT) mh_xcalloc (1, sizeof(*ct))))
adios (NULL, "out of memory");
ct->c_fp = in;
ct->c_subtype = kv->kv_value;
/* allocate text character set structure */
- if ((t = (struct text *) calloc (1, sizeof(*t))) == NULL)
+ if ((t = (struct text *) mh_xcalloc (1, sizeof(*t))) == NULL)
adios (NULL, "out of memory");
ct->c_ctparams = (void *) t;
}
/* allocate primary structure for multipart info */
- if ((m = (struct multipart *) calloc (1, sizeof(*m))) == NULL)
+ if ((m = (struct multipart *) mh_xcalloc (1, sizeof(*m))) == NULL)
adios (NULL, "out of memory");
ct->c_ctparams = (void *) m;
if (strcmp (bufp + 2, m->mp_start))
continue;
next_part:
- if ((part = (struct part *) calloc (1, sizeof(*part))) == NULL)
+ if ((part = (struct part *) mh_xcalloc (1, sizeof(*part))) == NULL)
adios (NULL, "out of memory");
*next = part;
next = &part->mp_next;
* reverse the order of the parts of a multipart/alternative
*/
-void
+static void
reverse_parts (CT ct)
{
struct multipart *m = (struct multipart *) ct->c_ctparams;
}
+
+
+/* parse_mime() arranges alternates in reverse (priority) order. This
+ function can be used to reverse them back. This will put, for
+ example, a text/plain part before a text/html part in a
+ multipart/alternative part, for example, where it belongs. */
+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);
+ }
+ }
+}
+
+
/*
* MESSAGE
*/
PM pm;
struct partial *p;
- if ((p = (struct partial *) calloc (1, sizeof(*p))) == NULL)
+ if ((p = (struct partial *) mh_xcalloc (1, sizeof(*p))) == NULL)
adios (NULL, "out of memory");
ct->c_ctparams = (void *) p;
CT p;
FILE *fp;
- if ((e = (struct exbody *) calloc (1, sizeof(*e))) == NULL)
+ if ((e = (struct exbody *) mh_xcalloc (1, sizeof(*e))) == NULL)
adios (NULL, "out of memory");
ct->c_ctparams = (void *) e;
cc = len;
len -= cc;
- fwrite (buffer, sizeof(*buffer), cc, ce->ce_fp);
+ if ((int) fwrite (buffer, sizeof(*buffer), cc, ce->ce_fp) < cc) {
+ advise ("open7Bit", "fwrite");
+ }
if (ferror (ce->ce_fp)) {
content_error (ce->ce_file, ct, "error writing to");
goto clean_up;
}
}
+ *fd = fileno (ce->ce_fp);
return OK;
ready_already:
while ((cc = fread (buffer, sizeof(*buffer), sizeof(buffer), gp))
> 0)
- fwrite (buffer, sizeof(*buffer), cc, fp);
+ if ((int) fwrite (buffer, sizeof(*buffer), cc, fp) < cc) {
+ advise ("openFile", "fwrite");
+ }
fflush (fp);
if (ferror (gp)) {
while ((cc= fread (buffer, sizeof(*buffer), sizeof(buffer), gp))
> 0)
- fwrite (buffer, sizeof(*buffer), cc, fp);
+ if ((int) fwrite (buffer, sizeof(*buffer), cc, fp) < cc) {
+ advise ("openFTP", "fwrite");
+ }
fflush (fp);
if (ferror (gp)) {
while ((cc = fread(buffer, sizeof(*buffer),
sizeof(buffer), gp)) > 0)
- fwrite(buffer, sizeof(*buffer), cc, fp);
+ if ((int) fwrite(buffer, sizeof(*buffer), cc, fp) < cc) {
+ advise ("openURL", "fwrite");
+ }
fflush(fp);