2 ** rmm.c -- remove a message(s)
4 ** This code is Copyright (c) 2002, by the authors of nmh. See the
5 ** COPYRIGHT file in the root directory of the nmh distribution for
6 ** complete copyright information.
12 static struct swit switches[] = {
26 main(int argc, char **argv)
28 int msgnum, unlink_msgs = 0, vecp = 0;
29 char *cp, *maildir, *folder = NULL, **vec;
30 char buf[BUFSIZ], **argp;
32 struct msgs_array msgs = { 0, 0, NULL };
35 setlocale(LC_ALL, "");
36 invo_name = mhbasename(argv[0]);
40 arguments = getarguments(invo_name, argc, argv, 1);
44 while ((cp = *argp++)) {
46 switch (smatch(++cp, switches)) {
48 ambigsw(cp, switches);
51 adios(NULL, "-%s unknown\n", cp);
54 snprintf(buf, sizeof(buf), "%s [+folder] [msgs] [switches]", invo_name);
55 print_help(buf, switches, 1);
58 print_version(invo_name);
69 if (*cp == '+' || *cp == '@') {
71 adios(NULL, "only one folder at a time!");
73 folder = getcpy(expandfol(cp));
76 app_msgarg(&msgs, cp);
81 app_msgarg(&msgs, seq_cur);
86 maildir = toabsdir(folder);
88 if (chdir(maildir) == NOTOK) {
89 adios(maildir, "unable to change directory to");
92 /* read folder and create message structure */
93 if (!(mp = folder_read(folder))) {
94 adios(NULL, "unable to read folder %s", folder);
96 if (mp->nummsg == 0) {
97 adios(NULL, "no messages in %s", folder);
100 ** parse all the message ranges/sequences and set SELECTED
101 ** (We do this for the refiling case as well, to complain
102 ** about invalid msg arguments in rmm, before we call refile.)
104 for (msgnum = 0; msgnum < msgs.size; msgnum++) {
105 if (!m_convert(mp, msgs.msgs[msgnum])) {
110 context_replace(curfolder, folder);
114 /* "remove" the SELECTED messages */
115 folder_delmsgs(mp, 1);
123 /* remove by refiling. */
128 if (msgs.size+6 > MAXARGS) {
129 adios(NULL, "more than %d messages for refile exec",
132 vec = (char **)mh_xmalloc((size_t)(msgs.size + 6) * sizeof(*vec));
133 vec[vecp++] = "refile";
134 vec[vecp++] = "-src";
135 vec[vecp++] = concat("+", folder, NULL);
136 vec[vecp++] = "-nolink";
137 vec[vecp++] = concat("+", trashfolder, NULL);
138 for (msgnum = 0; msgnum < msgs.size; msgnum++) {
139 vec[vecp++] = msgs.msgs[msgnum];
142 done(execprog(*vec, vec));
144 return 1; /* just in case ... */