X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/6bc64765f773ce75454ec1592a86779e3547fe46..ec173fd2c:/uip/rcvstore.c?ds=sidebyside diff --git a/uip/rcvstore.c b/uip/rcvstore.c index be0ac396..58dba169 100644 --- a/uip/rcvstore.c +++ b/uip/rcvstore.c @@ -1,16 +1,37 @@ - -/* - * 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 * complete copyright information. */ -#include +#include "h/mh.h" +#include "sbr/m_gmprot.h" +#include "sbr/getarguments.h" +#include "sbr/seq_setunseen.h" +#include "sbr/seq_save.h" +#include "sbr/smatch.h" +#include "sbr/cpydata.h" +#include "sbr/getfolder.h" +#include "sbr/folder_read.h" +#include "sbr/folder_free.h" +#include "sbr/folder_addmsg.h" +#include "sbr/context_save.h" +#include "sbr/context_find.h" +#include "sbr/ambigsw.h" +#include "sbr/path.h" +#include "sbr/print_version.h" +#include "sbr/print_help.h" +#include "sbr/seq_add.h" +#include "sbr/error.h" #include -#include -#include +#include "h/signals.h" +#include "h/mts.h" +#include "h/done.h" +#include "h/utils.h" +#include "sbr/m_maildir.h" +#include "sbr/m_mktemp.h" +#include "sbr/makedir.h" #define RCVSTORE_SWITCHES \ X("create", 0, CRETSW) \ @@ -44,8 +65,10 @@ static void unlink_done(int) NORETURN; int main (int argc, char **argv) { - int publicsw = -1, zerosw = 0; - int create = 1, unseensw = 1; + int publicsw = -1; + bool zerosw = false; + bool create = true; + bool unseensw = true; int fd, msgnum; size_t seqp = 0; char *cp, *maildir, *folder = NULL, buf[BUFSIZ]; @@ -54,11 +77,11 @@ main (int argc, char **argv) struct msgs *mp; struct stat st; - if (nmh_init(argv[0], 1)) { return 1; } + if (nmh_init(argv[0], true, false)) { return 1; } - done=unlink_done; + set_done(unlink_done); - mts_init (invo_name); + mts_init (); arguments = getarguments (invo_name, argc, argv, 1); argp = arguments; @@ -70,7 +93,7 @@ main (int argc, char **argv) ambigsw (cp, switches); done (1); case UNKWNSW: - adios (NULL, "-%s unknown", cp); + die("-%s unknown", cp); case HELPSW: snprintf (buf, sizeof(buf), "%s [+folder] [switches]", @@ -83,17 +106,17 @@ main (int argc, char **argv) case SEQSW: if (!(cp = *argp++) || *cp == '-') - adios (NULL, "missing argument name to %s", argp[-2]); + die("missing argument name to %s", argp[-2]); svector_push_back (seqs, cp); seqp++; continue; case UNSEENSW: - unseensw = 1; + unseensw = true; continue; case NUNSEENSW: - unseensw = 0; + unseensw = false; continue; case PUBSW: @@ -104,27 +127,26 @@ main (int argc, char **argv) continue; case ZEROSW: - zerosw++; + zerosw = true; continue; case NZEROSW: - zerosw = 0; + zerosw = false; continue; case CRETSW: - create++; + create = true; continue; case NCRETSW: - create = 0; + create = false; continue; } } if (*cp == '+' || *cp == '@') { if (folder) - adios (NULL, "only one folder at a time!"); - else - folder = pluspath (cp); + die("only one folder at a time!"); + folder = pluspath (cp); } else { - adios (NULL, "usage: %s [+folder] [switches]", invo_name); + die("usage: %s [+folder] [switches]", invo_name); } } @@ -141,9 +163,9 @@ main (int argc, char **argv) if (errno != ENOENT) adios (maildir, "error on folder"); if (!create) - adios (NULL, "folder %s doesn't exist", maildir); + die("folder %s doesn't exist", maildir); if (!makedir (maildir)) - adios (NULL, "unable to create folder %s", maildir); + die("unable to create folder %s", maildir); } if (chdir (maildir) == NOTOK) @@ -158,7 +180,7 @@ main (int argc, char **argv) /* create a temporary file */ tmpfilenam = m_mktemp (invo_name, &fd, NULL); if (tmpfilenam == NULL) { - adios(NULL, "unable to create temporary file in %s", get_temp_dir()); + die("unable to create temporary file in %s", get_temp_dir()); } chmod (tmpfilenam, m_gmprot()); @@ -175,7 +197,7 @@ main (int argc, char **argv) /* don't add file if it is empty */ if (st.st_size == 0) { (void) m_unlink (tmpfilenam); - advise (NULL, "empty file"); + inform("empty file"); done (0); } @@ -183,13 +205,13 @@ main (int argc, char **argv) * read folder and create message structure */ if (!(mp = folder_read (folder, 1))) - adios (NULL, "unable to read folder %s", folder); + die("unable to read folder %s", folder); /* * 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); /* @@ -222,7 +244,7 @@ main (int argc, char **argv) /* * Clean up and exit */ -static void +static void NORETURN unlink_done(int status) { if (tmpfilenam && *tmpfilenam)