]> diplodocus.org Git - nmh/commitdiff
Merge branch 'tmpfiles'
authorDavid Levine <levinedl@acm.org>
Sun, 26 Jan 2014 17:26:11 +0000 (11:26 -0600)
committerDavid Levine <levinedl@acm.org>
Sun, 26 Jan 2014 17:26:11 +0000 (11:26 -0600)
75 files changed:
docs/README.developers
h/mh.h
h/prototypes.h
sbr/context_save.c
sbr/folder_delmsgs.c
sbr/lock_file.c
sbr/m_backup.c
sbr/m_mktemp.c
sbr/push.c
sbr/seq_save.c
sbr/signals.c
sbr/utils.c
sbr/vector.c
uip/ali.c
uip/anno.c
uip/annosbr.c
uip/ap.c
uip/burst.c
uip/comp.c
uip/conflict.c
uip/dist.c
uip/distsbr.c
uip/dp.c
uip/dropsbr.c
uip/flist.c
uip/fmtdump.c
uip/fmttest.c
uip/folder.c
uip/forw.c
uip/forwsbr.c
uip/inc.c
uip/install-mh.c
uip/mark.c
uip/mhbuild.c
uip/mhbuildsbr.c
uip/mhcachesbr.c
uip/mhfixmsg.c
uip/mhfree.c
uip/mhl.c
uip/mhlist.c
uip/mhlsbr.c
uip/mhn.c
uip/mhparam.c
uip/mhparse.c
uip/mhpath.c
uip/mhshow.c
uip/mhstore.c
uip/mhstoresbr.c
uip/mhtest.c
uip/msgchk.c
uip/msh.c
uip/mshcmds.c
uip/new.c
uip/packf.c
uip/pick.c
uip/post.c
uip/prompter.c
uip/rcvdist.c
uip/rcvpack.c
uip/rcvstore.c
uip/rcvtty.c
uip/refile.c
uip/repl.c
uip/rmf.c
uip/rmm.c
uip/scan.c
uip/send.c
uip/sendsbr.c
uip/show.c
uip/slocal.c
uip/sortm.c
uip/viamail.c
uip/whatnow.c
uip/whatnowsbr.c
uip/whom.c

index 76f650dcbad534659bd47dce5998d3afea8b5db0..1d3fd73799c93df756abf0f464ac81e6d7a9e632 100644 (file)
@@ -22,6 +22,15 @@ commit checklist
 8. notify nmh-users?
 
 
 8. notify nmh-users?
 
 
+---------------------------------
+C library/system call usage notes
+---------------------------------
+* Use m_mktemp2() or m_mktemp() instead of mkstemp(3) (see section on
+  nmh temporary files below).
+* Use m_unlink() instead of unlink(3).
+* Use done() instead of _exit(3) except after a fork(3).
+
+
 -------------------------
 autoconf & automake files
 -------------------------
 -------------------------
 autoconf & automake files
 -------------------------
@@ -162,6 +171,21 @@ OS function  nmh-local version to use instead
 getpass()    nmh_getpass()
 
 
 getpass()    nmh_getpass()
 
 
+-------------------
+nmh temporary files
+-------------------
+
+To create a temporary file, use m_mktemp2() or m_mktemp().  They use
+mkstemp(3), but they also register the temporary file for removal on
+program termination.  So, do not use mkstemp() directly.
+
+To further support this, nmh_init() must be called at the beginning of
+main().  And, if a child process is not going to immediately call one
+of the exec(3) functions or _exit(3) after a fork(3), it should call
+unregister_for_removal(0).  Finally, nmh_init() sets up signal handlers
+for several signals:  these signal handlers should not be disabled.
+
+
 --------------
 nmh test suite
 --------------
 --------------
 nmh test suite
 --------------
diff --git a/h/mh.h b/h/mh.h
index 999d600ab1e0d691dd3fb9b3a9588a5e8d812d05..1ecb48825bf1df3ba799dc082a333eb80d4cd3a9 100644 (file)
--- a/h/mh.h
+++ b/h/mh.h
@@ -172,6 +172,7 @@ svector_t svector_create (size_t);
 void svector_free (svector_t);
 char *svector_push_back (svector_t, char *);
 char *svector_at (svector_t, size_t);
 void svector_free (svector_t);
 char *svector_push_back (svector_t, char *);
 char *svector_at (svector_t, size_t);
+char **svector_find(svector_t, const char *);
 char **svector_strs (svector_t);
 size_t svector_size (svector_t);
 
 char **svector_strs (svector_t);
 size_t svector_size (svector_t);
 
index a4184312a9ac85804a2c6e8069c2d43ebae652a8..563a0d5df2c12839fcc406f6ef85958ddd43737a 100644 (file)
@@ -191,6 +191,7 @@ int m_putenv (char *, char *);
 int m_rand (unsigned char *, size_t);
 char *m_mktemp(const char *, int *, FILE **);
 char *m_mktemp2(const char *, const char *, int *, FILE **);
 int m_rand (unsigned char *, size_t);
 char *m_mktemp(const char *, int *, FILE **);
 char *m_mktemp2(const char *, const char *, int *, FILE **);
+char *get_temp_dir();
 void m_unknown(m_getfld_state_t *, FILE *);
 int makedir (char *);
 char *message_id (time_t, int);
 void m_unknown(m_getfld_state_t *, FILE *);
 int makedir (char *);
 char *message_id (time_t, int);
@@ -370,3 +371,10 @@ int writeBase64raw (unsigned char *, size_t, unsigned char *);
  */
 void init_credentials_file ();
 int nmh_get_credentials (char *, char *, int, nmh_creds_t);
  */
 void init_credentials_file ();
 int nmh_get_credentials (char *, char *, int, nmh_creds_t);
+
+/*
+ * temporary file management
+ */
+int nmh_init(const char *argv0, int read_context);
+int m_unlink(const char *);
+void unregister_for_removal(int remove_files);
index 5224af4ce403a7a390c2246fd3d8db82064949e6..d7d87e45f5c6b51ab4d8ab3d694ad38d96ea793a 100644 (file)
@@ -53,6 +53,8 @@ context_save (void)
     sigprocmask (SIG_SETMASK, &oset, &set); /* reset the signal mask */
 
     if (action == 0)
     sigprocmask (SIG_SETMASK, &oset, &set); /* reset the signal mask */
 
     if (action == 0)
+       /* This must be _exit(), not exit(), because the child didn't
+          call unregister_for_removal() in m_chkids(). */
        _exit (0);              /* we are child, time to die */
 }
 
        _exit (0);              /* we are child, time to die */
 }
 
@@ -83,6 +85,8 @@ m_chkids (void)
            break;
 
        case 0:
            break;
 
        case 0:
+           /* It's not necessary to call unregister_for_removal(0)
+               because the child calls _exit() in context_save(). */
            setgid (getgid ());
            setuid (getuid ());
            break;
            setgid (getgid ());
            setuid (getuid ());
            break;
index ee4bd9e95e4b96d33b971578eda3918dd80363a3..db593f805134e20011863b86c3aa14193423d2af 100644 (file)
@@ -112,7 +112,7 @@ folder_delmsgs (struct msgs *mp, int unlink_msgs, int nohook)
 
            if (unlink_msgs) {
                /* just unlink the messages */
 
            if (unlink_msgs) {
                /* just unlink the messages */
-               if (unlink (dp) == -1) {
+               if (m_unlink (dp) == -1) {
                    admonish (dp, "unable to unlink");
                    retval = -1;
                    continue;
                    admonish (dp, "unable to unlink");
                    retval = -1;
                    continue;
index 01d7ae49a849e4710c46ca7942334dfc05d2de54..1a562f9b987d61333f7367bb50fd1aee851cbfa7 100644 (file)
@@ -335,7 +335,7 @@ lkclose_dot (int fd, const char *file)
 
     lockname (file, &lkinfo, 0);       /* get name of lock file */
 #if !defined(HAVE_LIBLOCKFILE)
 
     lockname (file, &lkinfo, 0);       /* get name of lock file */
 #if !defined(HAVE_LIBLOCKFILE)
-    unlink (lkinfo.curlock);           /* remove lock file      */
+    (void) m_unlink (lkinfo.curlock);  /* remove lock file      */
 #else
     lockfile_remove(lkinfo.curlock);
 #endif /* HAVE_LIBLOCKFILE */
 #else
     lockfile_remove(lkinfo.curlock);
 #endif /* HAVE_LIBLOCKFILE */
@@ -513,7 +513,7 @@ lkopen_dot (const char *file, int access, mode_t mode)
                    
                    /* check for stale lockfile, else sleep */
                    if (curtime > st.st_ctime + RSECS)
                    
                    /* check for stale lockfile, else sleep */
                    if (curtime > st.st_ctime + RSECS)
-                       unlink (lkinfo.curlock);
+                       (void) m_unlink (lkinfo.curlock);
                    else
                        sleep (5);
                }
                    else
                        sleep (5);
                }
@@ -543,17 +543,18 @@ static int
 lockit (struct lockinfo *li)
 {
     int fd;
 lockit (struct lockinfo *li)
 {
     int fd;
-    char *curlock, *tmplock;
+    char *curlock, *tmpfile;
 
 #if 0
     char buffer[128];
 #endif
 
     curlock = li->curlock;
 
 #if 0
     char buffer[128];
 #endif
 
     curlock = li->curlock;
-    tmplock = li->tmplock;
 
 
-    if ((fd = mkstemp(tmplock)) == -1)
+    if ((tmpfile = m_mktemp(li->tmplock, &fd, NULL)) == NULL) {
+        advise(NULL, "unable to create temporary file in %s", get_temp_dir());
        return -1;
        return -1;
+    }
 
 #if 0
     /* write our process id into lock file */
 
 #if 0
     /* write our process id into lock file */
@@ -567,8 +568,8 @@ lockit (struct lockinfo *li)
      * Now try to create the real lock file
      * by linking to the temporary file.
      */
      * Now try to create the real lock file
      * by linking to the temporary file.
      */
-    fd = link(tmplock, curlock);
-    unlink(tmplock);
+    fd = link(tmpfile, curlock);
+    (void) m_unlink(tmpfile);
 
     return (fd == -1 ? -1 : 0);
 }
 
     return (fd == -1 ? -1 : 0);
 }
index c34c40974343f1b92e0de5c685090d916f05fc38..5e24a0335327327ac58c85b8d378e93760f4b344 100644 (file)
@@ -23,6 +23,6 @@ m_backup (char *file)
        snprintf(buffer, sizeof(buffer), "%.*s%s%s", (int)(cp - file), file,
                BACKUP_PREFIX, cp);
 
        snprintf(buffer, sizeof(buffer), "%.*s%s%s", (int)(cp - file), file,
                BACKUP_PREFIX, cp);
 
-    unlink(buffer);
+    (void) m_unlink(buffer);
     return buffer;
 }
     return buffer;
 }
index ca4ab29cabdd7047c706d0b46420798d5477b50f..ac05306a96cb33b4c9c40ef947a3157ab0ed3700 100644 (file)
@@ -7,8 +7,11 @@
  */
 
 #include <h/mh.h>
  */
 
 #include <h/mh.h>
+#include <h/utils.h>
+#include <h/signals.h>
+
+static void register_for_removal(const char *);
 
 
-static char *get_temp_dir();
 
 /*  Create a temporary file.  If pfx_in is null, the temporary file
  *  will be created in the temporary directory (more on that later).
 
 /*  Create a temporary file.  If pfx_in is null, the temporary file
  *  will be created in the temporary directory (more on that later).
@@ -26,7 +29,7 @@ static char *get_temp_dir();
  *
  *  When pfx_in is null, the temporary directory is determined as
  *  follows, in order:
  *
  *  When pfx_in is null, the temporary directory is determined as
  *  follows, in order:
- *  
+ *
  *    MHTMPDIR envvar
  *    TMPDIR envvar
  *    TMP envvar
  *    MHTMPDIR envvar
  *    TMPDIR envvar
  *    TMP envvar
@@ -58,10 +61,14 @@ m_mktemp (
     }
 
     fd = mkstemp(tmpfil);
     }
 
     fd = mkstemp(tmpfil);
+
     if (fd < 0) {
         umask(oldmode);
         return NULL;
     }
     if (fd < 0) {
         umask(oldmode);
         return NULL;
     }
+
+    register_for_removal(tmpfil);
+
     if (fd_ret != NULL) {
         *fd_ret = fd;
         keep_open = 1;
     if (fd_ret != NULL) {
         *fd_ret = fd;
         keep_open = 1;
@@ -70,7 +77,7 @@ m_mktemp (
         FILE *fp = fdopen(fd, "w+");
         if (fp == NULL) {
             int olderr = errno;
         FILE *fp = fdopen(fd, "w+");
         if (fp == NULL) {
             int olderr = errno;
-            unlink(tmpfil);
+            (void) m_unlink(tmpfil);
             close(fd);
             errno = olderr;
             umask(oldmode);
             close(fd);
             errno = olderr;
             umask(oldmode);
@@ -90,7 +97,7 @@ m_mktemp (
  * by created based on a given pathname.  Although m_mktemp() technically
  * supports this, this version is when the directory is defined by
  * a separate variable from the prefix, eliminating the caller from having
  * by created based on a given pathname.  Although m_mktemp() technically
  * supports this, this version is when the directory is defined by
  * a separate variable from the prefix, eliminating the caller from having
- * to do string manipulation to generate the desired. pathname prefix.
+ * to do string manipulation to generate the desired pathname prefix.
  *
  * The pfx_in parameter specifies a basename prefix for the file.  If dir_in
  * is NULL, then the defined temporary directory (see comments to m_mktemp()
  *
  * The pfx_in parameter specifies a basename prefix for the file.  If dir_in
  * is NULL, then the defined temporary directory (see comments to m_mktemp()
@@ -126,7 +133,7 @@ m_mktemp2 (
 }
 
 
 }
 
 
-static char *
+char *
 get_temp_dir()
 {
     /* Ignore envvars if we are setuid */
 get_temp_dir()
 {
     /* Ignore envvars if we are setuid */
@@ -143,3 +150,125 @@ get_temp_dir()
     }
     return m_maildir("");
 }
     }
     return m_maildir("");
 }
+
+
+/*
+ * Array of files (full pathnames) to remove on process exit.
+ * Instead of removing slots from the array, just set to NULL
+ * to indicate that the file should no longer be removed.
+ */
+static svector_t exit_filelist = NULL;
+
+/*
+ * Register a file for removal at program termination.
+ */
+static void
+register_for_removal(const char *pathname) {
+    if (exit_filelist == NULL) exit_filelist = svector_create(20);
+    (void) svector_push_back(exit_filelist, add(pathname, NULL));
+}
+
+/*
+ * Unregister all files that were registered to be removed at program
+ * termination.  When called with remove_files of 0, this function is
+ * intended for use by one of the programs after a fork(3) without a
+ * subsequent call to one of the exec(3) functions or _exit(3).  When
+ * called with non-0 remove_files argument, it is intended for use by
+ * an atexit() function.
+ *
+ * Right after a fork() and before calling exec() or _exit(), if the
+ * child catches one of the appropriate signals, it will remove
+ * all the registered temporary files.  Some of those may be needed by
+ * the parent.  Some nmh programs ignore or block some of the signals
+ * in the child right after fork().  For the other programs, rather
+ * than complicate things by preventing that, just take the chance
+ * that it might happen.  It is harmless to attempt to unlink a
+ * temporary file twice, assuming another one wasn't created too
+ * quickly created with the same name.
+ */
+void
+unregister_for_removal(int remove_files) {
+    if (exit_filelist) {
+        size_t i;
+
+        for (i = 0; i < svector_size(exit_filelist); ++i) {
+            char *filename = svector_at(exit_filelist, i);
+
+            if (filename) {
+                if (remove_files) (void) unlink(filename);
+                free(filename);
+            }
+        }
+
+        svector_free(exit_filelist);
+        exit_filelist = NULL;
+    }
+}
+
+/*
+ * If the file was registered for removal, deregister it.  In
+ * any case, unlink it.
+ */
+int
+m_unlink(const char *pathname) {
+    if (exit_filelist) {
+        char **slot = svector_find(exit_filelist, pathname);
+
+        if (slot  &&  *slot) {
+            free(*slot);
+            *slot = NULL;
+        }
+    }
+
+    return unlink(pathname);
+    /* errno should be set to ENOENT if file was not found */
+}
+
+/*
+ * Remove all registered temporary files.
+ */
+void
+remove_registered_files_atexit() {
+    unregister_for_removal(1);
+}
+
+/*
+ * Remove all registered temporary files.  Suitable for use as a
+ * signal handler.  If the signal is one of the usual process
+ * termination signals, calls exit().  Otherwise, disables itself
+ * by restoring the default action and then re-raises the signal,
+ * in case the use was expecting a core dump.
+ */
+void
+remove_registered_files(int sig) {
+    struct sigaction act;
+
+    /*
+     * Ignore this signal for the duration.  And we either exit() or
+     * disable this signal handler below, so don't restore this handler.
+     */
+    act.sa_handler = SIG_IGN;
+    (void) sigemptyset(&act.sa_mask);
+    act.sa_flags = 0;
+    (void) sigaction(sig, &act, 0);
+
+    if (sig == SIGHUP || sig == SIGINT || sig == SIGQUIT || sig == SIGTERM) {
+        /*
+         * We don't need to call remove_registered_files_atexit() if
+         * it was registered with atexit(), but let's not assume that.
+         * It's harmless to call it twice.
+         */
+        remove_registered_files_atexit();
+
+        exit(1);
+    } else {
+        act.sa_handler = SIG_DFL;
+        (void) sigemptyset(&act.sa_mask);
+        act.sa_flags = 0;
+        (void) sigaction(sig, &act, 0);
+
+        remove_registered_files_atexit();
+
+        (void) raise(sig);
+    }
+}
index b4e3f4983f2297540f5494f797377bbdb22c3775..39c58acc8a093888734c0653b1626f77c411e295 100644 (file)
@@ -37,6 +37,9 @@ push(void)
            SIGNAL (SIGTTIN, SIG_IGN);
            SIGNAL (SIGTTOU, SIG_IGN);
 #endif
            SIGNAL (SIGTTIN, SIG_IGN);
            SIGNAL (SIGTTOU, SIG_IGN);
 #endif
