* complete copyright information.
*/
-#include <h/mh.h>
-#include <h/utils.h>
-#include "../sbr/m_maildir.h"
-#include "../sbr/m_mktemp.h"
+#include "h/mh.h"
+#include "sbr/remdir.h"
+#include "sbr/ssequal.h"
+#include "sbr/m_atoi.h"
+#include "sbr/getfolder.h"
+#include "sbr/ext_hook.h"
+#include "sbr/context_save.h"
+#include "sbr/context_replace.h"
+#include "sbr/context_del.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/error.h"
+#include "h/done.h"
+#include "h/utils.h"
+#include "sbr/m_maildir.h"
+#include "sbr/m_mktemp.h"
#define RMF_SWITCHES \
X("interactive", 0, INTRSW) \
int
main (int argc, char **argv)
{
- int defolder = 0, interactive = -1;
+ bool defolder = false;
+ int interactive = -1;
char *cp, *folder = NULL, newfolder[BUFSIZ];
char buf[BUFSIZ], **argp, **arguments;
+ char *fp;
- if (nmh_init(argv[0], 1)) { return 1; }
+ if (nmh_init(argv[0], true, true)) { return 1; }
arguments = getarguments (invo_name, argc, argv, 1);
argp = arguments;
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]",
}
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);
}
}
free (path ("./", TFOLDER));
if (!folder) {
folder = getfolder (1);
- defolder++;
+ defolder = true;
}
- if (strcmp (m_mailpath (folder), pwd ()) == 0)
- adios (NULL, "sorry, you can't remove the current working directory");
+ fp = m_mailpath(folder);
+ if (!strcmp(fp, pwd()))
+ die("sorry, you can't remove the current working directory");
+ free(fp);
if (interactive == -1)
interactive = defolder;
static int
rmf (char *folder)
{
- int i, others;
+ int i;
+ bool others;
+ char *fp;
char *maildir;
char cur[BUFSIZ];
struct dirent *dp;
/* FALLTHRU */
case NOTOK:
- snprintf (cur, sizeof(cur), "atr-%s-%s",
- current, m_mailpath (folder));
+ fp = m_mailpath(folder);
+ snprintf (cur, sizeof(cur), "atr-%s-%s", current, fp);
+ free(fp);
if (!context_del (cur)) {
printf ("[+%s de-referenced]\n", folder);
return OK;
}
if ((dd = opendir (".")) == NULL)
- adios (NULL, "unable to read folder +%s", folder);
- others = 0;
+ die("unable to read folder +%s", folder);
+ others = false;
/*
* Run the external delete hook program.
if (strcmp (dp->d_name, ".") == 0
|| strcmp (dp->d_name, "..") == 0)
continue;
- /* FALLTHRU */
+ break;
case ',':
break;
inform("file \"%s/%s\" not deleted, continuing...",
folder, dp->d_name);
- others++;
+ others = true;
continue;
}
if (m_unlink (dp->d_name) == NOTOK) {
admonish (dp->d_name, "unable to unlink %s:", folder);
- others++;
+ others = true;
}
}
if (chdir ("..") < 0) {
advise ("..", "chdir");
}
- if (others == 0 && remdir (maildir))
+ if (!others && remdir (maildir))
return OK;
inform("folder +%s not removed", folder);
pp = np;
}
}
+
+ free(cp);
}