/*
* rcvstore.c -- asynchronously add mail to a folder
*
- * $Id$
- *
* This code is Copyright (c) 2002, by the authors of nmh. See the
* COPYRIGHT file in the root directory of the nmh distribution for
* complete copyright information.
*/
static char *tmpfilenam = NULL;
+static void unlink_done(int) NORETURN;
int
main (int argc, char **argv)
{
int publicsw = -1, zerosw = 0;
int create = 1, unseensw = 1;
- int fd, msgnum, seqp = 0;
+ int fd, msgnum;
+ size_t seqp = 0;
char *cp, *maildir, *folder = NULL, buf[BUFSIZ];
char **argp, **arguments, *seqs[NUMATTRS+1];
struct msgs *mp;
struct stat st;
+ done=unlink_done;
+
#ifdef LOCALE
setlocale(LC_ALL, "");
#endif
if (folder)
adios (NULL, "only one folder at a time!");
else
- folder = path (cp + 1, *cp == '+' ? TFOLDER : TSUBCWF);
+ folder = pluspath (cp);
} else {
adios (NULL, "usage: %s [+folder] [switches]", invo_name);
}
SIGNAL (SIGTERM, SIG_IGN);
/* create a temporary file */
- tmpfilenam = m_scratch ("", invo_name);
- if ((fd = creat (tmpfilenam, m_gmprot ())) == NOTOK)
- adios (tmpfilenam, "unable to create");
+ tmpfilenam = m_mktemp (invo_name, &fd, NULL);
+ if (tmpfilenam == NULL) {
+ adios ("rcvstore", "unable to create temporary file");
+ }
chmod (tmpfilenam, m_gmprot());
/* copy the message from stdin into temp file */
unlink (tmpfilenam); /* remove temporary file */
tmpfilenam = NULL;
- return done (0);
+ done (0);
+ return 1;
}
/*
* Clean up and exit
*/
-int
-done(int status)
+static void
+unlink_done(int status)
{
if (tmpfilenam && *tmpfilenam)
unlink (tmpfilenam);
exit (status);
- return 1; /* dead code to satisfy the compiler */
}