+
+           unregister_for_removal(0);
+
            freopen ("/dev/null", "r", stdin);
            freopen ("/dev/null", "w", stdout);
            break;
            freopen ("/dev/null", "r", stdin);
            freopen ("/dev/null", "w", stdout);
            break;
index 83753afb5a1be551f068a06d9768b268b823ee4d..5b06dcdfe8019c73d7ea54e299b446906d487c26 100644 (file)
@@ -91,7 +91,7 @@ priv:
                    rewind(fp);
                    ftruncate(fileno(fp), 0);
                } else if ((fp = lkfopendata (seqfile, "w")) == NULL
                    rewind(fp);
                    ftruncate(fileno(fp), 0);
                } else if ((fp = lkfopendata (seqfile, "w")) == NULL
-                       && (unlink (seqfile) == -1 ||
+                       && (m_unlink (seqfile) == -1 ||
                            (fp = lkfopendata (seqfile, "w")) == NULL)) {
                    admonish (attr, "unable to write");
                    goto priv;
                            (fp = lkfopendata (seqfile, "w")) == NULL)) {
                    admonish (attr, "unable to write");
                    goto priv;
@@ -118,7 +118,7 @@ priv:
         * public sequences, then remove that file.
         */
        if (!is_readonly(mp))
         * public sequences, then remove that file.
         */
        if (!is_readonly(mp))
-           unlink (seqfile);
+           (void) m_unlink (seqfile);
     }
 
     /*
     }
 
     /*
index eb26e632317be1075936a8981f8fe5a17c90ec71..7645c1ccd52e9a6e591dd5d81b12e6be0ff61ddc 100644 (file)
@@ -10,6 +10,9 @@
 #include <h/mh.h>
 #include <h/signals.h>
 
 #include <h/mh.h>
 #include <h/signals.h>
 
+/* sbr/m_mktemp.c */
+extern void remove_registered_files(int);
+
 
 /*
  * A version of the function `signal' that uses reliable
 
 /*
  * A version of the function `signal' that uses reliable
@@ -78,3 +81,30 @@ SIGNAL2 (int sig, SIGNAL_HANDLER func)
     return (oact.sa_handler);
 }
 
     return (oact.sa_handler);
 }
 
+
+/*
+ * For use by nmh_init().
+ */
+int
+setup_signal_handlers() {
+    /*
+     * Catch HUP, INT, QUIT, and TERM so that we can clean up tmp
+     * files when the user terminates the process early.  And also a
+     * few other common signals that can be thrown due to bugs, stack
+     * overflow, etc.
+     */
+
+    if (SIGNAL(SIGHUP,  remove_registered_files) == SIG_ERR  ||
+        SIGNAL(SIGINT,  remove_registered_files) == SIG_ERR  ||
+        SIGNAL(SIGQUIT, remove_registered_files) == SIG_ERR  ||
+        SIGNAL(SIGTERM, remove_registered_files) == SIG_ERR  ||
+        SIGNAL(SIGILL,  remove_registered_files) == SIG_ERR  ||
+#       ifdef SIGBUS
+        SIGNAL(SIGBUS,  remove_registered_files) == SIG_ERR  ||
+#       endif
+        SIGNAL(SIGSEGV, remove_registered_files) == SIG_ERR) {
+        return NOTOK;
+    }
+
+    return OK;
+}
index 7f0760a0aefa46430c0f96352454b36392e22b45..d8b060fb13ce5f7a87a949166fe01e6d566c73d6 100644 (file)
 #include <h/utils.h>
 #include <fcntl.h>
 
 #include <h/utils.h>
 #include <fcntl.h>
 
+/* sbr/signals.c */
+extern int setup_signal_handlers();
+
+/* sbr/m_mktemp.c */
+extern void remove_registered_files_atexit();
+
+
 /*
  * We allocate space for messages (msgs array)
  * this number of elements at a time.
 /*
  * We allocate space for messages (msgs array)
  * this number of elements at a time.
@@ -317,3 +324,31 @@ nmh_strcasestr (const char *s1, const char *s2) {
 
     return NULL;
 }
 
     return NULL;
 }
+
+
+int
+nmh_init(const char *argv0, int read_context) {
+    setlocale(LC_ALL, "");
+
+    invo_name = r1bindex ((char *) argv0, '/');
+
+    if (setup_signal_handlers()) {
+        admonish("sigaction", "unable to set up signal handlers");
+    }
+
+    /* POSIX atexit() does not define any error conditions. */
+    if (atexit(remove_registered_files_atexit)) {
+        admonish("atexit", "unable to register atexit function");
+    }
+
+    if (read_context) {
+        context_read();
+        return OK;
+    } else {
+        int status = context_foil(NULL);
+        if (status != OK) {
+            advise("", "failed to create minimal profile/conext");
+        }
+        return status;
+    }
+}
index ca8c894ea398bce0d3f988f72daf4f5f774a3e0c..10058d4da1e8df45c015eeb955ddf57021fecad3 100644 (file)
@@ -174,6 +174,24 @@ svector_at (svector_t vec, size_t i) {
     return vec->strs[i];
 }
 
     return vec->strs[i];
 }
 
