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 };
36 setlocale(LC_ALL, "");
37 invo_name = mhbasename(argv[0]);
41 arguments = getarguments(invo_name, argc, argv, 1);
45 while ((cp = *argp++)) {
47 switch (smatch(++cp, switches)) {
49 ambigsw(cp, switches);
52 adios(NULL, "-%s unknown\n", cp);
55 snprintf(buf, sizeof(buf), "%s [+folder] [msgs] [switches]", invo_name);
56 print_help(buf, switches, 1);
59 print_version(invo_name);
70 if (*cp == '+' || *cp == '@') {
72 adios(NULL, "only one folder at a time!");
74 folder = getcpy(expandfol(cp));
77 app_msgarg(&msgs, cp);
82 app_msgarg(&msgs, seq_cur);
87 maildir = toabsdir(folder);
89 if (chdir(maildir) == NOTOK) {
90 adios(maildir, "unable to change directory to");
93 /* read folder and create message structure */
94 if (!(mp = folder_read(folder))) {
95 adios(NULL, "unable to read folder %s", folder);
97 if (mp->nummsg == 0) {
98 adios(NULL, "no messages in %s", folder);
101 ** parse all the message ranges/sequences and set SELECTED
102 ** (We do this for the refiling case as well, to complain
103 ** about invalid msg arguments in rmm, before we call refile.)
105 for (msgnum = 0; msgnum < msgs.size; msgnum++) {
106 if (!m_convert(mp, msgs.msgs[msgnum])) {
111 context_replace(curfolder, folder);
115 /* "remove" the SELECTED messages */
116 folder_delmsgs(mp, 1);
124 /* remove by refiling. */
129 if (msgs.size+6 > MAXARGS) {
130 adios(NULL, "more than %d messages for refile exec",
133 vec = (char **)mh_xmalloc((size_t)(msgs.size + 6) * sizeof(*vec));
134 vec[vecp++] = "refile";
135 vec[vecp++] = "-src";
136 vec[vecp++] = concat("+", folder, NULL);
137 vec[vecp++] = "-nolink";
138 vec[vecp++] = concat("+", trashfolder, NULL);
139 for (msgnum = 0; msgnum < msgs.size; msgnum++) {
140 vec[vecp++] = msgs.msgs[msgnum];
145 switch (pid = fork()) {
147 adios("fork", "unable to");
151 fprintf(stderr, "unable to exec ");