X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/6b4bc4a25eaac2eddd1bef51e3f00c21f98ed32d..63621a81d16ab743de6b57d47578a9a2c670ad22:/uip/rcvstore.c diff --git a/uip/rcvstore.c b/uip/rcvstore.c index 9a89230e..6f82f812 100644 --- a/uip/rcvstore.c +++ b/uip/rcvstore.c @@ -1,6 +1,4 @@ - -/* - * rcvstore.c -- asynchronously add mail to a folder +/* rcvstore.c -- asynchronously add mail to a folder * * This code is Copyright (c) 2002, by the authors of nmh. See the * COPYRIGHT file in the root directory of the nmh distribution for @@ -10,9 +8,11 @@ #include #include #include -#include -#include #include +#include +#include "sbr/m_maildir.h" +#include "sbr/m_mktemp.h" +#include "sbr/makedir.h" #define RCVSTORE_SWITCHES \ X("create", 0, CRETSW) \ @@ -51,21 +51,16 @@ main (int argc, char **argv) int fd, msgnum; size_t seqp = 0; char *cp, *maildir, *folder = NULL, buf[BUFSIZ]; - char **argp, **arguments, *seqs[NUMATTRS+1]; + char **argp, **arguments; + svector_t seqs = svector_create (0); struct msgs *mp; struct stat st; - done=unlink_done; - -#ifdef LOCALE - setlocale(LC_ALL, ""); -#endif - invo_name = r1bindex (argv[0], '/'); + if (nmh_init(argv[0], 2)) { return 1; } - /* read user profile/context */ - context_read(); + done=unlink_done; - mts_init (invo_name); + mts_init (); arguments = getarguments (invo_name, argc, argv, 1); argp = arguments; @@ -92,10 +87,8 @@ main (int argc, char **argv) if (!(cp = *argp++) || *cp == '-') adios (NULL, "missing argument name to %s", argp[-2]); - /* check if too many sequences specified */ - if (seqp >= NUMATTRS) - adios (NULL, "too many sequences (more than %d) specified", NUMATTRS); - seqs[seqp++] = cp; + svector_push_back (seqs, cp); + seqp++; continue; case UNSEENSW: @@ -130,15 +123,12 @@ main (int argc, char **argv) if (*cp == '+' || *cp == '@') { if (folder) adios (NULL, "only one folder at a time!"); - else - folder = pluspath (cp); + folder = pluspath (cp); } else { adios (NULL, "usage: %s [+folder] [switches]", invo_name); } } - seqs[seqp] = NULL; /* NULL terminate list of sequences */ - if (!context_find ("path")) free (path ("./", TFOLDER)); @@ -169,7 +159,7 @@ main (int argc, char **argv) /* 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()); @@ -177,7 +167,7 @@ main (int argc, char **argv) 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) @@ -185,8 +175,8 @@ main (int argc, char **argv) /* don't add file if it is empty */ if (st.st_size == 0) { - unlink (tmpfilenam); - advise (NULL, "empty file"); + (void) m_unlink (tmpfilenam); + inform("empty file"); done (0); } @@ -200,24 +190,30 @@ 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, 0, (char *)0)) == -1) + if ((msgnum = folder_addmsg (&mp, tmpfilenam, 0, unseensw, 0, 0, NULL)) == -1) done (1); /* * Add the message to any extra sequences * that have been specified. */ - for (seqp = 0; seqs[seqp]; seqp++) { - if (!seq_addmsg (mp, seqs[seqp], msgnum, publicsw, zerosw)) - done (1); + if (seqp) { + /* The only reason that seqp was checked to be non-zero is in + case a -nosequence switch is added. */ + for (seqp = 0; seqp < svector_size (seqs); seqp++) { + if (!seq_addmsg (mp, svector_at (seqs, seqp), msgnum, publicsw, + zerosw)) + done (1); + } } + svector_free (seqs); seq_setunseen (mp, 0); /* synchronize any Unseen-Sequence's */ seq_save (mp); /* synchronize and save message sequences */ 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); @@ -227,10 +223,10 @@ main (int argc, char **argv) /* * Clean up and exit */ -static void +static void NORETURN unlink_done(int status) { if (tmpfilenam && *tmpfilenam) - unlink (tmpfilenam); + (void) m_unlink (tmpfilenam); exit (status); }