+/*
+ * Return address of first element that stringwise matches s.
+ * The caller can replace the contents of the return address.
+ */
+char **
+svector_find (svector_t vec, const char *s) {
+    size_t i;
+    char **str = vec->strs;
+
+    for (i = 0; i < vec->size; ++i, ++str) {
+        if (*str  &&  ! strcmp(*str, s)) {
+            return str;
+        }
+    }
+
+    return NULL;
+}
+
 char **
 svector_strs (svector_t vec) {
     return vec->strs;
 char **
 svector_strs (svector_t vec) {
     return vec->strs;
index 534c25d886fdec0a267a6e05823ea2b8b234bf47..e7c865befee983e6f8ef98e6763b65454aff9402 100644 (file)
--- a/uip/ali.c
+++ b/uip/ali.c
@@ -53,11 +53,7 @@ main (int argc, char **argv)
     char **vec = mh_xmalloc (argc * sizeof (char *)), **arguments;
     struct aka *ak;
 
     char **vec = mh_xmalloc (argc * sizeof (char *)), **arguments;
     struct aka *ak;
 
-    setlocale(LC_ALL, "");
-    invo_name = r1bindex (argv[0], '/');
-
-    /* read user profile/context */
-    context_read();
+    if (nmh_init(argv[0], 1)) { return 1; }
 
     mts_init (invo_name);
     arguments = getarguments (invo_name, argc, argv, 1);
 
     mts_init (invo_name);
     arguments = getarguments (invo_name, argc, argv, 1);
index 75bcc68220dbf56357f0a42ca0c366a2036d7f45..26706edac514e8c51f364104cb2915c30c031e1b 100644 (file)
@@ -94,11 +94,7 @@ main (int argc, char **argv)
     int                list = 0;               /* list header elements if set */
     int                number = 0;             /* delete specific number of like elements if set */
 
     int                list = 0;               /* list header elements if set */
     int                number = 0;             /* delete specific number of like elements if set */
 
-    setlocale(LC_ALL, "");
-    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;
 
     arguments = getarguments (invo_name, argc, argv, 1);
     argp = arguments;
index ae9df280b04b3ac0477429e254e654630915b646..88c90f44eca8fc871381945280240d4dc4d127eb 100644 (file)
@@ -184,7 +184,10 @@ annosbr (int fd, char *file, char *comp, char *text, int inplace, int datesw, in
 
     mode = fstat (fd, &st) != NOTOK ? (int) (st.st_mode & 0777) : m_gmprot ();
 
 
     mode = fstat (fd, &st) != NOTOK ? (int) (st.st_mode & 0777) : m_gmprot ();
 
-    strncpy (tmpfil, m_mktemp2(file, "annotate", NULL, &tmp), sizeof(tmpfil));
+    if ((cp = m_mktemp2(file, "annotate", NULL, &tmp)) == NULL) {
+       adios(NULL, "unable to create temporary file in %s", get_temp_dir());
+    }
+    strncpy (tmpfil, cp, sizeof(tmpfil));
     chmod (tmpfil, mode);
 
     /*
     chmod (tmpfil, mode);
 
     /*
@@ -412,13 +415,13 @@ annosbr (int fd, char *file, char *comp, char *text, int inplace, int datesw, in
 
        cpydata (tmpfd, fd, tmpfil, file);
        close (tmpfd);
 
        cpydata (tmpfd, fd, tmpfil, file);
        close (tmpfd);
-       unlink (tmpfil);
+       (void) m_unlink (tmpfil);
     } else {
        strncpy (buffer, m_backup (file), sizeof(buffer));
        if (rename (file, buffer) == NOTOK) {
            switch (errno) {
                case ENOENT:    /* unlinked early - no annotations */
     } else {
        strncpy (buffer, m_backup (file), sizeof(buffer));
        if (rename (file, buffer) == NOTOK) {
            switch (errno) {
                case ENOENT:    /* unlinked early - no annotations */
-                   unlink (tmpfil);
+                   (void) m_unlink (tmpfil);
                    break;
 
                default:
                    break;
 
                default:
index a8f9169f9a597494caaf1277453cea698bd134a7..c8cf4b25d120327c8df257ed152c4d0f5c1f8861 100644 (file)
--- a/uip/ap.c
+++ b/uip/ap.c
@@ -53,11 +53,7 @@ main (int argc, char **argv)
     char buf[BUFSIZ], **argp;
     char **arguments, *addrs[NADDRS];
 
     char buf[BUFSIZ], **argp;
     char **arguments, *addrs[NADDRS];
 
-    setlocale(LC_ALL, "");
-    invo_name = r1bindex (argv[0], '/');
-
-    /* read user profile/context */
-    context_read();
+    if (nmh_init(argv[0], 1)) { return 1; }
 
     mts_init (invo_name);
     arguments = getarguments (invo_name, argc, argv, 1);
 
     mts_init (invo_name);
     arguments = getarguments (invo_name, argc, argv, 1);
index e838422b93c7e2b636f3bd084acb7d46dd669ce1..ff5af237c60f2adba797d03b5b6d215a6343d622 100644 (file)
@@ -75,11 +75,7 @@ main (int argc, char **argv)
     struct smsg *smsgs;
     struct msgs *mp;
 
     struct smsg *smsgs;
     struct msgs *mp;
 
-    setlocale(LC_ALL, "");
-    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;
 
     arguments = getarguments (invo_name, argc, argv, 1);
     argp = arguments;
@@ -462,8 +458,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--) {
 
     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 (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);
 
        if (verbosw && i != msgnum)
            printf ("message %d of digest %d becomes message %d\n", j, msgnum, i);
index a7300c34300c647f5c6a4ea4fa081e15ec2c3f25..02feefaa445765d10c19946004b485cf5f9bb36f 100644 (file)
@@ -83,11 +83,7 @@ main (int argc, char **argv)
     struct format *fmt;
     struct stat st;
 
     struct format *fmt;
     struct stat st;
 
-    setlocale(LC_ALL, "");
-    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;
 
     arguments = getarguments (invo_name, argc, argv, 1);
     argp = arguments;
index 9174a39b7dc1eae8ed1ed50c9b51f07e230aca34..4c140022345c04285d1ac032186e2c537077c576 100644 (file)
@@ -68,12 +68,7 @@ main (int argc, char **argv)
     char *cp, **argp, **arguments;
     char buf[BUFSIZ], *akv[50];
 
     char *cp, **argp, **arguments;
     char buf[BUFSIZ], *akv[50];
 
-    setlocale(LC_ALL, "");
-    invo_name = r1bindex (argv[0], '/');
-
-    /* foil search of user profile/context */
-    if (context_foil (NULL) == -1)
-       done (1);
+    if (nmh_init(argv[0], 0 /* use context_foil() */)) { return 1; }
 
     mts_init (invo_name);
     arguments = getarguments (invo_name, argc, argv, 0);
 
     mts_init (invo_name);
     arguments = getarguments (invo_name, argc, argv, 0);
index 00503be5552edf7893365c927499a64acdf529ca..5a35e59a7385b052b918a9f3b47b81f2ac308114 100644 (file)
@@ -83,11 +83,7 @@ main (int argc, char **argv)
     struct msgs *mp = NULL;
     struct stat st;
 
     struct msgs *mp = NULL;
     struct stat st;
 
-    setlocale(LC_ALL, "");
-    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;
 
     arguments = getarguments (invo_name, argc, argv, 1);
     argp = arguments;
index d7a271209e383df2fc99f01f504e33cafebb365b..2d9239e92fd4495f627ceaf1d2896fa23af9ef25 100644 (file)
@@ -87,7 +87,7 @@ distout (char *drft, char *msgnam, char *backup)
        leave_bad: ;
                fclose (ifp);
                fclose (ofp);
        leave_bad: ;
                fclose (ifp);
                fclose (ofp);
-               unlink (drft);
+               (void) m_unlink (drft);
                if (rename (backup, drft) == NOTOK)
                    adios (drft, "unable to rename %s to", backup);
                return NOTOK;
                if (rename (backup, drft) == NOTOK)
                    adios (drft, "unable to rename %s to", backup);
                return NOTOK;
@@ -104,7 +104,7 @@ process: ;
     if (!resent) {
        advise (NULL, BADMSG, "draft");
        fclose (ofp);
     if (!resent) {
        advise (NULL, BADMSG, "draft");
        fclose (ofp);
-       unlink (drft);
+       (void) m_unlink (drft);
        if (rename (backup, drft) == NOTOK)
            adios (drft, "unable to rename %s to", backup);
        return NOTOK;
        if (rename (backup, drft) == NOTOK)
            adios (drft, "unable to rename %s to", backup);
        return NOTOK;
@@ -141,14 +141,13 @@ ready_msg (char *msgnam)
 
     cp = m_mktemp2(NULL, "dist", &hdrfd, NULL);
     if (cp == NULL) {
 
     cp = m_mktemp2(NULL, "dist", &hdrfd, NULL);
     if (cp == NULL) {
-        adios("distsbr", "unable to create temporary file");
+       adios(NULL, "unable to create temporary file in %s", get_temp_dir());
     }
     }
-    fchmod(hdrfd, 0600);
     strncpy(tmpfil, cp, sizeof(tmpfil));
     if ((out = dup (hdrfd)) == NOTOK
            || (ofp = fdopen (out, "w")) == NULL)
        adios (NULL, "no file descriptors -- you lose big");
     strncpy(tmpfil, cp, sizeof(tmpfil));
     if ((out = dup (hdrfd)) == NOTOK
            || (ofp = fdopen (out, "w")) == NULL)
        adios (NULL, "no file descriptors -- you lose big");
-    unlink (tmpfil);
+    (void) m_unlink (tmpfil);
 
     for (;;) {
        int buffersz = sizeof buffer;
 
     for (;;) {
        int buffersz = sizeof buffer;
@@ -170,14 +169,15 @@ ready_msg (char *msgnam)
 
                 cp = m_mktemp2(NULL, "dist", &txtfd, NULL);
                 if (cp == NULL) {
 
                 cp = m_mktemp2(NULL, "dist", &txtfd, NULL);
                 if (cp == NULL) {
-                    adios("distsbr", "unable to create temporary file");
+                   adios(NULL, "unable to create temporary file in %s",
+                         get_temp_dir());
                 }
                 fchmod(txtfd, 0600);
                strncpy (tmpfil, cp, sizeof(tmpfil));
                if ((out = dup (txtfd)) == NOTOK
                        || (ofp = fdopen (out, "w")) == NULL)
                    adios (NULL, "no file descriptors -- you lose big");
                 }
                 fchmod(txtfd, 0600);
                strncpy (tmpfil, cp, sizeof(tmpfil));
                if ((out = dup (txtfd)) == NOTOK
                        || (ofp = fdopen (out, "w")) == NULL)
                    adios (NULL, "no file descriptors -- you lose big");
-               unlink (tmpfil);
+               (void) m_unlink (tmpfil);
                fprintf (ofp, "\n%s", buffer);
                while (state == BODY) {
                    buffersz = sizeof buffer;
                fprintf (ofp, "\n%s", buffer);
                while (state == BODY) {
                    buffersz = sizeof buffer;
index 8245f60ad66eb06693b333ff46e8ae522de5f604..dabdd74c84adde9eb358988a2b5aa1e64def9e13 100644 (file)
--- a/uip/dp.c
+++ b/uip/dp.c
@@ -51,11 +51,7 @@ main (int argc, char **argv)
     char buf[BUFSIZ], **argp, **arguments;
     char *dates[NDATES];
 
     char buf[BUFSIZ], **argp, **arguments;
     char *dates[NDATES];
 
-    setlocale(LC_ALL, "");
-    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;
 
     arguments = getarguments (invo_name, argc, argv, 1);
     argp = arguments;
index 2cf5b598d6415d92c7053e49739f0bea0d0e6c38..da2752d12debfd1f0cb2eccde51815d4fc989812 100644 (file)
@@ -567,7 +567,7 @@ map_write (char *mailbox, int md, int id, long last, off_t start,
        clear = 1;
 
     if (!clear && map_chk (file, fd, &d1, pos, noisy)) {
        clear = 1;
 
     if (!clear && map_chk (file, fd, &d1, pos, noisy)) {
-       unlink (file);
+       (void) m_unlink (file);
        mbx_close (file, fd);
        if ((fd = map_open (file, md)) == NOTOK)
            return NOTOK;
        mbx_close (file, fd);
        if ((fd = map_open (file, md)) == NOTOK)
            return NOTOK;
index cea1ca7c3c1e940cf6faee2ac92c179264567df6..829500d625c69f0fa60e3f5fc4c053f30adb982a 100644 (file)
@@ -115,11 +115,7 @@ main(int argc, char **argv)
     char **arguments;
     char buf[BUFSIZ];
 
     char **arguments;
     char buf[BUFSIZ];
 
-    setlocale(LC_ALL, "");
-    invo_name = r1bindex(argv[0], '/');
-
-    /* read user profile/context */
-    context_read();
+    if (nmh_init(argv[0], 1)) { return 1; }
 
     /*
      * If program was invoked with name ending
 
     /*
      * If program was invoked with name ending
index 289f1e6677b23b16b4056b88b4428fbf232bb292..f1df6f35f758dd0ba292c6f127ad9a9ec479570d 100644 (file)
@@ -51,11 +51,7 @@ main (int argc, char **argv)
     char buf[BUFSIZ], *nfs, **argp, **arguments;
     struct format *fmt;
 
     char buf[BUFSIZ], *nfs, **argp, **arguments;
     struct format *fmt;
 
-    setlocale(LC_ALL, "");
-    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;
 
     arguments = getarguments (invo_name, argc, argv, 1);
     argp = arguments;
index a3a436f4ab2f8fdbd09b81f5bf956d80c4c2a650..2f45e7b5363b96b5b0f7aee34c5837f94da42615 100644 (file)
@@ -121,11 +121,7 @@ main (int argc, char **argv)
     int dat[5];
     struct fmt_callbacks cb, *cbp = NULL;
 
     int dat[5];
     struct fmt_callbacks cb, *cbp = NULL;
 
-    setlocale(LC_ALL, "");
-    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;
 
     arguments = getarguments (invo_name, argc, argv, 1);
     argp = arguments;
index a2e6a4a8afdb531174ea3a4773b419d727d6163c..98ecde68d70f27ac102083dfb6012e8e04a799a7 100644 (file)
@@ -101,11 +101,7 @@ main (int argc, char **argv)
     char *cp, *dp, *msg = NULL, *argfolder = NULL;
     char **ap, **argp, buf[BUFSIZ], **arguments;
 
     char *cp, *dp, *msg = NULL, *argfolder = NULL;
     char **ap, **argp, buf[BUFSIZ], **arguments;
 
-    setlocale(LC_ALL, "");
-    invo_name = r1bindex (argv[0], '/');
-
-    /* read user profile/context */
-    context_read();
+    if (nmh_init(argv[0], 1)) { return 1; }
 
     /*
      * If program was invoked with name ending
 
     /*
      * If program was invoked with name ending
index 9eeb6123d6864d839c73524c31e2bac2d4b78474..2139d35cffa5a8c5c1bbf17fe253f64ef4ca8d42 100644 (file)
@@ -116,14 +116,9 @@ main (int argc, char **argv)
     char **argp, **arguments;
     struct stat st;
     struct msgs_array msgs = { 0, 0, NULL };
     char **argp, **arguments;
     struct stat st;
     struct msgs_array msgs = { 0, 0, NULL };
-
     int buildsw = 0;
 
     int buildsw = 0;
 
-    setlocale(LC_ALL, "");
-    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;
 
     arguments = getarguments (invo_name, argc, argv, 1);
     argp = arguments;
index 48fecb179a6b05f50463e004bf499c2988ff435c..295507d61482ee426f000f8c2b1166228593543d 100644 (file)
@@ -174,9 +174,11 @@ finished:
     }
 
     cp = m_mktemp2(NULL, invo_name, NULL, &tmp);
     }
 
     cp = m_mktemp2(NULL, invo_name, NULL, &tmp);
-    if (cp == NULL) adios("forw", "unable to create temporary file");
+    if (cp == NULL) {
+       adios(NULL, "unable to create temporary file in %s", get_temp_dir());
+    }
     strncpy (tmpfil, cp, sizeof(tmpfil));
     strncpy (tmpfil, cp, sizeof(tmpfil));
-    unlink (tmpfil);
+    (void) m_unlink (tmpfil);
     if ((in = dup (fileno (tmp))) == NOTOK)
        adios ("dup", "unable to");
 
     if ((in = dup (fileno (tmp))) == NOTOK)
        adios ("dup", "unable to");
 
index 3aa5e50fde06fbf4e579d2bdac13a1e5b741c89e..b76f1cd96d8d04bf33b646ba479b9559a6a9f287 100644 (file)
--- a/uip/inc.c
+++ b/uip/inc.c
@@ -197,11 +197,7 @@ main (int argc, char **argv)
     SAVEGROUPPRIVS();
     TRYDROPGROUPPRIVS();
 
     SAVEGROUPPRIVS();
     TRYDROPGROUPPRIVS();
 
-    setlocale(LC_ALL, "");
-    invo_name = r1bindex (argv[0], '/');
-
-    /* read user profile/context */
-    context_read();
+    if (nmh_init(argv[0], 1)) { return 1; }
 
     mts_init (invo_name);
     arguments = getarguments (invo_name, argc, argv, 1);
 
     mts_init (invo_name);
     arguments = getarguments (invo_name, argc, argv, 1);
@@ -660,7 +656,7 @@ go_to_it:
            } else {
                if (ferror(pf) || fclose (pf)) {
                    int e = errno;
            } else {
                if (ferror(pf) || fclose (pf)) {
                    int e = errno;
-                   unlink (cp);
+                   (void) m_unlink (cp);
                    pop_quit ();
                    errno = e;
                    adios (cp, "write error on");
                    pop_quit ();
                    errno = e;
                    adios (cp, "write error on");
@@ -755,7 +751,7 @@ go_to_it:
                        break;
                if (ferror(sf) || fflush(pf) || ferror(pf)) {
                        int e = errno;
                        break;
                if (ferror(sf) || fflush(pf) || ferror(pf)) {
                        int e = errno;
-                       fclose(pf); fclose(sf); unlink(cp);
+                       fclose(pf); fclose(sf); (void) m_unlink(cp);
                        errno = e;
                        adios(cp, "copy error %s -> %s", sp, cp);
                }
                        errno = e;
                        adios(cp, "copy error %s -> %s", sp, cp);
                }
@@ -802,14 +798,14 @@ go_to_it:
            }
            if (ferror(pf) || fclose (pf)) {
                int e = errno;
            }
            if (ferror(pf) || fclose (pf)) {
                int e = errno;
-               unlink (cp);
+               (void) m_unlink (cp);
                errno = e;
                adios (cp, "write error on");
            }
            pf = NULL;
            free (cp);
 
                errno = e;
                adios (cp, "write error on");
            }
            pf = NULL;
            free (cp);
 
-           if (trnflag && unlink (sp) == NOTOK)
+           if (trnflag && m_unlink (sp) == NOTOK)
                adios (sp, "couldn't unlink");
            free (sp); /* Free Maildir[i]->filename */
        }
                adios (sp, "couldn't unlink");
            free (sp); /* Free Maildir[i]->filename */
        }
@@ -851,7 +847,7 @@ go_to_it:
                    close (newfd);
                else
                    admonish (newmail, "error zero'ing");
                    close (newfd);
                else
                    admonish (newmail, "error zero'ing");
-               unlink(map_name(newmail));
+               (void) m_unlink(map_name(newmail));
            }
        } else {
            if (noisy)
            }
        } else {
            if (noisy)
index 0fc97c45353f3f63d1a7ed039dc8ee8c7994e068..12377352a8c71ea6c4ca5fc824602d938fc4d0f2 100644 (file)
@@ -42,8 +42,8 @@ main (int argc, char **argv)
     FILE *in, *out;
     int                check;
 
     FILE *in, *out;
     int                check;
 
-    setlocale(LC_ALL, "");
-    invo_name = r1bindex (argv[0], '/');
+    if (nmh_init(argv[0], 0 /* use context_foil() */ )) { return 1; }
+
     arguments = getarguments (invo_name, argc, argv, 0);
     argp = arguments;
 
     arguments = getarguments (invo_name, argc, argv, 0);
     argp = arguments;
 
index 439ea40703ab080888eeb48e408d25fd126860cd..da25f0b376bfe3e36a8d04aac1d063f61f52b2de 100644 (file)
@@ -52,11 +52,7 @@ main (int argc, char **argv)
     struct msgs_array msgs = { 0, 0, NULL };
     struct msgs *mp;
 
     struct msgs_array msgs = { 0, 0, NULL };
     struct msgs *mp;
 
-    setlocale(LC_ALL, "");
-    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;
 
     arguments = getarguments (invo_name, argc, argv, 1);
     argp = arguments;
index 85b5a21b369a012d0bc151dd499e268b3a792a9d..de849a39549fee0e89385daaaedc4d1ce6aec24b 100644 (file)
@@ -66,9 +66,6 @@ DEFINE_SWITCH_ENUM(MIMEENCODING);
 DEFINE_SWITCH_ARRAY(MIMEENCODING, encodingswitches);
 #undef X
 
 DEFINE_SWITCH_ARRAY(MIMEENCODING, encodingswitches);
 #undef X
 
-/* mhbuildsbr.c */
-extern char *tmp;      /* directory to place temp files */
-
 /* mhcachesbr.c */
 extern int rcachesw;
 extern int wcachesw;
 /* mhcachesbr.c */
 extern int rcachesw;
 extern int wcachesw;
@@ -114,13 +111,9 @@ main (int argc, char **argv)
     FILE *fp_out = NULL;
     int header_encoding = CE_UNKNOWN;
 
     FILE *fp_out = NULL;
     int header_encoding = CE_UNKNOWN;
 
-    done=unlink_done;
-
-    setlocale(LC_ALL, "");
-    invo_name = r1bindex (argv[0], '/');
+    if (nmh_init(argv[0], 1)) { return 1; }
 
 
-    /* read user profile/context */
-    context_read();
+    done=unlink_done;
 
     arguments = getarguments (invo_name, argc, argv, 1);
     argp = arguments;
 
     arguments = getarguments (invo_name, argc, argv, 1);
     argp = arguments;
@@ -309,16 +302,6 @@ main (int argc, char **argv)
        cache_private = ".cache";
     cache_private = getcpy (m_maildir (cache_private));
 
        cache_private = ".cache";
     cache_private = getcpy (m_maildir (cache_private));
 
-    /*
-     * Check for storage directory.  If defined, we
-     * will store temporary files there.  Else we
-     * store them in standard nmh directory.
-     */
-    if ((cp = context_find (nmhstorage)) && *cp)
-       tmp = concat (cp, "/", invo_name, NULL);
-    else
-       tmp = add (m_maildir (invo_name), NULL);
-
     if (!context_find ("path"))
        free (path ("./", TFOLDER));
 
     if (!context_find ("path"))
        free (path ("./", TFOLDER));
 
@@ -330,8 +313,13 @@ main (int argc, char **argv)
      * Process the composition file from standard input.
      */
     if (compfile[0] == '-' && compfile[1] == '\0') {
      * Process the composition file from standard input.
      */
     if (compfile[0] == '-' && compfile[1] == '\0') {
+       if ((cp = m_mktemp2(NULL, invo_name, NULL, &fp)) == NULL) {
+           adios(NULL, "unable to create temporary file in %s",
+                 get_temp_dir());
+       }
+
        /* copy standard input to temporary file */
        /* copy standard input to temporary file */
-       strncpy (infile, m_mktemp(invo_name, NULL, &fp), sizeof(infile));
+       strncpy (infile, cp, sizeof(infile));
        while (fgets (buffer, BUFSIZ, stdin))
            fputs (buffer, fp);
        fclose (fp);
        while (fgets (buffer, BUFSIZ, stdin))
            fputs (buffer, fp);
        fclose (fp);
@@ -357,7 +345,7 @@ main (int argc, char **argv)
            free_content (ct);
        }
 
            free_content (ct);
        }
 
-       unlink (infile);
+       (void) m_unlink (infile);
        unlink_infile = 0;
 
        done (0);
        unlink_infile = 0;
 
        done (0);
@@ -382,8 +370,10 @@ main (int argc, char **argv)
     cts[1] = NULL;
 
     /* output MIME message to this temporary file */
     cts[1] = NULL;
 
     /* output MIME message to this temporary file */
-    strncpy(outfile, m_mktemp2(compfile, invo_name, NULL, &fp_out),
-            sizeof(outfile));
+    if ((cp = m_mktemp2(compfile, invo_name, NULL, &fp_out)) == NULL) {
+       adios(NULL, "unable to create temporary file in %s", get_temp_dir());
+    }
+    strncpy(outfile, cp, sizeof(outfile));
     unlink_outfile = 1;
 
     /* output the message */
     unlink_outfile = 1;
 
     /* output the message */
@@ -424,9 +414,9 @@ unlink_done (int status)
      * temporary files.
      */
     if (unlink_infile)
      * temporary files.
      */
     if (unlink_infile)
-       unlink (infile);
+       (void) m_unlink (infile);
     if (unlink_outfile)
     if (unlink_outfile)
-       unlink (outfile);
+       (void) m_unlink (outfile);
 
     exit (status);
 }
 
     exit (status);
 }
index e5909229ca85fbd8500ad402be66eaf7a0468323..70747c85ee93a35fca37d17d698e61367ee9bd38 100644 (file)
@@ -42,12 +42,6 @@ extern int contentidsw;
 extern int rcachesw;   /* mhcachesbr.c */
 extern int wcachesw;   /* mhcachesbr.c */
 
 extern int rcachesw;   /* mhcachesbr.c */
 extern int wcachesw;   /* mhcachesbr.c */
 
-/*
- * Directory to place tmp files.  This must
- * be set before these routines are called.
- */
-char *tmp;
-
 pid_t xpid = 0;
 
 static char prefix[] = "----- =_aaaaaaaaaa";
 pid_t xpid = 0;
 
 static char prefix[] = "----- =_aaaaaaaaaa";
@@ -580,8 +574,10 @@ user_content (FILE *in, char *buf, CT *ctp)
        FILE *out;
         char *cp;
 
        FILE *out;
         char *cp;
 
-        cp = m_mktemp2(NULL, invo_name, NULL, &out);
-        if (cp == NULL) adios("mhbuildsbr", "unable to create temporary file");
+       if ((cp = m_mktemp2(NULL, invo_name, NULL, &out)) == NULL) {
+           adios("mhbuildsbr", "unable to create temporary file in %s",
+                 get_temp_dir());
+       }
 
        /* use a temp file to collect the plain text lines */
        ce->ce_file = add (cp, NULL);
 
        /* use a temp file to collect the plain text lines */
        ce->ce_file = add (cp, NULL);
@@ -1140,10 +1136,10 @@ compose_content (CT ct)
            if (!(cp = ci->ci_magic))
                adios (NULL, "internal error(5)");
 
            if (!(cp = ci->ci_magic))
                adios (NULL, "internal error(5)");
 
-            tfile = m_mktemp2(NULL, invo_name, NULL, NULL);
-            if (tfile == NULL) {
-                adios("mhbuildsbr", "unable to create temporary file");
-            }
+           if ((tfile = m_mktemp2(NULL, invo_name, NULL, NULL)) == NULL) {
+               adios("mhbuildsbr", "unable to create temporary file in %s",
+                     get_temp_dir());
+           }
            ce->ce_file = add (tfile, NULL);
            ce->ce_unlink = 1;
 
            ce->ce_file = add (tfile, NULL);
            ce->ce_unlink = 1;
 
index 0bf725c686718fca40882a7bea70662f77a1e0bb..136b567807e6c9b84506b8dda4ba3982d57aa238 100644 (file)
@@ -143,11 +143,11 @@ cache_content (CT ct)
 
            if (ferror (gp)) {
                admonish (ce->ce_file, "error reading");
 
            if (ferror (gp)) {
                admonish (ce->ce_file, "error reading");
-               unlink (cachefile);
+               (void) m_unlink (cachefile);
            } else {
                if (ferror (fp)) {
                    admonish (cachefile, "error writing");
            } else {
                if (ferror (fp)) {
                    admonish (cachefile, "error writing");
-                   unlink (cachefile);
+                   (void) m_unlink (cachefile);
                }
            }
            fclose (fp);
                }
            }
            fclose (fp);
@@ -273,7 +273,7 @@ got_it:
     if (status == OK && writing) {
        if (*writing && strchr(buffer, '/'))
            make_intermediates (buffer);
     if (status == OK && writing) {
        if (*writing && strchr(buffer, '/'))
            make_intermediates (buffer);
-       unlink (buffer);
+       (void) m_unlink (buffer);
     }
 
     free (id);
     }
 
     free (id);
index bafd78e261f927bc98d750a2cabe041f8adb5588..201625087d44427126a6117ebf7860948768fbe9 100644 (file)
@@ -53,7 +53,6 @@ int debugsw; /* Needed by mhparse.c. */
 #define quitser pipeser
 
 /* mhparse.c */
 #define quitser pipeser
 
 /* mhparse.c */
-extern char *tmp;                             /* directory to place tmp files */
 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 */
 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 */
@@ -135,13 +134,9 @@ main (int argc, char **argv) {
     fx.decodetext = CE_8BIT;
     fx.textcodeset = NULL;
 
     fx.decodetext = CE_8BIT;
     fx.textcodeset = NULL;
 
-    done = freects_done;
-
-    setlocale(LC_ALL, "");
-    invo_name = r1bindex (argv[0], '/');
+    if (nmh_init(argv[0], 1)) { return 1; }
 
 
-    /* read user profile/context */
-    context_read();
+    done = freects_done;
 
     arguments = getarguments (invo_name, argc, argv, 1);
     argp = arguments;
 
     arguments = getarguments (invo_name, argc, argv, 1);
     argp = arguments;
@@ -264,16 +259,6 @@ main (int argc, char **argv) {
         fclose (fp);
     }
 
         fclose (fp);
     }
 
-    /*
-     * Check for storage directory.  If specified,
-     * then store temporary files there.  Else we
-     * store them in standard nmh directory.
-     */
-    if ((cp = context_find (nmhstorage)) && *cp)
-        tmp = concat (cp, "/", invo_name, NULL);
-    else
-        tmp = add (m_maildir (invo_name), NULL);
-
     suppress_bogus_mp_content_warning = skip_mp_cte_check = 1;
 
     if (! context_find ("path"))
     suppress_bogus_mp_content_warning = skip_mp_cte_check = 1;
 
     if (! context_find ("path"))
@@ -298,17 +283,17 @@ main (int argc, char **argv) {
 
             using_stdin = 1;
 
 
             using_stdin = 1;
 
-            if ((cp = m_mktemp2 (tmp, invo_name, &fd, NULL)) == NULL) {
-                adios (NULL, "unable to create temporary file");
+            if ((cp = m_mktemp2 (NULL, invo_name, &fd, NULL)) == NULL) {
+                adios (NULL, "unable to create temporary file in %s",
+                       get_temp_dir());
             } else {
                 free (file);
                 file = add (cp, NULL);
             } else {
                 free (file);
                 file = add (cp, NULL);
-                chmod (file, 0600);
                 cpydata (STDIN_FILENO, fd, "-", file);
             }
 
             if (close (fd)) {
                 cpydata (STDIN_FILENO, fd, "-", file);
             }
 
             if (close (fd)) {
-                unlink (file);
+                (void) m_unlink (file);
                 adios (NULL, "failed to write temporary file");
             }
         }
                 adios (NULL, "failed to write temporary file");
             }
         }
@@ -371,7 +356,7 @@ main (int argc, char **argv) {
             status += mhfixmsgsbr (ctp, &fx, outfile);
 
             if (using_stdin) {
             status += mhfixmsgsbr (ctp, &fx, outfile);
 
             if (using_stdin) {
-                unlink (file);
+                (void) m_unlink (file);
 
                 if (! outfile) {
                     /* Just calling m_backup() unlinks the backup file. */
 
                 if (! outfile) {
                     /* Just calling m_backup() unlinks the backup file. */
@@ -384,7 +369,6 @@ main (int argc, char **argv) {
     }
 
     free (outfile);
     }
 
     free (outfile);
-    free (tmp);
     free (file);
 
     /* done is freects_done, which will clean up all of cts. */
     free (file);
 
     /* done is freects_done, which will clean up all of cts. */
@@ -406,7 +390,12 @@ mhfixmsgsbr (CT *ctp, const fix_transformations *fx, char *outfile) {
         modify_inplace = 1;
 
         if ((*ctp)->c_file) {
         modify_inplace = 1;
 
         if ((*ctp)->c_file) {
-            outfile = add (m_mktemp2 (tmp, invo_name, NULL, NULL), NULL);
+            char *tempfile;
+            if ((tempfile = m_mktemp2 (NULL, invo_name, NULL, NULL)) == NULL) {
+                adios (NULL, "unable to create temporary file in %s",
+                       get_temp_dir());
+            }
+            outfile = add (tempfile, NULL);
         } else {
             adios (NULL, "missing both input and output filenames\n");
         }
         } else {
             adios (NULL, "missing both input and output filenames\n");
         }
@@ -468,7 +457,7 @@ mhfixmsgsbr (CT *ctp, const fix_transformations *fx, char *outfile) {
     }
 
     if (modify_inplace) {
     }
 
     if (modify_inplace) {
-        if (status != OK) unlink (outfile);
+        if (status != OK) (void) m_unlink (outfile);
         free (outfile);
         outfile = NULL;
     }
         free (outfile);
         outfile = NULL;
     }
@@ -524,7 +513,7 @@ fix_boundary (CT *ct, int *message_mods) {
             if (get_multipart_boundary (*ct, &part_boundary) == OK) {
                 char *fixed;
 
             if (get_multipart_boundary (*ct, &part_boundary) == OK) {
                 char *fixed;
 
-                if ((fixed = m_mktemp2 (tmp, invo_name, NULL, &(*ct)->c_fp))) {
+                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);
 
                     if (replace_boundary (*ct, fixed, part_boundary) == OK) {
                         char *filename = add ((*ct)->c_file, NULL);
 
@@ -544,7 +533,8 @@ fix_boundary (CT *ct, int *message_mods) {
                         status = NOTOK;
                     }
                 } else {
                         status = NOTOK;
                     }
                 } else {
-                    advise (NULL, "unable to create temporary file");
+                    advise (NULL, "unable to create temporary file in %s",
+                            get_temp_dir());
                     status = NOTOK;
                 }
 
                     status = NOTOK;
                 }
 
@@ -1029,7 +1019,13 @@ build_text_plain_part (CT encoded_part) {
            contains the decoded contents.  And the decoding function, such
            as openQuoted, will have set ...->ce_unlink to 1 so that it will
            be unlinked by free_content (). */
            contains the decoded contents.  And the decoding function, such
            as openQuoted, will have set ...->ce_unlink to 1 so that it will
            be unlinked by free_content (). */
-        tmp_plain_file = add (m_mktemp2 (tmp, invo_name, NULL, NULL), NULL);
+        char *tempfile;
+
+        if ((tempfile = m_mktemp2 (NULL, invo_name, NULL, NULL)) == NULL) {
+            advise (NULL, "unable to create temporary file in %s",
+                    get_temp_dir());
+        }
+        tmp_plain_file = add (tempfile, NULL);
         if (reformat_part (tp_part, tmp_plain_file,
                            tp_part->c_ctinfo.ci_type,
                            tp_part->c_ctinfo.ci_subtype,
         if (reformat_part (tp_part, tmp_plain_file,
                            tp_part->c_ctinfo.ci_type,
                            tp_part->c_ctinfo.ci_subtype,
@@ -1039,7 +1035,7 @@ build_text_plain_part (CT encoded_part) {
     }
 
     free_content (tp_part);
     }
 
     free_content (tp_part);
-    unlink (tmp_plain_file);
+    (void) m_unlink (tmp_plain_file);
     free (tmp_plain_file);
 
     return NULL;
     free (tmp_plain_file);
 
     return NULL;
@@ -1100,13 +1096,17 @@ static int
 decode_part (CT ct) {
     char *tmp_decoded;
     int status;
 decode_part (CT ct) {
     char *tmp_decoded;
     int status;
+    char *tempfile;
 
 
-    tmp_decoded = add (m_mktemp2 (tmp, invo_name, NULL, NULL), NULL);
+    if ((tempfile = m_mktemp2 (NULL, invo_name, NULL, NULL)) == NULL) {
+        adios (NULL, "unable to create temporary file in %s", get_temp_dir());
+    }
+    tmp_decoded = add (tempfile, NULL);
     /* The following call will load ct->c_cefile.ce_file with the tmp
        filename of the decoded content.  tmp_decoded will contain the
        encoded output, get rid of that. */
     status = output_message (ct, tmp_decoded);
     /* The following call will load ct->c_cefile.ce_file with the tmp
        filename of the decoded content.  tmp_decoded will contain the
        encoded output, get rid of that. */
     status = output_message (ct, tmp_decoded);
-    unlink (tmp_decoded);
+    (void) m_unlink (tmp_decoded);
     free (tmp_decoded);
 
     return status;
     free (tmp_decoded);
 
     return status;
@@ -1166,7 +1166,7 @@ reformat_part (CT ct, char *file, char *type, char *subtype, int c_type) {
     /* Unlink decoded content tmp file and free its filename to avoid
        leaks.  The file stream should already have been closed. */
     if (ct->c_cefile.ce_unlink) {
     /* Unlink decoded content tmp file and free its filename to avoid
        leaks.  The file stream should already have been closed. */
     if (ct->c_cefile.ce_unlink) {
-        unlink (ct->c_cefile.ce_file);
+        (void) m_unlink (ct->c_cefile.ce_file);
         free (ct->c_cefile.ce_file);
         ct->c_cefile.ce_file = NULL;
         ct->c_cefile.ce_unlink = 0;
         free (ct->c_cefile.ce_file);
         ct->c_cefile.ce_file = NULL;
         ct->c_cefile.ce_unlink = 0;
@@ -1486,7 +1486,7 @@ decode_text_parts (CT ct, int encoding, int *message_mods) {
                                               :  ct->c_ctline  ?  ct->c_ctline
                                                                :  "");
                     }
                                               :  ct->c_ctline  ?  ct->c_ctline
                                                                :  "");
                     }
-                    unlink (ct->c_cefile.ce_file);
+                    (void) m_unlink (ct->c_cefile.ce_file);
                     free (ct->c_cefile.ce_file);
                     ct->c_cefile.ce_file = NULL;
                 } else if (ct->c_encoding == CE_QUOTED  &&
                     free (ct->c_cefile.ce_file);
                     ct->c_cefile.ce_file = NULL;
                 } else if (ct->c_encoding == CE_QUOTED  &&
@@ -1500,7 +1500,7 @@ decode_text_parts (CT ct, int encoding, int *message_mods) {
                                               :  ct->c_ctline  ?  ct->c_ctline
                                                                :  "");
                     }
                                               :  ct->c_ctline  ?  ct->c_ctline
                                                                :  "");
                     }
-                    unlink (ct->c_cefile.ce_file);
+                    (void) m_unlink (ct->c_cefile.ce_file);
                     free (ct->c_cefile.ce_file);
                     ct->c_cefile.ce_file = NULL;
                 } else {
                     free (ct->c_cefile.ce_file);
                     ct->c_cefile.ce_file = NULL;
                 } else {
@@ -1689,8 +1689,14 @@ strip_crs (CT ct, int *message_mods) {
 
             if (has_crs) {
                 int fd;
 
             if (has_crs) {
                 int fd;
-                char *stripped_content_file =
-                    add (m_mktemp2 (tmp, invo_name, &fd, NULL), NULL);
+                char *stripped_content_file;
+                char *tempfile = m_mktemp2 (NULL, invo_name, &fd, NULL); 
+
+                if (tempfile == NULL) {
+                    adios (NULL, "unable to create temporary file in %s",
+                           get_temp_dir());
+                }
+                stripped_content_file = add (tempfile, NULL);
 
                 /* Strip each CR before a LF from the content. */
                 fseeko (*fp, begin, SEEK_SET);
 
                 /* Strip each CR before a LF from the content. */
                 fseeko (*fp, begin, SEEK_SET);
@@ -1717,13 +1723,13 @@ strip_crs (CT ct, int *message_mods) {
                 if (close (fd)) {
                     admonish (NULL, "unable to write temporary file %s",
                               stripped_content_file);
                 if (close (fd)) {
                     admonish (NULL, "unable to write temporary file %s",
                               stripped_content_file);
-                    unlink (stripped_content_file);
+                    (void) m_unlink (stripped_content_file);
                     status = NOTOK;
                 } else {
                     /* Replace the decoded file with the converted one. */
                     if (ct->c_cefile.ce_file) {
                         if (ct->c_cefile.ce_unlink) {
                     status = NOTOK;
                 } else {
                     /* Replace the decoded file with the converted one. */
                     if (ct->c_cefile.ce_file) {
                         if (ct->c_cefile.ce_unlink) {
-                            unlink (ct->c_cefile.ce_file);
+                            (void) m_unlink (ct->c_cefile.ce_file);
                         }
                         free (ct->c_cefile.ce_file);
                     }
                         }
                         free (ct->c_cefile.ce_file);
                     }
@@ -1842,6 +1848,7 @@ convert_codeset (CT ct, char *dest_codeset, int *message_mods) {
         int opened_input_file = 0;
         char src_buffer[BUFSIZ];
         HF hf;
         int opened_input_file = 0;
         char src_buffer[BUFSIZ];
         HF hf;
+        char *tempfile;
 
         if ((conv_desc = iconv_open (dest_codeset, src_codeset)) ==
             (iconv_t) -1) {
 
         if ((conv_desc = iconv_open (dest_codeset, src_codeset)) ==
             (iconv_t) -1) {
@@ -1849,7 +1856,11 @@ convert_codeset (CT ct, char *dest_codeset, int *message_mods) {
             return -1;
         }
 
             return -1;
         }
 
-        dest = add (m_mktemp2 (tmp, invo_name, &fd, NULL), NULL);
+        if ((tempfile = m_mktemp2 (NULL, invo_name, &fd, NULL)) == NULL) {
+            adios (NULL, "unable to create temporary file in %s",
+                   get_temp_dir());
+        }
+        dest = add (tempfile, NULL);
 
         if (ct->c_cefile.ce_file) {
             file = &ct->c_cefile.ce_file;
 
         if (ct->c_cefile.ce_file) {
             file = &ct->c_cefile.ce_file;
@@ -1912,7 +1923,7 @@ convert_codeset (CT ct, char *dest_codeset, int *message_mods) {
             /* Replace the decoded file with the converted one. */
             if (ct->c_cefile.ce_file) {
                 if (ct->c_cefile.ce_unlink) {
             /* Replace the decoded file with the converted one. */
             if (ct->c_cefile.ce_file) {
                 if (ct->c_cefile.ce_unlink) {
-                    unlink (ct->c_cefile.ce_file);
+                    (void) m_unlink (ct->c_cefile.ce_file);
                 }
                 free (ct->c_cefile.ce_file);
             }
                 }
                 free (ct->c_cefile.ce_file);
             }
@@ -1951,7 +1962,7 @@ convert_codeset (CT ct, char *dest_codeset, int *message_mods) {
                 }
             }
         } else {
                 }
             }
         } else {
-            unlink (dest);
+            (void) m_unlink (dest);
         }
 #else  /* ! HAVE_ICONV */
         NMH_UNUSED (message_mods);
         }
 #else  /* ! HAVE_ICONV */
         NMH_UNUSED (message_mods);
@@ -2001,7 +2012,7 @@ write_content (CT ct, char *input_filename, char *outfile, int modify_inplace,
                         }
                         if (new != -1) close (new);
                         if (old != -1) close (old);
                         }
                         if (new != -1) close (new);
                         if (old != -1) close (old);
-                        unlink (outfile);
+                        (void) m_unlink (outfile);
 
                         if (i < 0) {
                             /* The -file argument processing used path() to
 
                         if (i < 0) {
                             /* The -file argument processing used path() to
@@ -2017,7 +2028,7 @@ write_content (CT ct, char *input_filename, char *outfile, int modify_inplace,
                 } else {
                     admonish (NULL, "unable to remove input file %s, "
                               "not modifying it", infile);
                 } else {
                     admonish (NULL, "unable to remove input file %s, "
                               "not modifying it", infile);
-                    unlink (outfile);
+                    (void) m_unlink (outfile);
                     status = NOTOK;
                 }
 
                     status = NOTOK;
                 }
 
@@ -2027,7 +2038,7 @@ write_content (CT ct, char *input_filename, char *outfile, int modify_inplace,
             }
         } else {
             /* No modifications and didn't need the tmp outfile. */
             }
         } else {
             /* No modifications and didn't need the tmp outfile. */
-            unlink (outfile);
+            (void) m_unlink (outfile);
         }
     } else {
         /* Output is going to some file.  Produce it whether or not
         }
     } else {
         /* Output is going to some file.  Produce it whether or not
index 5fa2a59cfa3bc1ff3059aede1c28d8748e21a0f1..29756876fdd11637a6cbafccd03d1a7191a05123 100644 (file)
@@ -106,7 +106,7 @@ free_content (CT ct)
 
     if (ct->c_file) {
        if (ct->c_unlink)
 
     if (ct->c_file) {
        if (ct->c_unlink)
-           unlink (ct->c_file);
+           (void) m_unlink (ct->c_file);
        free (ct->c_file);
     }
     if (ct->c_fp)
        free (ct->c_file);
     }
     if (ct->c_fp)
@@ -270,7 +270,7 @@ free_encoding (CT ct, int toplevel)
 
     if (ce->ce_file) {
        if (ce->ce_unlink)
 
     if (ce->ce_file) {
        if (ce->ce_unlink)
-           unlink (ce->ce_file);
+           (void) m_unlink (ce->ce_file);
        free (ce->ce_file);
        ce->ce_file = NULL;
     }
        free (ce->ce_file);
        ce->ce_file = NULL;
     }
index d4c5308b39483f243adccefbf101d885a1e65776..652fb11b1d01adbc61dfa2d680a3f1037daca919 100644 (file)
--- a/uip/mhl.c
+++ b/uip/mhl.c
@@ -13,7 +13,8 @@
 int
 main (int argc, char **argv)
 {
 int
 main (int argc, char **argv)
 {
-    setlocale(LC_ALL, "");
+    if (nmh_init(argv[0], 1)) { return 1; }
+
     done (mhl (argc, argv));
     return 1;
 }
     done (mhl (argc, argv));
     return 1;
 }
index 7092434895a57f34375cd137495c427dbdbc5440..f37041c38f1cb07d01b52a4595296535e3c479c7 100644 (file)
@@ -47,9 +47,6 @@ DEFINE_SWITCH_ARRAY(MHLIST, switches);
 #undef X
 
 
 #undef X
 
 
-/* mhparse.c */
-extern char *tmp;      /* directory to place temp files */
-
 /* mhcachesbr.c */
 extern int rcachesw;
 extern int wcachesw;
 /* mhcachesbr.c */
 extern int rcachesw;
 extern int wcachesw;
@@ -107,13 +104,9 @@ main (int argc, char **argv)
     struct msgs *mp = NULL;
     CT ct, *ctp;
 
     struct msgs *mp = NULL;
     CT ct, *ctp;
 
-    done=freects_done;
-
-    setlocale(LC_ALL, "");
-    invo_name = r1bindex (argv[0], '/');
+    if (nmh_init(argv[0], 1)) { return 1; }
 
 
-    /* read user profile/context */
-    context_read();
+    done=freects_done;
 
     arguments = getarguments (invo_name, argc, argv, 1);
     argp = arguments;
 
     arguments = getarguments (invo_name, argc, argv, 1);
     argp = arguments;
@@ -243,16 +236,6 @@ do_cache:
        cache_private = ".cache";
     cache_private = getcpy (m_maildir (cache_private));
 
        cache_private = ".cache";
     cache_private = getcpy (m_maildir (cache_private));
 
-    /*
-     * Check for storage directory.  If specified,
-     * then store temporary files there.  Else we
-     * store them in standard nmh directory.
-     */
-    if ((cp = context_find (nmhstorage)) && *cp)
-       tmp = concat (cp, "/", invo_name, NULL);
-    else
-       tmp = add (m_maildir (invo_name), NULL);
-
     if (!context_find ("path"))
        free (path ("./", TFOLDER));
 
     if (!context_find ("path"))
        free (path ("./", TFOLDER));
 
index 6a1c3db7878ef0e2121c1bc25c8c30fda167e073..f4df180abfb59927e355482b00d3446b25a864aa 100644 (file)
@@ -349,11 +349,6 @@ mhl (int argc, char **argv)
     char buf[BUFSIZ], *files[MAXARGS];
     char **argp, **arguments;
 
     char buf[BUFSIZ], *files[MAXARGS];
     char **argp, **arguments;
 
-    invo_name = r1bindex (argv[0], '/');
-
-    /* read user profile/context */
-    context_read();
-
     arguments = getarguments (invo_name, argc, argv, 1);
     argp = arguments;
 
     arguments = getarguments (invo_name, argc, argv, 1);
     argp = arguments;
 
index 06aeee53019ef9fc536cad488a40e1afd82cb4c2..08405d4d009dbd6f6bcc22f4f19c5d0abf3882c7 100644 (file)
--- a/uip/mhn.c
+++ b/uip/mhn.c
@@ -77,9 +77,6 @@ DEFINE_SWITCH_ARRAY(MHN, switches);
 #undef X
 
 
 #undef X
 
 
-/* mhparse.c */
-extern char *tmp;      /* directory to place temp files */
-
 /* mhcachesbr.c */
 extern int rcachesw;
 extern int wcachesw;
 /* mhcachesbr.c */
 extern int rcachesw;
 extern int wcachesw;
@@ -167,13 +164,9 @@ main (int argc, char **argv)
     CT ct, *ctp;
     FILE *fp;
 
     CT ct, *ctp;
     FILE *fp;
 
-    done=freects_done;
-
-    setlocale(LC_ALL, "");
-    invo_name = r1bindex (argv[0], '/');
+    if (nmh_init(argv[0], 1)) { return 1; }
 
 
-    /* read user profile/context */
-    context_read();
+    done=freects_done;
 
     arguments = getarguments (invo_name, argc, argv, 1);
     argp = arguments;
 
     arguments = getarguments (invo_name, argc, argv, 1);
     argp = arguments;
@@ -411,16 +404,6 @@ do_cache:
      */
     cwd = getcpy (pwd());
 
      */
     cwd = getcpy (pwd());
 
-    /*
-     * Check for storage directory.  If specified,
-     * then store temporary files there.  Else we
-     * store them in standard nmh directory.
-     */
-    if ((cp = context_find (nmhstorage)) && *cp)
-       tmp = concat (cp, "/", invo_name, NULL);
-    else
-       tmp = add (m_maildir (invo_name), NULL);
-
     if (!context_find ("path"))
        free (path ("./", TFOLDER));
 
     if (!context_find ("path"))
        free (path ("./", TFOLDER));
 
index b0c119cfa4365a676536d62e9ffc93fbe32c8672..8a276f72402b50ef0a5200903fe74314fc38fb0a 100644 (file)
@@ -131,10 +131,7 @@ main(int argc, char **argv)
     char *cp, buf[BUFSIZ], **argp;
     char **arguments, *comps[MAXARGS];
 
     char *cp, buf[BUFSIZ], **argp;
     char **arguments, *comps[MAXARGS];
 
-    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;
 
     arguments = getarguments (invo_name, argc, argv, 1);
     argp = arguments;
index 5e35cbbf5c77e49881765681d17453a38e766914..716a22f73144de4b8436883d9cfe87c9d2c41459 100644 (file)
@@ -28,12 +28,6 @@ extern int wcachesw; /* mhcachesbr.c */
 
 int checksw = 0;       /* check Content-MD5 field */
 
 
 int checksw = 0;       /* check Content-MD5 field */
 
-/*
- * Directory to place temp files.  This must
- * be set before these routines are called.
- */
-char *tmp;
-
 /*
  * These are for mhfixmsg to:
  * 1) Instruct parser not to detect invalid Content-Transfer-Encoding
 /*
  * These are for mhfixmsg to:
  * 1) Instruct parser not to detect invalid Content-Transfer-Encoding
@@ -200,23 +194,23 @@ parse_mime (char *file)
     if ((is_stdin = !(strcmp (file, "-")))) {
         char *tfile = m_mktemp2(NULL, invo_name, NULL, &fp);
         if (tfile == NULL) {
     if ((is_stdin = !(strcmp (file, "-")))) {
         char *tfile = m_mktemp2(NULL, invo_name, NULL, &fp);
         if (tfile == NULL) {
-            advise("mhparse", "unable to create temporary file");
+            advise("mhparse", "unable to create temporary file in %s",
+                  get_temp_dir());
             return NULL;
         }
        file = add (tfile, NULL);
             return NULL;
         }
        file = add (tfile, NULL);
-       chmod (file, 0600);
 
        while (fgets (buffer, sizeof(buffer), stdin))
            fputs (buffer, fp);
        fflush (fp);
 
        if (ferror (stdin)) {
 
        while (fgets (buffer, sizeof(buffer), stdin))
            fputs (buffer, fp);
        fflush (fp);
 
        if (ferror (stdin)) {
-           unlink (file);
+           (void) m_unlink (file);
            advise ("stdin", "error reading");
            return NULL;
        }
        if (ferror (fp)) {
            advise ("stdin", "error reading");
            return NULL;
        }
        if (ferror (fp)) {
-           unlink (file);
+           (void) m_unlink (file);
            advise (file, "error writing");
            return NULL;
        }
            advise (file, "error writing");
            return NULL;
        }
@@ -228,7 +222,7 @@ parse_mime (char *file)
 
     if (!(ct = get_content (fp, file, 1))) {
        if (is_stdin)
 
     if (!(ct = get_content (fp, file, 1))) {
        if (is_stdin)
-           unlink (file);
+           (void) m_unlink (file);
        advise (NULL, "unable to decode %s", file);
        return NULL;
     }
        advise (NULL, "unable to decode %s", file);
        return NULL;
     }
@@ -1652,7 +1646,12 @@ openBase64 (CT ct, char **file)
     }
 
     if (*file == NULL) {
     }
 
     if (*file == NULL) {
-       ce->ce_file = add (m_mktemp(tmp, NULL, NULL), NULL);
+       char *tempfile;
+       if ((tempfile = m_mktemp2(NULL, invo_name, NULL, NULL)) == NULL) {
+           adios(NULL, "unable to create temporary file in %s",
+                 get_temp_dir());
+       }
+       ce->ce_file = add (tempfile, NULL);
        ce->ce_unlink = 1;
     } else {
        ce->ce_file = add (*file, NULL);
        ce->ce_unlink = 1;
     } else {
        ce->ce_file = add (*file, NULL);
@@ -1670,17 +1669,7 @@ openBase64 (CT ct, char **file)
         cp = context_find (buffer);
     }
     if (cp != NULL && *cp != '\0') {
         cp = context_find (buffer);
     }
     if (cp != NULL && *cp != '\0') {
-        if (ce->ce_unlink) {
-            /* Temporary file already exists, so we rename to
-               version with extension. */
-            char *file_org = strdup(ce->ce_file);
-            ce->ce_file = add (cp, ce->ce_file);
-            if (rename(file_org, ce->ce_file)) {
-                adios (ce->ce_file, "unable to rename %s to ", file_org);
-            }
-            free(file_org);
-
-        } else {
+        if (! ce->ce_unlink) {
             ce->ce_file = add (cp, ce->ce_file);
         }
     }
             ce->ce_file = add (cp, ce->ce_file);
         }
     }
@@ -1886,7 +1875,12 @@ openQuoted (CT ct, char **file)
     }
 
     if (*file == NULL) {
     }
 
     if (*file == NULL) {
-       ce->ce_file = add (m_mktemp(tmp, NULL, NULL), NULL);
+       char *tempfile;
+       if ((tempfile = m_mktemp2(NULL, invo_name, NULL, NULL)) == NULL) {
+           adios(NULL, "unable to create temporary file in %s",
+                 get_temp_dir());
+       }
+       ce->ce_file = add (tempfile, NULL);
        ce->ce_unlink = 1;
     } else {
        ce->ce_file = add (*file, NULL);
        ce->ce_unlink = 1;
     } else {
        ce->ce_file = add (*file, NULL);
@@ -1904,17 +1898,7 @@ openQuoted (CT ct, char **file)
         cp = context_find (buffer);
     }
     if (cp != NULL && *cp != '\0') {
         cp = context_find (buffer);
     }
     if (cp != NULL && *cp != '\0') {
-        if (ce->ce_unlink) {
-            /* Temporary file already exists, so we rename to
-               version with extension. */
-            char *file_org = strdup(ce->ce_file);
-            ce->ce_file = add (cp, ce->ce_file);
-            if (rename(file_org, ce->ce_file)) {
-                adios (ce->ce_file, "unable to rename %s to ", file_org);
-            }
-            free(file_org);
-
-        } else {
+        if (! ce->ce_unlink) {
             ce->ce_file = add (cp, ce->ce_file);
         }
     }
             ce->ce_file = add (cp, ce->ce_file);
         }
     }
@@ -2110,7 +2094,12 @@ open7Bit (CT ct, char **file)
     }
 
     if (*file == NULL) {
     }
 
     if (*file == NULL) {
-       ce->ce_file = add (m_mktemp(tmp, NULL, NULL), NULL);
+       char *tempfile;
+       if ((tempfile = m_mktemp2(NULL, invo_name, NULL, NULL)) == NULL) {
+           adios(NULL, "unable to create temporary file in %s",
+                 get_temp_dir());
+       }
+       ce->ce_file = add (tempfile, NULL);
        ce->ce_unlink = 1;
     } else {
        ce->ce_file = add (*file, NULL);
        ce->ce_unlink = 1;
     } else {
        ce->ce_file = add (*file, NULL);
@@ -2128,17 +2117,7 @@ open7Bit (CT ct, char **file)
         cp = context_find (buffer);
     }
     if (cp != NULL && *cp != '\0') {
         cp = context_find (buffer);
     }
     if (cp != NULL && *cp != '\0') {
-        if (ce->ce_unlink) {
-            /* Temporary file already exists, so we rename to
-               version with extension. */
-            char *file_org = strdup(ce->ce_file);
-            ce->ce_file = add (cp, ce->ce_file);
-            if (rename(file_org, ce->ce_file)) {
-                adios (ce->ce_file, "unable to rename %s to ", file_org);
-            }
-            free(file_org);
-
-        } else {
+        if (! ce->ce_unlink) {
             ce->ce_file = add (cp, ce->ce_file);
         }
     }
             ce->ce_file = add (cp, ce->ce_file);
         }
     }
@@ -2361,12 +2340,12 @@ openFile (CT ct, char **file)
 
            if (ferror (gp)) {
                admonish (ce->ce_file, "error reading");
 
            if (ferror (gp)) {
                admonish (ce->ce_file, "error reading");
-               unlink (cachefile);
+               (void) m_unlink (cachefile);
            }
            else
                if (ferror (fp)) {
                    admonish (cachefile, "error writing");
            }
            else
                if (ferror (fp)) {
                    admonish (cachefile, "error writing");
-                   unlink (cachefile);
+                   (void) m_unlink (cachefile);
                }
            fclose (fp);
        }
                }
            fclose (fp);
        }
@@ -2499,8 +2478,14 @@ openFTP (CT ct, char **file)
        ce->ce_file = add (*file, NULL);
     else if (caching)
        ce->ce_file = add (cachefile, NULL);
        ce->ce_file = add (*file, NULL);
     else if (caching)
        ce->ce_file = add (cachefile, NULL);
-    else
-       ce->ce_file = add (m_mktemp(tmp, NULL, NULL), NULL);
+    else {
+       char *tempfile;
+       if ((tempfile = m_mktemp2(NULL, invo_name, NULL, NULL)) == NULL) {
+           adios(NULL, "unable to create temporary file in %s",
+                 get_temp_dir());
+       }
+       ce->ce_file = add (tempfile, NULL);
+    }
 
     if ((ce->ce_fp = fopen (ce->ce_file, "w+")) == NULL) {
        content_error (ce->ce_file, ct, "unable to fopen for reading/writing");
 
     if ((ce->ce_fp = fopen (ce->ce_file, "w+")) == NULL) {
        content_error (ce->ce_file, ct, "unable to fopen for reading/writing");
@@ -2571,12 +2556,12 @@ openFTP (CT ct, char **file)
 
                if (ferror (gp)) {
                    admonish (ce->ce_file, "error reading");
 
                if (ferror (gp)) {
                    admonish (ce->ce_file, "error reading");
-                   unlink (cachefile);
+                   (void) m_unlink (cachefile);
                }
                else
                    if (ferror (fp)) {
                        admonish (cachefile, "error writing");
                }
                else
                    if (ferror (fp)) {
                        admonish (cachefile, "error writing");
-                       unlink (cachefile);
+                       (void) m_unlink (cachefile);
                    }
                fclose (fp);
            }
                    }
                fclose (fp);
            }
@@ -2688,7 +2673,12 @@ openMail (CT ct, char **file)
     }
 
     if (*file == NULL) {
     }
 
     if (*file == NULL) {
-       ce->ce_file = add (m_mktemp(tmp, NULL, NULL), NULL);
+       char *tempfile;
+       if ((tempfile = m_mktemp2(NULL, invo_name, NULL, NULL)) == NULL) {
+           adios(NULL, "unable to create temporary file in %s",
+                 get_temp_dir());
+       }
+       ce->ce_file = add (tempfile, NULL);
        ce->ce_unlink = 1;
     } else {
        ce->ce_file = add (*file, NULL);
        ce->ce_unlink = 1;
     } else {
        ce->ce_file = add (*file, NULL);
@@ -2781,8 +2771,14 @@ openURL (CT ct, char **file)
        ce->ce_file = add(*file, NULL);
     else if (caching)
        ce->ce_file = add(cachefile, NULL);
        ce->ce_file = add(*file, NULL);
     else if (caching)
        ce->ce_file = add(cachefile, NULL);
-    else
-       ce->ce_file = add(m_mktemp(tmp, NULL, NULL), NULL);
+    else {
+       char *tempfile;
+       if ((tempfile = m_mktemp2(NULL, invo_name, NULL, NULL)) == NULL) {
+           adios(NULL, "unable to create temporary file in %s",
+                 get_temp_dir());
+       }
+       ce->ce_file = add (tempfile, NULL);
+    }
 
     if ((ce->ce_fp = fopen(ce->ce_file, "w+")) == NULL) {
        content_error(ce->ce_file, ct, "unable to fopen for read/writing");
 
     if ((ce->ce_fp = fopen(ce->ce_file, "w+")) == NULL) {
        content_error(ce->ce_file, ct, "unable to fopen for read/writing");
@@ -2835,7 +2831,7 @@ openURL (CT ct, char **file)
 
                if (ferror(gp)) {
                    admonish(ce->ce_file, "error reading");
 
                if (ferror(gp)) {
                    admonish(ce->ce_file, "error reading");
-                   unlink(cachefile);
+                   (void) m_unlink (cachefile);
                }
            }
            umask(mask);
                }
            }
            umask(mask);
index 29b59f4a115f4d511b3aaa9cc2b1be1e231cb3bc..b9506d7383cc96efe8818bf9d6172be2acdecb1d 100644 (file)
@@ -32,11 +32,7 @@ main(int argc, char **argv)
     struct msgs_array msgs = { 0, 0, NULL };
     struct msgs *mp;
 
     struct msgs_array msgs = { 0, 0, NULL };
     struct msgs *mp;
 
-    setlocale(LC_ALL, "");
-    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;
 
     arguments = getarguments (invo_name, argc, argv, 1);
     argp = arguments;
index f19f9a9d9009a94e7327c96438f505d9c5ab7d9b..f83236b7433e1f063ef77ce29aa6efb6121c86b1 100644 (file)
@@ -56,9 +56,6 @@ DEFINE_SWITCH_ARRAY(MHSHOW, switches);
 #undef X
 
 
 #undef X
 
 
-/* mhparse.c */
-extern char *tmp;      /* directory to place temp files */
-
 /* mhcachesbr.c */
 extern int rcachesw;
 extern int wcachesw;
 /* mhcachesbr.c */
 extern int rcachesw;
 extern int wcachesw;
@@ -117,13 +114,9 @@ main (int argc, char **argv)
     CT ct, *ctp;
     FILE *fp;
 
     CT ct, *ctp;
     FILE *fp;
 
-    done=freects_done;
-
-    setlocale(LC_ALL, "");
-    invo_name = r1bindex (argv[0], '/');
+    if (nmh_init(argv[0], 1)) { return 1; }
 
 
-    /* read user profile/context */
-    context_read();
+    done=freects_done;
 
     arguments = getarguments (invo_name, argc, argv, 1);
     argp = arguments;
 
     arguments = getarguments (invo_name, argc, argv, 1);
     argp = arguments;
@@ -291,16 +284,6 @@ do_cache:
        cache_private = ".cache";
     cache_private = getcpy (m_maildir (cache_private));
 
        cache_private = ".cache";
     cache_private = getcpy (m_maildir (cache_private));
 
-    /*
-     * Check for storage directory.  If specified,
-     * then store temporary files there.  Else we
-     * store them in standard nmh directory.
-     */
-    if ((cp = context_find (nmhstorage)) && *cp)
-       tmp = concat (cp, "/", invo_name, NULL);
-    else
-       tmp = add (m_maildir (invo_name), NULL);
-
     if (!context_find ("path"))
        free (path ("./", TFOLDER));
 
     if (!context_find ("path"))
        free (path ("./", TFOLDER));
 
index fff480aef70f598cdb70673ddb183838f4f7b439..fb5349faaeba04ac7966226a1a42549755548265 100644 (file)
@@ -48,9 +48,6 @@ DEFINE_SWITCH_ARRAY(MHSTORE, switches);
 int save_clobber_policy (const char *);
 extern int files_not_clobbered;
 
 int save_clobber_policy (const char *);
 extern int files_not_clobbered;
 
-/* mhparse.c */
-extern char *tmp;      /* directory to place temp files */
-
 /* mhcachesbr.c */
 extern int rcachesw;
 extern int wcachesw;
 /* mhcachesbr.c */
 extern int rcachesw;
 extern int wcachesw;
@@ -106,13 +103,9 @@ main (int argc, char **argv)
     CT ct, *ctp;
     FILE *fp;
 
     CT ct, *ctp;
     FILE *fp;
 
-    done=freects_done;
-
-    setlocale(LC_ALL, "");
-    invo_name = r1bindex (argv[0], '/');
+    if (nmh_init(argv[0], 1)) { return 1; }
 
 
-    /* read user profile/context */
-    context_read();
+    done=freects_done;
 
     arguments = getarguments (invo_name, argc, argv, 1);
     argp = arguments;
 
     arguments = getarguments (invo_name, argc, argv, 1);
     argp = arguments;
@@ -267,16 +260,6 @@ do_cache:
      */
     cwd = getcpy (pwd());
 
      */
     cwd = getcpy (pwd());
 
-    /*
-     * Check for storage directory.  If specified,
-     * then store temporary files there.  Else we
-     * store them in standard nmh directory.
-     */
-    if ((cp = context_find (nmhstorage)) && *cp)
-       tmp = concat (cp, "/", invo_name, NULL);
-    else
-       tmp = add (m_maildir (invo_name), NULL);
-
     if (!context_find ("path"))
        free (path ("./", TFOLDER));
 
     if (!context_find ("path"))
        free (path ("./", TFOLDER));
 
index 93d3e90259fc8e90bf2612bd6b2c0b233d320d42..7b1dbd519b5c3655eed7d734b5ed4b5ac94b6d0b 100644 (file)
@@ -562,7 +562,10 @@ store_content (CT ct, CT p)
            char *tmpfilenam, *folder;
 
            /* Store content in temporary file for now */
            char *tmpfilenam, *folder;
 
            /* Store content in temporary file for now */
-           tmpfilenam = m_mktemp(invo_name, NULL, NULL);
+           if ((tmpfilenam = m_mktemp(invo_name, NULL, NULL)) == NULL) {
+               adios(NULL, "unable to create temporary file in %s",
+                     get_temp_dir());
+           }
            ct->c_storage = add (tmpfilenam, NULL);
 
            /* Get the folder name */
            ct->c_storage = add (tmpfilenam, NULL);
 
            /* Get the folder name */
@@ -623,7 +626,7 @@ got_filename:
      */
     if (ct->c_folder && (!is_partial || last_partial)) {
        msgnum = output_content_folder (ct->c_folder, ct->c_storage);
      */
     if (ct->c_folder && (!is_partial || last_partial)) {
        msgnum = output_content_folder (ct->c_folder, ct->c_storage);
-       unlink (ct->c_storage);
+       (void) m_unlink (ct->c_storage);
        if (msgnum == NOTOK)
            return NOTOK;
     }
        if (msgnum == NOTOK)
            return NOTOK;
     }
index 092b542a5a234fa3b4dbe1db1ce584318564a8fe..b85a91ea782730c15780ce12812f0be1f741821e 100644 (file)
@@ -42,9 +42,6 @@ DEFINE_SWITCH_ARRAY(MHTEST, switches);
 #undef X
 
 
 #undef X
 
 
-/* mhparse.c */
-extern char *tmp;      /* directory to place temp files */
-
 /* mhcachesbr.c */
 extern int rcachesw;
 extern int wcachesw;
 /* mhcachesbr.c */
 extern int rcachesw;
 extern int wcachesw;
@@ -102,13 +99,9 @@ main (int argc, char **argv)
     struct msgs *mp = NULL;
     CT ct, *ctp;
 
     struct msgs *mp = NULL;
     CT ct, *ctp;
 
-    done=freects_done;
-
-    setlocale(LC_ALL, "");
-    invo_name = r1bindex (argv[0], '/');
+    if (nmh_init(argv[0], 1)) { return 1; }
 
 
-    /* read user profile/context */
-    context_read();
+    done=freects_done;
 
     arguments = getarguments (invo_name, argc, argv, 1);
     argp = arguments;
 
     arguments = getarguments (invo_name, argc, argv, 1);
     argp = arguments;
@@ -226,16 +219,6 @@ do_cache:
        cache_private = ".cache";
     cache_private = getcpy (m_maildir (cache_private));
 
        cache_private = ".cache";
     cache_private = getcpy (m_maildir (cache_private));
 
-    /*
-     * Check for storage directory.  If specified,
-     * then store temporary files there.  Else we
-     * store them in standard nmh directory.
-     */
-    if ((cp = context_find (nmhstorage)) && *cp)
-       tmp = concat (cp, "/", invo_name, NULL);
-    else
-       tmp = add (m_maildir (invo_name), NULL);
-
     if (!context_find ("path"))
        free (path ("./", TFOLDER));
 
     if (!context_find ("path"))
        free (path ("./", TFOLDER));
 
@@ -360,7 +343,6 @@ static void
 pipeser (int i)
 {
     if (i == SIGQUIT) {
 pipeser (int i)
 {
     if (i == SIGQUIT) {
-       unlink ("core");
        fflush (stdout);
        fprintf (stderr, "\n");
        fflush (stderr);
        fflush (stdout);
        fprintf (stderr, "\n");
        fflush (stderr);
index 39a2918d2c9b8eb3078fa35a4578d52bad4a1af7..49e758f07be9aa4c37a1dca644df06b624ed4324 100644 (file)
@@ -85,11 +85,7 @@ main (int argc, char **argv)
     char **argp, **arguments, *vec[MAXVEC];
     struct passwd *pw;
 
     char **argp, **arguments, *vec[MAXVEC];
     struct passwd *pw;
 
-    setlocale(LC_ALL, "");
-    invo_name = r1bindex (argv[0], '/');
-
-    /* read user profile/context */
-    context_read();
+    if (nmh_init(argv[0], 1)) { return 1; }
 
     mts_init (invo_name);
 
 
     mts_init (invo_name);
 
index 75371bad378e34917e4dace2a46b97942c7fc5e0..e91924c35db2275236cce48fdada9739a49df0b0 100644 (file)
--- a/uip/msh.c
+++ b/uip/msh.c
@@ -203,11 +203,7 @@ main (int argc, char **argv)
     char *cp, *file = NULL, *folder = NULL;
     char **argp, **arguments, buf[BUFSIZ];
 
     char *cp, *file = NULL, *folder = NULL;
     char **argp, **arguments, buf[BUFSIZ];
 
-    setlocale(LC_ALL, "");
-    invo_name = r1bindex (argv[0], '/');
-
-    /* read user profile/context */
-    context_read();
+    if (nmh_init(argv[0], 1)) { return 1; }
 
     mts_init (invo_name);
     arguments = getarguments (invo_name, argc,argv, 1);
 
     mts_init (invo_name);
     arguments = getarguments (invo_name, argc,argv, 1);
@@ -1118,7 +1114,7 @@ quit (void)
                close (i);
            else
                advise (mp->foldpath, "error zero'ing");
                close (i);
            else
                advise (mp->foldpath, "error zero'ing");
-           unlink (map_name (mp->foldpath));/* XXX */
+           (void) m_unlink (map_name (mp->foldpath));/* XXX */
        }
        goto release;
     }
        }
        goto release;
     }
@@ -1135,8 +1131,8 @@ quit (void)
     for (msgnum = mp->lowmsg; msgnum <= mp->hghmsg; msgnum++)
        if (does_exist(mp, msgnum) && pack (tmpfil, md, msgnum) == NOTOK) {
            mbx_close (tmpfil, md);
     for (msgnum = mp->lowmsg; msgnum <= mp->hghmsg; msgnum++)
        if (does_exist(mp, msgnum) && pack (tmpfil, md, msgnum) == NOTOK) {
            mbx_close (tmpfil, md);
-           unlink (tmpfil);
-           unlink (map_name (tmpfil));
+           (void) m_unlink (tmpfil);
+           (void) m_unlink (map_name (tmpfil));
            goto release;
        }
     mbx_close (tmpfil, md);
            goto release;
        }
     mbx_close (tmpfil, md);
@@ -1149,8 +1145,8 @@ quit (void)
 
        if (rename (map1, map2) == NOTOK) {
            admonish (map2, "unable to rename %s to", map1);
 
        if (rename (map1, map2) == NOTOK) {
            admonish (map2, "unable to rename %s to", map1);
-           unlink (map1);
-           unlink (map2);
+           (void) m_unlink (map1);
+           (void) m_unlink (map2);
        }
     }
 
        }
     }
 
index 3a5f98fa4add71b9bb0f0370ad8a1cec7f4ac9f2..6627c6ab61d2c61c3db51d15be677550084d5833 100644 (file)
@@ -1011,7 +1011,7 @@ forw (char *proc, char *filter, int vecp, char **vec)
                break;
        }
 
                break;
        }
 
-    unlink (tmpfil);
+    (void) m_unlink (tmpfil);
 }
 
 
 }
 
 
@@ -2842,7 +2842,7 @@ ready: ;
     }
 
     if (!fmsh)
     }
 
     if (!fmsh)
-       unlink (tmpfil);
+       (void) m_unlink (tmpfil);
     return status;
 }
 
     return status;
 }
 
