]> diplodocus.org Git - nmh/blobdiff - uip/mhparse.c
Renamed getmymbox mh-format escape function to getmyaddr, and
[nmh] / uip / mhparse.c
index 754146674fbe71f88ec7da757133d2956304ed61..69bb542e7c56cca2088ef18bc3addf9eeb6db77a 100644 (file)
@@ -115,7 +115,7 @@ static int get_comment (const char *, const char *, char **, char **);
 static int InitGeneric (CT);
 static int InitText (CT);
 static int InitMultiPart (CT);
 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);
 static int InitMessage (CT);
 static int InitApplication (CT);
 static int init_encoding (CT, OpenCEFunc);
@@ -283,7 +283,7 @@ get_content (FILE *in, char *file, int toplevel)
     m_getfld_state_t gstate = 0;
 
     /* allocate the content structure */
     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;
        adios (NULL, "out of memory");
 
     ct->c_fp = in;
@@ -1018,7 +1018,7 @@ InitText (CT ct)
     ct->c_subtype = kv->kv_value;
 
     /* allocate text character set structure */
     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;
 
        adios (NULL, "out of memory");
     ct->c_ctparams = (void *) t;
 
@@ -1126,7 +1126,7 @@ InitMultiPart (CT ct)
     }
 
     /* allocate primary structure for multipart info */
     }
 
     /* 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;
 
        adios (NULL, "out of memory");
     ct->c_ctparams = (void *) m;
 
@@ -1171,7 +1171,7 @@ InitMultiPart (CT ct)
            if (strcmp (bufp + 2, m->mp_start))
                continue;
 next_part:
            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;
                adios (NULL, "out of memory");
            *next = part;
            next = &part->mp_next;
@@ -1277,7 +1277,7 @@ last_part:
  * reverse the order of the parts of a multipart/alternative
  */
 
  * 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;
 reverse_parts (CT ct)
 {
     struct multipart *m = (struct multipart *) ct->c_ctparams;
@@ -1294,6 +1294,30 @@ reverse_parts (CT ct)
 }
 
 
 }
 
 
+
+
+/* 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
  */
 /*
  * MESSAGE
  */
@@ -1330,7 +1354,7 @@ InitMessage (CT ct)
                PM pm;
                struct partial *p;
 
                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;
 
                    adios (NULL, "out of memory");
                ct->c_ctparams = (void *) p;
 
@@ -1379,7 +1403,7 @@ invalid_param:
                CT p;
                FILE *fp;
 
                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;
 
                    adios (NULL, "out of memory");
                ct->c_ctparams = (void *) e;
 
@@ -2250,7 +2274,9 @@ open7Bit (CT ct, char **file)
                cc = len;
            len -= cc;
 
                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;
            if (ferror (ce->ce_fp)) {
                content_error (ce->ce_file, ct, "error writing to");
                goto clean_up;
@@ -2317,6 +2343,7 @@ openExternal (CT ct, CT cb, CE ce, char **file, int *fd)
        }
     }
 
        }
     }
 
+    *fd = fileno (ce->ce_fp);
     return OK;
 
 ready_already:
     return OK;
 
 ready_already:
@@ -2384,7 +2411,9 @@ openFile (CT ct, char **file)
 
            while ((cc = fread (buffer, sizeof(*buffer), sizeof(buffer), gp))
                       > 0)
 
            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)) {
            fflush (fp);
 
            if (ferror (gp)) {
@@ -2593,7 +2622,9 @@ openFTP (CT ct, char **file)
 
                while ((cc= fread (buffer, sizeof(*buffer), sizeof(buffer), gp))
                           > 0)
 
                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)) {
                fflush (fp);
 
                if (ferror (gp)) {
@@ -2853,7 +2884,9 @@ openURL (CT ct, char **file)
 
                while ((cc = fread(buffer, sizeof(*buffer),
                                   sizeof(buffer), gp)) > 0)
 
                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);
 
 
                fflush(fp);