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.
14 static struct swit switches[] = {
28 main(int argc, char **argv)
30 int msgnum, unlink_msgs = 0, vecp = 0;
31 char *cp, *maildir, *folder = NULL, **vec;
32 char buf[BUFSIZ], **argp;
34 struct msgs_array msgs = { 0, 0, NULL };
37 setlocale(LC_ALL, "");
38 invo_name = mhbasename(argv[0]);
42 arguments = getarguments(invo_name, argc, argv, 1);
46 while ((cp = *argp++)) {
48 switch (smatch(++cp, switches)) {
50 ambigsw(cp, switches);
53 adios(NULL, "-%s unknown\n", cp);
56 snprintf(buf, sizeof(buf), "%s [+folder] [msgs] [switches]", invo_name);
57 print_help(buf, switches, 1);
60 print_version(invo_name);
71 if (*cp == '+' || *cp == '@') {
73 adios(NULL, "only one folder at a time!");
75 folder = getcpy(expandfol(cp));
78 app_msgarg(&msgs, cp);
83 app_msgarg(&msgs, seq_cur);
88 maildir = toabsdir(folder);
90 if (chdir(maildir) == NOTOK) {
91 adios(maildir, "unable to change directory to");
94 /* read folder and create message structure */
95 if (!(mp = folder_read(folder))) {
96 adios(NULL, "unable to read folder %s", folder);
98 if (mp->nummsg == 0) {
99 adios(NULL, "no messages in %s", folder);
102 ** parse all the message ranges/sequences and set SELECTED
103 ** (We do this for the refiling case as well, to complain
104 ** about invalid msg arguments in rmm, before we call refile.)
106 for (msgnum = 0; msgnum < msgs.size; msgnum++) {
107 if (!m_convert(mp, msgs.msgs[msgnum])) {
108 /* sysexits EX_USAGE */
113 context_replace(curfolder, folder);
117 /* "remove" the SELECTED messages */
118 folder_delmsgs(mp, 1);
125 /* remove by refiling. */
130 if (msgs.size+6 > MAXARGS) {
131 adios(NULL, "more than %d messages for refile exec",
134 vec = (char **)mh_xmalloc((size_t)(msgs.size + 6) * sizeof(*vec));
135 vec[vecp++] = "refile";
136 vec[vecp++] = "-src";
137 vec[vecp++] = concat("+", folder, NULL);
138 vec[vecp++] = "-nolink";
139 vec[vecp++] = concat("+", trashfolder, NULL);
140 for (msgnum = 0; msgnum < msgs.size; msgnum++) {
141 vec[vecp++] = msgs.msgs[msgnum];
145 return execprog(*vec, vec);