index 59b5b8cfb06b4934cc83def90e55fdef6e523a05..6f9982528c50111ade88551a63ac45616ac6062f 100644 (file)
--- a/uip/new.c
+++ b/uip/new.c
@@ -422,11 +422,7 @@ main(int argc, char **argv)
     char *unseen;
     struct node *folder;
 
     char *unseen;
     struct node *folder;
 
-    setlocale(LC_ALL, "");
-    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;
 
     arguments = getarguments (invo_name, argc, argv, 1);
     argp = arguments;
index 6f951914187606107803325d247de8dfa4c14569..30f0f484059cd234f81e8e8129f9a9805040d836 100644 (file)
@@ -46,13 +46,9 @@ main (int argc, char **argv)
     struct msgs *mp;
     struct stat st;
 
     struct msgs *mp;
     struct stat st;
 
-    done=mbxclose_done;
-
-    setlocale(LC_ALL, "");
-    invo_name = r1bindex (argv[0], '/');
+    if (nmh_init(argv[0], 1)) { return 1; }
 
 
-    /* read user profile/context */
-    context_read();
+    done=mbxclose_done;
 
     arguments = getarguments (invo_name, argc, argv, 1);
     argp = arguments;
 
     arguments = getarguments (invo_name, argc, argv, 1);
     argp = arguments;
