]> diplodocus.org Git - nmh/blobdiff - uip/burst.c
Remove support for aliases based on Unix groups.
[nmh] / uip / burst.c
index e4792335f4d3f5bd2906cbc16d92efb82591e001..de762e9901ebb91f0690f7f2081685eb02a2f66a 100644 (file)
@@ -1,6 +1,4 @@
-
-/*
- * burst.c -- explode digests into individual messages
+/* burst.c -- explode digests into individual messages
  *
  * This code is Copyright (c) 2002, by the authors of nmh.  See the
  * COPYRIGHT file in the root directory of the nmh distribution for
@@ -10,6 +8,9 @@
 #include <h/mh.h>
 #include <h/utils.h>
 #include <h/mhparse.h>
+#include "../sbr/m_maildir.h"
+#include "../sbr/m_mktemp.h"
+#include "mhfree.h"
 
 #define BURST_SWITCHES \
     X("inplace", 0, INPLSW) \
@@ -42,7 +43,6 @@ struct smsg {
  */
 
 int debugsw = 0;
-pid_t xpid = 0;
 
 /*
  * static prototypes
@@ -75,13 +75,7 @@ main (int argc, char **argv)
     struct smsg *smsgs;
     struct msgs *mp;
 
-#ifdef LOCALE
-    setlocale(LC_ALL, "");
-#endif
-    invo_name = r1bindex (argv[0], '/');
-
-    /* read user profile/context */
-    context_read();
+    if (nmh_init(argv[0], 1)) { return 1; }
 
     arguments = getarguments (invo_name, argc, argv, 1);
     argp = arguments;
@@ -158,7 +152,7 @@ main (int argc, char **argv)
        adios (maildir, "unable to change directory to");
 
     /* read folder and create message structure */
-    if (!(mp = folder_read (folder)))
+    if (!(mp = folder_read (folder, 1)))
        adios (NULL, "unable to read folder %s", folder);
 
     /* check for empty folder */
@@ -171,10 +165,7 @@ main (int argc, char **argv)
            done (1);
     seq_setprev (mp);  /* set the previous-sequence */
 
-    smsgs = (struct smsg *)
-       calloc ((size_t) (MAXFOLDER + 2), sizeof(*smsgs));
-    if (smsgs == NULL)
-       adios (NULL, "unable to allocate burst storage");
+    smsgs = mh_xcalloc(MAXFOLDER + 2, sizeof *smsgs);
 
     hi = mp->hghmsg + 1;
 
@@ -184,13 +175,13 @@ main (int argc, char **argv)
            if ((numburst = find_delim (msgnum, smsgs, &mimesw)) >= 1) {
                if (verbosw)
                    printf ("%d message%s exploded from digest %d\n",
-                           numburst, numburst > 1 ? "s" : "", msgnum);
+                           numburst, PLURALS(numburst), msgnum);
                burst (&mp, msgnum, smsgs, numburst, inplace, verbosw,
                       maildir, mimesw);
            } else {
                if (numburst == 0) {
                    if (!quietsw)
-                       admonish (NULL, "message %d not in digest format",
+                       inform("message %d not in digest format, continuing...",
                                  msgnum);
                }  /* this pair of braces was missing before 1999-07-15 */
                else
@@ -199,7 +190,7 @@ main (int argc, char **argv)
        }
     }
 
-    free ((char *) smsgs);
+    free(smsgs);
     context_replace (pfolder, folder); /* update current folder */
 
     /*
@@ -252,7 +243,7 @@ find_delim (int msgnum, struct smsg *smsgs, int *mimesw)
        content = parse_mime(msgnam);
        if (! content && *mimesw == 2)
            return 0;
-       else if (content) {
+       if (content) {
            smsgs[0].s_start = 0;
            smsgs[0].s_stop = content->c_begin - 1;
            msgp = 1;
@@ -294,7 +285,7 @@ find_delim (int msgnum, struct smsg *smsgs, int *mimesw)
        /*
         * Read in lines until we get to a message delimiter.
         *
-        * Previously we checked to make sure the preceeding line and
+        * Previously we checked to make sure the preceding line and
         * next line was a newline.  That actually does not comply with
         * RFC 934, so make sure we break on a message delimiter even
         * if the previous character was NOT a newline.
@@ -363,8 +354,6 @@ find_mime_parts (CT content, struct smsg *smsgs, int *msgp)
        for (part = m->mp_parts; part; part = part->mp_next)
            find_mime_parts(part->mp_part, smsgs, msgp);
     }
-
-    return;
 }
 
 
@@ -464,8 +453,14 @@ burst (struct msgs **mpp, int msgnum, struct smsg *smsgs, int numburst,
 
     i = inplace ? msgnum + numburst : mp->hghmsg;
     for (j = numburst; j >= (inplace ? 0 : 1); i--, j--) {
+        char *tempfile;
+
+       if ((tempfile = m_mktemp2(NULL, invo_name, NULL, &out)) == NULL) {
+           adios(NULL, "unable to create temporary file in %s",
+                 get_temp_dir());
+       }
+       strncpy (f2, tempfile, sizeof(f2));
        strncpy (f1, m_name (i), sizeof(f1));
-       strncpy (f2, m_mktemp(invo_name, NULL, &out), sizeof(f2));
 
        if (verbosw && i != msgnum)
            printf ("message %d of digest %d becomes message %d\n", j, msgnum, i);
@@ -482,13 +477,13 @@ burst (struct msgs **mpp, int msgnum, struct smsg *smsgs, int numburst,
                admonish (f3, "unable to rename %s to", f1);
 
            (void)snprintf(f3, sizeof (f3), "%s/%d", maildir, i);
-           ext_hook("del-hook", f3, (char *)0);
+           ext_hook("del-hook", f3, NULL);
        }
        if (rename (f2, f1) == NOTOK)
            admonish (f1, "unable to rename %s to", f2);
 
        (void)snprintf(f3, sizeof (f3), "%s/%d", maildir, i);
-       ext_hook("add-hook", f3, (char *)0);
+       ext_hook("add-hook", f3, NULL);
 
        copy_msg_flags (mp, i, msgnum);
        mp->msgflags |= SEQMOD;
@@ -504,14 +499,14 @@ burst (struct msgs **mpp, int msgnum, struct smsg *smsgs, int numburst,
 #define S4  3
 
 /*
- * Copy a mesage which is being burst out of a digest.
+ * Copy a message which is being burst out of a digest.
  * It will remove any "dashstuffing" in the message.
  */
 
 static void
 cpybrst (FILE *in, FILE *out, char *ifile, char *ofile, int len, int mime)
 {
-    register int c, state;
+    int c, state;
 
     for (state = mime ? S4 : S1; (c = fgetc (in)) != EOF && len > 0; len--) {
        if (c == 0)
@@ -525,6 +520,7 @@ cpybrst (FILE *in, FILE *out, char *ifile, char *ofile, int len, int mime)
 
                    default: 
                        state = S2;
+                       /* FALLTHRU */
                    case '\n': 
                        fputc (c, out);
                        break;
@@ -535,6 +531,7 @@ cpybrst (FILE *in, FILE *out, char *ifile, char *ofile, int len, int mime)
                switch (c) {
                    case '\n': 
                        state = S1;
+                       /* FALLTHRU */
                    default: 
                        fputc (c, out);
                        break;