X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/dbbbe1b73d4eba1f4d0d55ccab54f2f7130f395d..0b7286788a95dd854d1826b8493eda431d8e8aac:/uip/rcvstore.c diff --git a/uip/rcvstore.c b/uip/rcvstore.c index a7d3a9e9..61980ea2 100644 --- a/uip/rcvstore.c +++ b/uip/rcvstore.c @@ -1,16 +1,30 @@ - -/* - * 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/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 +58,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,9 +70,9 @@ 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 (); arguments = getarguments (invo_name, argc, argv, 1); @@ -70,7 +86,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 +99,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 +120,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 +156,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 +173,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 +190,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 +198,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 +237,7 @@ main (int argc, char **argv) /* * Clean up and exit */ -static void +static void NORETURN unlink_done(int status) { if (tmpfilenam && *tmpfilenam)