index a915920808340735600c102e25b58c2c0e5271b1..740f6f0a4e9524069b831a1bf88746708aa8a1e7 100644 (file)
@@ -66,13 +66,9 @@ main (int argc, char **argv)
     struct msgs *mp, *mp2;
     register FILE *fp;
 
     struct msgs *mp, *mp2;
     register FILE *fp;
 
-    done=putzero_done;
-
-    setlocale(LC_ALL, "");
-    invo_name = r1bindex (argv[0], '/');
+    if (nmh_init(argv[0], 1)) { return 1; }
 
 
-    /* read user profile/context */
-    context_read();
+    done=putzero_done;
 
     arguments = getarguments (invo_name, argc, argv, 1);
     argp = arguments;
 
     arguments = getarguments (invo_name, argc, argv, 1);
     argp = arguments;
index f6e14fb45d6b24a1685deebed1531a95ada1a148..9b358521c97afe13e3f03f21b41a4eb1a83fbe3b 100644 (file)
@@ -283,12 +283,7 @@ main (int argc, char **argv)
     FILE *in, *out;
     m_getfld_state_t gstate = 0;
 
     FILE *in, *out;
     m_getfld_state_t gstate = 0;
 
-    setlocale(LC_ALL, "");
-    invo_name = r1bindex (argv[0], '/');
-
-    /* foil search of user profile/context */
-    if (context_foil (NULL) == -1)
-       done (1);
+    if (nmh_init(argv[0], 0 /* use context_foil() */)) { return 1; }
 
     mts_init (invo_name);
     arguments = getarguments (invo_name, argc, argv, 0);
 
     mts_init (invo_name);
     arguments = getarguments (invo_name, argc, argv, 0);
