X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/3c9700d8d045f3ff26ce5dd2a174454dafc14822..78211e93:/uip/rcvstore.c?ds=sidebyside diff --git a/uip/rcvstore.c b/uip/rcvstore.c index 5a3dcbe0..3afe12e3 100644 --- a/uip/rcvstore.c +++ b/uip/rcvstore.c @@ -2,7 +2,9 @@ /* * 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. */ #include @@ -10,52 +12,51 @@ #include #include #include +#include + +#define RCVSTORE_SWITCHES \ + X("create", 0, CRETSW) \ + X("nocreate", 0, NCRETSW) \ + X("unseen", 0, UNSEENSW) \ + X("nounseen", 0, NUNSEENSW) \ + X("public", 0, PUBSW) \ + X("nopublic", 0, NPUBSW) \ + X("zero", 0, ZEROSW) \ + X("nozero", 0, NZEROSW) \ + X("sequence name", 0, SEQSW) \ + X("version", 0, VERSIONSW) \ + X("help", 0, HELPSW) \ + +#define X(sw, minchars, id) id, +DEFINE_SWITCH_ENUM(RCVSTORE); +#undef X + +#define X(sw, minchars, id) { sw, minchars, id }, +DEFINE_SWITCH_ARRAY(RCVSTORE, switches); +#undef X -static struct swit switches[] = { -#define CRETSW 0 - { "create", 0 }, -#define NCRETSW 1 - { "nocreate", 0 }, -#define UNSEENSW 2 - { "unseen", 0 }, -#define NUNSEENSW 3 - { "nounseen", 0 }, -#define PUBSW 4 - { "public", 0 }, -#define NPUBSW 5 - { "nopublic", 0 }, -#define ZEROSW 6 - { "zero", 0 }, -#define NZEROSW 7 - { "nozero", 0 }, -#define SEQSW 8 - { "sequence name", 0 }, -#define VERSIONSW 9 - { "version", 0 }, -#define HELPSW 10 - { "help", 4 }, - { NULL, 0 } -}; - -extern int errno; /* * name of temporary file to store incoming message */ 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 @@ -82,10 +83,10 @@ main (int argc, char **argv) snprintf (buf, sizeof(buf), "%s [+folder] [switches]", invo_name); print_help (buf, switches, 1); - done (1); + done (0); case VERSIONSW: print_version(invo_name); - done (1); + done (0); case SEQSW: if (!(cp = *argp++) || *cp == '-') @@ -130,7 +131,7 @@ main (int argc, char **argv) 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); } @@ -166,9 +167,10 @@ main (int argc, char **argv) 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 */ @@ -198,7 +200,7 @@ main (int argc, char **argv) * Link message into folder, and possibly add * to the Unseen-Sequence's. */ - if ((msgnum = folder_addmsg (&mp, tmpfilenam, 0, unseensw, 0)) == -1) + if ((msgnum = folder_addmsg (&mp, tmpfilenam, 0, unseensw, 0, 0, (char *)0)) == -1) done (1); /* @@ -218,17 +220,17 @@ main (int argc, char **argv) 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 */ }