@@ -533,15 +528,12 @@ main (int argc, char **argv)
            if ((out = fopen ("/dev/null", "w")) == NULL)
                adios ("/dev/null", "unable to open");
        } else {
            if ((out = fopen ("/dev/null", "w")) == NULL)
                adios ("/dev/null", "unable to open");
        } else {
-            char *cp = m_mktemp(m_maildir(invo_name), NULL, &out);
-            if (cp == NULL) {
-                cp = m_mktemp2(NULL, invo_name, NULL, &out);
-                if (cp == NULL) {
-                   adios ("post", "unable to create temporary file");
-                }
-            }
+           char *cp = m_mktemp2(NULL, invo_name, NULL, &out);
+           if (cp == NULL) {
+               adios(NULL, "unable to create temporary file in %s",
+                     get_temp_dir());
+           }
             strncpy(tmpfil, cp, sizeof(tmpfil));
             strncpy(tmpfil, cp, sizeof(tmpfil));
-           chmod (tmpfil, 0600);
        }
     }
 
        }
     }
 
@@ -638,13 +630,13 @@ main (int argc, char **argv)
            post (tmpfil, 0, verbose, envelope);
        }
        post (bccfil, 1, verbose, envelope);
            post (tmpfil, 0, verbose, envelope);
        }
        post (bccfil, 1, verbose, envelope);
-       unlink (bccfil);
+       (void) m_unlink (bccfil);
     } else {
        post (tmpfil, 0, isatty (1), envelope);
     }
 
     p_refile (tmpfil);
     } else {
        post (tmpfil, 0, isatty (1), envelope);
     }
 
     p_refile (tmpfil);
-    unlink (tmpfil);
+    (void) m_unlink (tmpfil);
 
     if (verbose) {
        if (partno)
 
     if (verbose) {
        if (partno)
@@ -1280,8 +1272,9 @@ make_bcc_file (int dashstuff)
     FILE *out;
     char *tfile = NULL, *program;
 
     FILE *out;
     char *tfile = NULL, *program;
 
-    tfile = m_mktemp2(NULL, "bccs", NULL, &out);
-    if (tfile == NULL) adios("bcc", "unable to create temporary file");
+    if ((tfile = m_mktemp2(NULL, "bccs", NULL, &out)) == NULL) {
+       adios(NULL, "unable to create temporary file in %s", get_temp_dir());
+    }
     strncpy (bccfil, tfile, sizeof(bccfil));
 
     fprintf (out, "From: %s\n", fullfrom);
     strncpy (bccfil, tfile, sizeof(bccfil));
 
     fprintf (out, "From: %s\n", fullfrom);
@@ -1712,9 +1705,9 @@ sigser (int i)
 {
     NMH_UNUSED (i);
 
 {
     NMH_UNUSED (i);
 
-    unlink (tmpfil);
+    (void) m_unlink (tmpfil);
     if (msgflags & MINV)
     if (msgflags & MINV)
-       unlink (bccfil);
+       (void) m_unlink (bccfil);
 
     if (!whomsw || checksw)
        sm_end (NOTOK);
 
     if (!whomsw || checksw)
        sm_end (NOTOK);
@@ -1836,9 +1829,9 @@ die (char *what, char *fmt, ...)
 {
     va_list ap;
 
 {
     va_list ap;
 
-    unlink (tmpfil);
+    (void) m_unlink (tmpfil);
     if (msgflags & MINV)
     if (msgflags & MINV)
-       unlink (bccfil);
+       (void) m_unlink (bccfil);
 
     if (!whomsw || checksw)
        sm_end (NOTOK);
 
     if (!whomsw || checksw)
        sm_end (NOTOK);
index 7923e84b316508ccb9fc60fdc43f2212b0c3abfe..37f5960b0c322a622af6775c38d62361bc1420ce 100644 (file)
@@ -78,11 +78,7 @@ main (int argc, char **argv)
     char *tmpfil;
     m_getfld_state_t gstate = 0;
 
     char *tmpfil;
     m_getfld_state_t gstate = 0;
 
-    setlocale(LC_ALL, "");
-    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;
 
     arguments = getarguments (invo_name, argc, argv, 1);
     argp = arguments;
@@ -152,9 +148,9 @@ main (int argc, char **argv)
     if ((in = fopen (drft, "r")) == NULL)
        adios (drft, "unable to open");
 
     if ((in = fopen (drft, "r")) == NULL)
        adios (drft, "unable to open");
 
-    tmpfil = m_mktemp2(NULL, invo_name, NULL, &out);
-    if (tmpfil == NULL) adios("prompter", "unable to create temporary file");
-    chmod (tmpfil, 0600);
+    if ((tmpfil = m_mktemp2(NULL, invo_name, NULL, &out)) == NULL) {
+       adios(NULL, "unable to create temporary file in %s", get_temp_dir());
+    }
 
     /*
      * Are we changing the kill or erase character?
 
     /*
      * Are we changing the kill or erase character?
@@ -231,7 +227,7 @@ abort:
                        if (killp || erasep) {
                            tcsetattr(0, TCSADRAIN, &tio);
                        }
                        if (killp || erasep) {
                            tcsetattr(0, TCSADRAIN, &tio);
                        }
-                       unlink (tmpfil);
+                       (void) m_unlink (tmpfil);
                        done (1);
                    }
                    if (i != 0 || (field[0] != '\n' && field[0] != 0)) {
                        done (1);
                    }
                    if (i != 0 || (field[0] != '\n' && field[0] != 0)) {
@@ -320,7 +316,7 @@ abort:
     cpydata (fdi, fdo, tmpfil, drft);
     close (fdi);
     close (fdo);
     cpydata (fdi, fdo, tmpfil, drft);
     close (fdi);
     close (fdo);
-    unlink (tmpfil);
+    (void) m_unlink (tmpfil);
 
     context_save ();   /* save the context file */
     done (0);
 
     context_save ();   /* save the context file */
     done (0);
index 8b672cd7ba849994a551939d0c1eca2b63b3783d..85baf33db00a6a8d9596d820038122f67a8a6266 100644 (file)
@@ -48,13 +48,9 @@ main (int argc, char **argv)
     FILE *fp;
     char *tfile = NULL;
 
     FILE *fp;
     char *tfile = NULL;
 
-    done=unlink_done;
-
-    setlocale(LC_ALL, "");
-    invo_name = r1bindex (argv[0], '/');
+    if (nmh_init(argv[0], 1)) { return 1; }
 
 
-    /* read user profile/context */
-    context_read();
+    done=unlink_done;
 
     /*
      * Configure this now, since any unknown switches to rcvdist get
 
     /*
      * Configure this now, since any unknown switches to rcvdist get
@@ -102,15 +98,17 @@ main (int argc, char **argv)
 
     umask (~m_gmprot ());
 
 
     umask (~m_gmprot ());
 
-    tfile = m_mktemp2(NULL, invo_name, NULL, &fp);
-    if (tfile == NULL) adios("rcvdist", "unable to create temporary file");
+    if ((tfile = m_mktemp2(NULL, invo_name, NULL, &fp)) == NULL) {
+       adios(NULL, "unable to create temporary file in %s", get_temp_dir());
+    }
     strncpy (tmpfil, tfile, sizeof(tmpfil));
 
     cpydata (fileno (stdin), fileno (fp), "message", tmpfil);
     fseek (fp, 0L, SEEK_SET);
 
     strncpy (tmpfil, tfile, sizeof(tmpfil));
 
     cpydata (fileno (stdin), fileno (fp), "message", tmpfil);
     fseek (fp, 0L, SEEK_SET);
 
-    tfile = m_mktemp2(NULL, invo_name, NULL, NULL);
-    if (tfile == NULL) adios("forw", "unable to create temporary file");
+    if ((tfile = m_mktemp2(NULL, invo_name, NULL, NULL)) == NULL) {
+       adios(NULL, "unable to create temporary file in %s", get_temp_dir());
+    }
     strncpy (drft, tfile, sizeof(tmpfil));
 
     rcvdistout (fp, form, addrs);
     strncpy (drft, tfile, sizeof(tmpfil));
 
     rcvdistout (fp, form, addrs);
@@ -255,11 +253,11 @@ static void
 unlink_done (int status)
 {
     if (backup[0])
 unlink_done (int status)
 {
     if (backup[0])
-       unlink (backup);
+       (void) m_unlink (backup);
     if (drft[0])
     if (drft[0])
-       unlink (drft);
+       (void) m_unlink (drft);
     if (tmpfil[0])
     if (tmpfil[0])
-       unlink (tmpfil);
+       (void) m_unlink (tmpfil);
 
     exit (status ? RCV_MBX : RCV_MOK);
 }
 
     exit (status ? RCV_MBX : RCV_MOK);
 }
index 08e21b9cf2e5759ff2f1d70b083e28532561ced9..bbd0e08e7ff34c10cb5538ef328545948d70352d 100644 (file)
@@ -40,11 +40,7 @@ main (int argc, char **argv)
     char *cp, *file = NULL, buf[BUFSIZ];
     char **argp, **arguments;
 
     char *cp, *file = NULL, buf[BUFSIZ];
     char **argp, **arguments;
 
-    setlocale(LC_ALL, "");
-    invo_name = r1bindex (argv[0], '/');
-
-    /* read user profile/context */
-    context_read();
+    if (nmh_init(argv[0], 1)) { return 1; }
 
     mts_init (invo_name);
     arguments = getarguments (invo_name, argc, argv, 1);
 
     mts_init (invo_name);
     arguments = getarguments (invo_name, argc, argv, 1);
index 98f17503a869fd99813cc710ebc0edb3df4d880f..be0ac396641494eed665bf6396c6271a221eb869 100644 (file)
@@ -54,13 +54,9 @@ main (int argc, char **argv)
     struct msgs *mp;
     struct stat st;
 
     struct msgs *mp;
     struct stat st;
 
-    done=unlink_done;
-
-    setlocale(LC_ALL, "");
-    invo_name = r1bindex (argv[0], '/');
+    if (nmh_init(argv[0], 1)) { return 1; }
 
 
-    /* read user profile/context */
-    context_read();
+    done=unlink_done;
 
     mts_init (invo_name);
     arguments = getarguments (invo_name, argc, argv, 1);
 
     mts_init (invo_name);
     arguments = getarguments (invo_name, argc, argv, 1);
@@ -162,7 +158,7 @@ main (int argc, char **argv)
     /* create a temporary file */
     tmpfilenam = m_mktemp (invo_name, &fd, NULL);
     if (tmpfilenam == NULL) {
     /* create a temporary file */
     tmpfilenam = m_mktemp (invo_name, &fd, NULL);
     if (tmpfilenam == NULL) {
-       adios ("rcvstore", "unable to create temporary file");
+       adios(NULL, "unable to create temporary file in %s", get_temp_dir());
     }
     chmod (tmpfilenam, m_gmprot());
 
     }
     chmod (tmpfilenam, m_gmprot());
 
@@ -170,7 +166,7 @@ main (int argc, char **argv)
     cpydata (fileno (stdin), fd, "standard input", tmpfilenam);
 
     if (fstat (fd, &st) == NOTOK) {
     cpydata (fileno (stdin), fd, "standard input", tmpfilenam);
 
     if (fstat (fd, &st) == NOTOK) {
-       unlink (tmpfilenam);
+       (void) m_unlink (tmpfilenam);
        adios (tmpfilenam, "unable to fstat");
     }
     if (close (fd) == NOTOK)
        adios (tmpfilenam, "unable to fstat");
     }
     if (close (fd) == NOTOK)
@@ -178,7 +174,7 @@ main (int argc, char **argv)
 
     /* don't add file if it is empty */
     if (st.st_size == 0) {
 
     /* don't add file if it is empty */
     if (st.st_size == 0) {
-       unlink (tmpfilenam);
+       (void) m_unlink (tmpfilenam);
        advise (NULL, "empty file");
        done (0);
     }
        advise (NULL, "empty file");
        done (0);
     }
@@ -216,7 +212,7 @@ main (int argc, char **argv)
     folder_free (mp);          /* free folder/message structure          */
 
     context_save ();           /* save the global context file           */
     folder_free (mp);          /* free folder/message structure          */
 
     context_save ();           /* save the global context file           */
-    unlink (tmpfilenam);       /* remove temporary file                  */
+    (void) m_unlink (tmpfilenam); /* remove temporary file                  */
     tmpfilenam = NULL;
 
     done (0);
     tmpfilenam = NULL;
 
     done (0);
@@ -230,6 +226,6 @@ static void
 unlink_done(int status)
 {
     if (tmpfilenam && *tmpfilenam)
 unlink_done(int status)
 {
     if (tmpfilenam && *tmpfilenam)
-       unlink (tmpfilenam);
+       (void) m_unlink (tmpfilenam);
     exit (status);
 }
     exit (status);
 }
index 447c6e402b191b7da739bbad09dd10d0066da523..3bee075e038e6165f50593c1cb11a952154e60ef 100644 (file)
@@ -82,11 +82,7 @@ main (int argc, char **argv)
     char **argp, **arguments, *vec[MAXARGS];
     struct utmpx *utp;
 
     char **argp, **arguments, *vec[MAXARGS];
     struct utmpx *utp;
 
-    setlocale(LC_ALL, "");
-    invo_name = r1bindex (argv[0], '/');
-
-    /* read user profile/context */
-    context_read();
+    if (nmh_init(argv[0], 1)) { return 1; }
 
     mts_init (invo_name);
     arguments = getarguments (invo_name, argc, argv, 1);
 
     mts_init (invo_name);
     arguments = getarguments (invo_name, argc, argv, 1);
@@ -188,13 +184,15 @@ message_fd (char **vec)
 {
     pid_t child_id;
     int bytes, seconds;
 {
     pid_t child_id;
     int bytes, seconds;
-    /* volatile to prevent "might be clobbered" warning from gcc: */
-    volatile int fd;
-    char tmpfil[BUFSIZ];
+    int fd;
+    char *tfile;
     struct stat st;
 
     struct stat st;
 
-    fd = mkstemp (strncpy (tmpfil, "/tmp/rcvttyXXXXX", sizeof(tmpfil)));
-    unlink (tmpfil);
+    if ((tfile = m_mktemp2(NULL, invo_name, &fd, NULL)) == NULL) {
+       advise(NULL, "unable to create temporary file in %s", get_temp_dir());
+       return NOTOK;
+    }
+    (void) m_unlink(tfile);  /* Use fd, no longer need the file name. */
 
     if ((child_id = fork()) == NOTOK) {
        /* fork error */
 
     if ((child_id = fork()) == NOTOK) {
        /* fork error */
@@ -254,9 +252,11 @@ header_fd (void)
     char *nfs;
     char *tfile = NULL;
 
     char *nfs;
     char *tfile = NULL;
 
-    tfile = m_mktemp2(NULL, invo_name, &fd, NULL);
-    if (tfile == NULL) return NOTOK;
-    unlink (tfile);
+    if ((tfile = m_mktemp2(NULL, invo_name, &fd, NULL)) == NULL) {
+       advise(NULL, "unable to create temporary file in %s", get_temp_dir());
+        return NOTOK;
+    }
+    (void) m_unlink(tfile);  /* Use fd, no longer need the file name. */
 
     rewind (stdin);
 
 
     rewind (stdin);
 
index 776c6fdfdf95c177473dc963a6a71b0f9eb8fcac..ecbe346627504d0e0467eb233f7f8d283de0689c 100644 (file)
@@ -68,11 +68,7 @@ main (int argc, char **argv)
     struct msgs_array msgs = { 0, 0, NULL };
     struct msgs *mp;
 
     struct msgs_array msgs = { 0, 0, NULL };
     struct msgs *mp;
 
-    setlocale(LC_ALL, "");
-    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;
 
     arguments = getarguments (invo_name, argc, argv, 1);
     argp = arguments;
@@ -342,7 +338,7 @@ remove_files (int filep, char **files)
     /* Else just unlink the files */
     files++;   /* advance past filevec[0] */
     for (i = 0; i < filep; i++) {
     /* Else just unlink the files */
     files++;   /* advance past filevec[0] */
     for (i = 0; i < filep; i++) {
-       if (unlink (files[i]) == NOTOK)
+       if (m_unlink (files[i]) == NOTOK)
            admonish (files[i], "unable to unlink");
     }
 }
            admonish (files[i], "unable to unlink");
     }
 }
index d1c8ebfa6ee44d7cc0aa8585655ed539c70de94e..7b0ab4a03d55dff683ba1707d75bb3040173407d 100644 (file)
@@ -129,11 +129,7 @@ main (int argc, char **argv)
 
     int buildsw = 0;
 
 
     int buildsw = 0;
 
-    setlocale(LC_ALL, "");
-    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;
 
     arguments = getarguments (invo_name, argc, argv, 1);
     argp = arguments;
index 735cf774c3e4384171b60fe3b0f6eb06472f84ba..bb03805a1b1300fb5e3dd344b456133c131a1e79 100644 (file)
--- a/uip/rmf.c
+++ b/uip/rmf.c
@@ -37,11 +37,7 @@ main (int argc, char **argv)
     char *cp, *folder = NULL, newfolder[BUFSIZ];
     char buf[BUFSIZ], **argp, **arguments;
 
     char *cp, *folder = NULL, newfolder[BUFSIZ];
     char buf[BUFSIZ], **argp, **arguments;
 
-    setlocale(LC_ALL, "");
-    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;
 
     arguments = getarguments (invo_name, argc, argv, 1);
     argp = arguments;
@@ -183,7 +179,7 @@ rmf (char *folder)
                others++;
                continue;
        }
                others++;
                continue;
        }
-       if (unlink (dp->d_name) == NOTOK) {
+       if (m_unlink (dp->d_name) == NOTOK) {
            admonish (dp->d_name, "unable to unlink %s:", folder);
            others++;
        }
            admonish (dp->d_name, "unable to unlink %s:", folder);
            others++;
        }
index 8882b8f623033bbf72c81aeb7cb85a9613575a12..8644a02fb363c8045c12f662a91d648becb89684 100644 (file)
--- a/uip/rmm.c
+++ b/uip/rmm.c
@@ -37,11 +37,7 @@ main (int argc, char **argv)
     struct msgs_array msgs = { 0, 0, NULL };
     struct msgs *mp;
 
     struct msgs_array msgs = { 0, 0, NULL };
     struct msgs *mp;
 
-    setlocale(LC_ALL, "");
-    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;
 
     arguments = getarguments (invo_name, argc, argv, 1);
     argp = arguments;
index 31309220dc247e1b37254fc3ed80f2a71963ed7d..20668691409d0f0a2ac9decb9b84174e774a08c3 100644 (file)
@@ -52,11 +52,7 @@ main (int argc, char **argv)
     struct msgs *mp;
     FILE *in;
 
     struct msgs *mp;
     FILE *in;
 
-    setlocale(LC_ALL, "");
-    invo_name = r1bindex (argv[0], '/');
-
-    /* read user profile/context */
-    context_read();
+    if (nmh_init(argv[0], 1)) { return 1; }
 
     mts_init (invo_name);
     arguments = getarguments (invo_name, argc, argv, 1);
 
     mts_init (invo_name);
     arguments = getarguments (invo_name, argc, argv, 1);
index 626eba16293f2a5a6fc1a476f832a6e0eb089bba..5885c98e71560d6371aea9a93d6faeb6f430092a 100644 (file)
@@ -118,11 +118,7 @@ main (int argc, char **argv)
     struct msgs *mp;
     struct stat st;
 
     struct msgs *mp;
     struct stat st;
 
-    setlocale(LC_ALL, "");
-    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;
 
     arguments = getarguments (invo_name, argc, argv, 1);
     argp = arguments;
@@ -382,8 +378,12 @@ go_to_it:
            && (distsw = atoi (cp))
            && altmsg) {
        vec[vecp++] = "-dist";
            && (distsw = atoi (cp))
            && altmsg) {
        vec[vecp++] = "-dist";
-       distfile = getcpy (m_mktemp2 (altmsg, invo_name, NULL, NULL));
-       unlink(distfile);
+       if ((cp = m_mktemp2(altmsg, invo_name, NULL, NULL)) == NULL) {
+           adios(NULL, "unable to create temporary file in %s",
+                 get_temp_dir());
+       }
+       distfile = getcpy (cp);
+       (void) m_unlink(distfile);
        if (link (altmsg, distfile) == NOTOK) {
            /* Cygwin with FAT32 filesystem produces EPERM. */
            if (errno != EXDEV  &&  errno != EPERM
        if (link (altmsg, distfile) == NOTOK) {
            /* Cygwin with FAT32 filesystem produces EPERM. */
            if (errno != EXDEV  &&  errno != EPERM
@@ -393,7 +393,11 @@ go_to_it:
                )
                adios (distfile, "unable to link %s to", altmsg);
            free (distfile);
                )
                adios (distfile, "unable to link %s to", altmsg);
            free (distfile);
-           distfile = getcpy (m_mktemp2(NULL, invo_name, NULL, NULL));
+           if ((cp = m_mktemp2(NULL, invo_name, NULL, NULL)) == NULL) {
+               adios(NULL, "unable to create temporary file in %s",
+                     get_temp_dir());
+           }
+           distfile = getcpy (cp);
            {
                int in, out;
                struct stat st;
            {
                int in, out;
                struct stat st;
index aa4426e152d65e0339486b460742c044dcf0941c..020949d0a40894bf918ba8b3721262a8ee1463b2 100644 (file)
@@ -99,10 +99,11 @@ sendsbr (char **vec, int vecp, char *program, char *draft, struct stat *st,
         * rename the draft file.  I'm not quite sure why.
         */
        if (pushsw && unique) {
         * rename the draft file.  I'm not quite sure why.
         */
        if (pushsw && unique) {
-            char *cp = m_mktemp2(drft, invo_name, NULL, NULL);
-            if (cp == NULL) {
-                adios ("sendsbr", "unable to create temporary file");
-            }
+           char *cp = m_mktemp2(drft, invo_name, NULL, NULL);
+           if (cp == NULL) {
+               adios(NULL, "unable to create temporary file in %s",
+                     get_temp_dir());
+           }
            if (rename (drft, strncpy(file, cp, sizeof(file))) == NOTOK)
                adios (file, "unable to rename %s to", drft);
            drft = file;
            if (rename (drft, strncpy(file, cp, sizeof(file))) == NOTOK)
                adios (file, "unable to rename %s to", drft);
            drft = file;
@@ -134,7 +135,7 @@ sendsbr (char **vec, int vecp, char *program, char *draft, struct stat *st,
 
     done=exit;
     if (distfile)
 
     done=exit;
     if (distfile)
-       unlink (distfile);
+       (void) m_unlink (distfile);
 
     return status;
 }
 
     return status;
 }
@@ -286,10 +287,10 @@ splitmsg (char **vec, int vecp, char *program, char *drft,
 
        char *cp = m_mktemp2(drft, invo_name, NULL, &out);
         if (cp == NULL) {
 
        char *cp = m_mktemp2(drft, invo_name, NULL, &out);
         if (cp == NULL) {
-           adios (drft, "unable to create temporary file for");
+           adios(NULL, "unable to create temporary file in %s",
+                 get_temp_dir());
         }
        strncpy(tmpdrf, cp, sizeof(tmpdrf));
         }
        strncpy(tmpdrf, cp, sizeof(tmpdrf));
-       chmod (tmpdrf, 0600);
 
        /*
         * Output the header fields
 
        /*
         * Output the header fields
@@ -353,7 +354,7 @@ splitmsg (char **vec, int vecp, char *program, char *drft,
 
        snprintf (partnum, sizeof(partnum), "%d", partno);
        status = sendaux (vec, vecp, program, tmpdrf, st);
 
        snprintf (partnum, sizeof(partnum), "%d", partno);
        status = sendaux (vec, vecp, program, tmpdrf, st);
-       unlink (tmpdrf);
+       (void) m_unlink (tmpdrf);
        if (status != OK)
            break;
 
        if (status != OK)
            break;
 
@@ -395,7 +396,8 @@ sendaux (char **vec, int vecp, char *program, char *drft, struct stat *st)
            snprintf (buf, sizeof(buf), "%d", fd2);
            vec[vecp++] = buf;
        } else {
            snprintf (buf, sizeof(buf), "%d", fd2);
            vec[vecp++] = buf;
        } else {
-           admonish (NULL, "unable to create file for annotation list");
+           admonish (NULL, "unable to create temporary file in %s "
+                      "for annotation list", get_temp_dir());
        }
     }
     if (distfile && distout (drft, distfile, backup) == NOTOK)
        }
     }
     if (distfile && distout (drft, distfile, backup) == NOTOK)
@@ -450,7 +452,7 @@ sendaux (char **vec, int vecp, char *program, char *drft, struct stat *st)
            if (annotext && fd2 != NOTOK)
                close (fd2);
            if (distfile) {
            if (annotext && fd2 != NOTOK)
                close (fd2);
            if (distfile) {
-               unlink (drft);
+               (void) m_unlink (drft);
                if (rename (backup, drft) == NOTOK)
                    advise (drft, "unable to rename %s to", backup);
            }
                if (rename (backup, drft) == NOTOK)
                    advise (drft, "unable to rename %s to", backup);
            }
@@ -536,16 +538,14 @@ static int
 tmp_fd (void)
 {
     int fd;
 tmp_fd (void)
 {
     int fd;
-    char *tfile = NULL;
+    char *tfile;
 
 
-    tfile = m_mktemp2(NULL, invo_name, &fd, NULL);
-    if (tfile == NULL) return NOTOK;
-    fchmod(fd, 0600);
+    if ((tfile = m_mktemp2(NULL, invo_name, &fd, NULL)) == NULL) return NOTOK;
 
     if (debugsw)
        advise (NULL, "temporary file %s selected", tfile);
     else
 
     if (debugsw)
        advise (NULL, "temporary file %s selected", tfile);
     else
-       if (unlink (tfile) == NOTOK)
+       if (m_unlink (tfile) == NOTOK)
            advise (tfile, "unable to remove");
 
     return fd;
            advise (tfile, "unable to remove");
 
     return fd;
@@ -588,6 +588,8 @@ anno (int fd, struct stat *st)
            sigaddset (&set, SIGTERM);
            sigprocmask (SIG_BLOCK, &set, &oset);
 
            sigaddset (&set, SIGTERM);
            sigprocmask (SIG_BLOCK, &set, &oset);
 
+           unregister_for_removal(0);
+
            annoaux (fd);
            if (child_id == OK)
                _exit (0);
            annoaux (fd);
            if (child_id == OK)
                _exit (0);
index 14d4191120d69e9ff8cbea48d6403bc6a5b6257b..acd08afb1bc9cbe1e4ae7a1e5475b6a49ed2e25e 100644 (file)
@@ -61,11 +61,7 @@ main (int argc, char **argv)
     struct msgs_array msgs = { 0, 0, NULL };
     struct msgs_array vec = { 0, 0, NULL };
 
     struct msgs_array msgs = { 0, 0, NULL };
     struct msgs_array vec = { 0, 0, NULL };
 
-    setlocale(LC_ALL, "");
-    invo_name = r1bindex (argv[0], '/');
-
-    /* read user profile/context */
-    context_read();
+    if (nmh_init(argv[0], 1)) { return 1; }
 
     if (!strcasecmp (invo_name, "next")) {
        mode = NEXT;
 
     if (!strcasecmp (invo_name, "next")) {
        mode = NEXT;
index 8dace05901054cab59838cd82fe2edf01e44c7f5..eaa7cb7c5bc2380e086575bfe589dc852e4971dd 100644 (file)
@@ -188,12 +188,7 @@ main (int argc, char **argv)
     char mailbox[BUFSIZ], tmpfil[BUFSIZ];
     char **argp, **arguments;
 
     char mailbox[BUFSIZ], tmpfil[BUFSIZ];
     char **argp, **arguments;
 
-    setlocale(LC_ALL, "");
-    invo_name = r1bindex (*argv, '/');
-
-    /* foil search of user profile/context */
-    if (context_foil (NULL) == -1)
-       done (1);
+    if (nmh_init(argv[0], 0 /* use context_foil() */)) { return 1; }
 
     mts_init (invo_name);
     arguments = getarguments (invo_name, argc, argv, 0);
 
     mts_init (invo_name);
     arguments = getarguments (invo_name, argc, argv, 0);
@@ -315,14 +310,16 @@ main (int argc, char **argv)
        if (debug)
            debug_printf ("retrieving message from file \"%s\"\n", file);
        if ((fd = copy_message (tempfd, tmpfil, 1)) == -1)
        if (debug)
            debug_printf ("retrieving message from file \"%s\"\n", file);
        if ((fd = copy_message (tempfd, tmpfil, 1)) == -1)
-           adios (NULL, "unable to create temporary file");
+           adios(NULL, "unable to create temporary file in %s",
+                  get_temp_dir());
        close (tempfd);
     } else {
        /* getting message from stdin */
        if (debug)
            debug_printf ("retrieving message from stdin\n");
        if ((fd = copy_message (fileno (stdin), tmpfil, 1)) == -1)
        close (tempfd);
     } else {
        /* getting message from stdin */
        if (debug)
            debug_printf ("retrieving message from stdin\n");
        if ((fd = copy_message (fileno (stdin), tmpfil, 1)) == -1)
-           adios (NULL, "unable to create temporary file");
+           adios(NULL, "unable to create temporary file in %s",
+                  get_temp_dir());
     }
 
     if (debug)
     }
 
     if (debug)
@@ -339,7 +336,7 @@ main (int argc, char **argv)
        thing would be to delay this unlink() until later if debug == 1, but I'll
        leave that for someone who cares about the temp-file-accessing
        functionality (they'll have to watch out for cases where we adios()). */
        thing would be to delay this unlink() until later if debug == 1, but I'll
        leave that for someone who cares about the temp-file-accessing
        functionality (they'll have to watch out for cases where we adios()). */
-    unlink (tmpfil);
+    (void) m_unlink (tmpfil);
 
     if (!(fp = fdopen (fd, "r+")))
        adios (NULL, "unable to access temporary file");
 
     if (!(fp = fdopen (fd, "r+")))
        adios (NULL, "unable to access temporary file");
@@ -1196,7 +1193,6 @@ copy_message (int qd, char *tmpfil, int fold)
 
     tfile = m_mktemp2(NULL, invo_name, &fd1, NULL);
     if (tfile == NULL) return -1;
 
     tfile = m_mktemp2(NULL, invo_name, &fd1, NULL);
     if (tfile == NULL) return -1;
-    fchmod(fd1, 0600);
     strncpy (tmpfil, tfile, BUFSIZ);
 
     if (!fold) {
     strncpy (tmpfil, tfile, BUFSIZ);
 
     if (!fold) {
@@ -1204,7 +1200,7 @@ copy_message (int qd, char *tmpfil, int fold)
            if (write (fd1, buffer, i) != i) {
 you_lose:
                close (fd1);
            if (write (fd1, buffer, i) != i) {
 you_lose:
                close (fd1);
-               unlink (tmpfil);
+               (void) m_unlink (tmpfil);
                return -1;
            }
        if (i == -1)
                return -1;
            }
        if (i == -1)
index f6a66f16d1f8980bdeb81752253f5c3947c741ff..3df188592fcb86026b6f7a5c821d44fecd59483d 100644 (file)
@@ -78,11 +78,7 @@ main (int argc, char **argv)
     struct smsg **dlist;
     int checksw = 0;
 
     struct smsg **dlist;
     int checksw = 0;
 
-    setlocale(LC_ALL, "");
-    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;
 
     arguments = getarguments (invo_name, argc, argv, 1);
     argp = arguments;
index 1344738248f99aa8de6893fbacb2dcc8cce2b209..97dee86bf3cfb8ab19d448e0e80e95c1050cd3c4 100644 (file)
@@ -57,10 +57,7 @@ main (int argc, char **argv)
     char *cp, buf[BUFSIZ];
     char **argp, **arguments;
 
     char *cp, buf[BUFSIZ];
     char **argp, **arguments;
 
-    setlocale(LC_ALL, "");
-    invo_name = r1bindex (argv[0], '/');
-
-    context_read();
+    if (nmh_init(argv[0], 1)) { return 1; }
 
     arguments = getarguments (invo_name, argc, argv, 0);
     argp = arguments;
 
     arguments = getarguments (invo_name, argc, argv, 0);
     argp = arguments;
@@ -158,9 +155,9 @@ via_mail (char *mailsw, char *subjsw, char *parmsw, char *descsw,
 
     umask (~m_gmprot ());
 
 
     umask (~m_gmprot ());
 
-    tfile = m_mktemp2(NULL, invo_name, NULL, &fp);
-    if (tfile == NULL) adios("viamail", "unable to create temporary file");
-    chmod(tfile, 0600);
+    if ((tfile = m_mktemp2(NULL, invo_name, NULL, &fp)) == NULL) {
+       adios(NULL, "unable to create temporary file in %s", get_temp_dir());
+    }
     strncpy (tmpfil, tfile, sizeof(tmpfil));
 
     if (!strchr(mailsw, '@'))
     strncpy (tmpfil, tfile, sizeof(tmpfil));
 
     if (!strchr(mailsw, '@'))
@@ -227,8 +224,8 @@ via_mail (char *mailsw, char *subjsw, char *parmsw, char *descsw,
     }
 
     fclose (fp);
     }
 
     fclose (fp);
-    if (unlink (tmpfil) == -1)
-       advise (NULL, "unable to remove temp file %s", tmpfil);
+    if (m_unlink (tmpfil) == -1)
+       advise (tmpfil, "unable to remove temp file %s", tmpfil);
     done (status);
     return 1;
 }
     done (status);
     return 1;
 }
index 4950514e6bcf0a1857a92b80d83bcc884c86340b..031ff3c8cac69a9c0c043dae2eda8eb34d4a9791 100644 (file)
@@ -13,6 +13,7 @@
 int
 main (int argc, char **argv)
 {
 int
 main (int argc, char **argv)
 {
-    setlocale(LC_ALL, "");
+    if (nmh_init(argv[0], 1)) { return 1; }
+
     return WhatNow (argc, argv);
 }
     return WhatNow (argc, argv);
 }
index 005095a8a9818e409d3f99663e209c3928e2d0a9..4a3c2647e9a2974ebef9e085c05caf5a7182194d 100644 (file)
@@ -129,11 +129,6 @@ WhatNow (int argc, char **argv)
     char       *l;                     /* set on -l to alist  command */
     int                n;                      /* set on -n to alist command */
 
     char       *l;                     /* set on -l to alist  command */
     int                n;                      /* set on -n to alist command */
 
-    invo_name = r1bindex (argv[0], '/');
-
-    /* read user profile/context */
-    context_read();
-
     arguments = getarguments (invo_name, argc, argv, 1);
     argp = arguments;
 
     arguments = getarguments (invo_name, argc, argv, 1);
     argp = arguments;
 
@@ -238,7 +233,7 @@ WhatNow (int argc, char **argv)
 #else /* ! READLINE_SUPPORT */
        if (!(argp = getans (prompt, aleqs))) {
 #endif /* READLINE_SUPPORT */
 #else /* ! READLINE_SUPPORT */
        if (!(argp = getans (prompt, aleqs))) {
 #endif /* READLINE_SUPPORT */
-           unlink (LINK);
+           (void) m_unlink (LINK);
            done (1);
        }
        switch (smatch (*argp, aleqs)) {
            done (1);
        }
        switch (smatch (*argp, aleqs)) {
@@ -681,7 +676,7 @@ editfile (char **ed, char **arg, char *file, int use, struct msgs *mp,
            snprintf (linkpath, sizeof(linkpath), "%s/%s", cwd, LINK);
 
        if (atfile) {
            snprintf (linkpath, sizeof(linkpath), "%s/%s", cwd, LINK);
 
        if (atfile) {
-           unlink (linkpath);
+           (void) m_unlink (linkpath);
            if (link (altpath, linkpath) == NOTOK) {
                symlink (altpath, linkpath);
                slinked = 1;
            if (link (altpath, linkpath) == NOTOK) {
                symlink (altpath, linkpath);
                slinked = 1;
@@ -747,7 +742,7 @@ editfile (char **ed, char **arg, char *file, int use, struct msgs *mp,
                                && copyf (linkpath, altpath) == NOTOK
                           : stat (linkpath, &st) != NOTOK
                                && st.st_nlink == 1
                                && copyf (linkpath, altpath) == NOTOK
                           : stat (linkpath, &st) != NOTOK
                                && st.st_nlink == 1
-                               && (unlink (altpath) == NOTOK
+                               && (m_unlink (altpath) == NOTOK
                                        || link (linkpath, altpath) == NOTOK)))
                advise (linkpath, "unable to update %s from", altmsg);
     }
                                        || link (linkpath, altpath) == NOTOK)))
                advise (linkpath, "unable to update %s from", altmsg);
     }
@@ -758,7 +753,7 @@ editfile (char **ed, char **arg, char *file, int use, struct msgs *mp,
 
     *ed = NULL;
     if (altmsg && atfile)
 
     *ed = NULL;
     if (altmsg && atfile)
-       unlink (linkpath);
+       (void) m_unlink (linkpath);
 
     return status;
 }
 
     return status;
 }
@@ -1194,8 +1189,12 @@ sendit (char *sp, char **arg, char *file, int pushed)
 #endif /* not lint */
            && altmsg) {
        vec[vecp++] = "-dist";
 #endif /* not lint */
            && altmsg) {
        vec[vecp++] = "-dist";
-       distfile = getcpy (m_mktemp2(altmsg, invo_name, NULL, NULL));
-       unlink(distfile);
+       if ((cp = m_mktemp2(altmsg, invo_name, NULL, NULL)) == NULL) {
+           adios(NULL, "unable to create temporary file in %s",
+                 get_temp_dir());
+       }
+       distfile = getcpy (cp);
+       (void) m_unlink(distfile);
        if (link (altmsg, distfile) == NOTOK)
            adios (distfile, "unable to link %s to", altmsg);
     } else {
        if (link (altmsg, distfile) == NOTOK)
            adios (distfile, "unable to link %s to", altmsg);
     } else {
@@ -1261,7 +1260,7 @@ whomfile (char **arg, char *file)
 static int
 removefile (char *drft)
 {
 static int
 removefile (char *drft)
 {
-    if (unlink (drft) == NOTOK)
+    if (m_unlink (drft) == NOTOK)
        adios (drft, "unable to unlink");
 
     return OK;
        adios (drft, "unable to unlink");
 
     return OK;
index 8973c76222aca1472a932013719cd02ffeae3a1c..2a36025aeb6846425a9e4036390c1e120bfc298c 100644 (file)
@@ -63,11 +63,7 @@ main (int argc, char **argv)
     char *msg = NULL, **ap, **argp, backup[BUFSIZ];
     char buf[BUFSIZ], **arguments, *vec[MAXARGS];
 
     char *msg = NULL, **ap, **argp, backup[BUFSIZ];
     char buf[BUFSIZ], **arguments, *vec[MAXARGS];
 
-    setlocale(LC_ALL, "");
-    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;
 
     arguments = getarguments (invo_name, argc, argv, 1);
     argp = arguments;
@@ -200,7 +196,7 @@ main (int argc, char **argv)
 
            status = pidwait(child_id, OK);
 
 
            status = pidwait(child_id, OK);
 
-           unlink (msg);
+           (void) m_unlink (msg);
            if (rename (backup, msg) == NOTOK)
                adios (msg, "unable to rename %s to", backup);
            done (status);
            if (rename (backup, msg) == NOTOK)
                adios (msg, "unable to rename %s to", backup);
            done (status);