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 };
38 setlocale(LC_ALL, "");
40 invo_name = mhbasename(argv[0]);
44 arguments = getarguments(invo_name, argc, argv, 1);
48 while ((cp = *argp++)) {
50 switch (smatch(++cp, switches)) {
52 ambigsw(cp, switches);
55 adios(NULL, "-%s unknown\n", cp);
58 snprintf(buf, sizeof(buf), "%s [+folder] [msgs] [switches]", invo_name);
59 print_help(buf, switches, 1);
62 print_version(invo_name);
73 if (*cp == '+' || *cp == '@') {
75 adios(NULL, "only one folder at a time!");
77 folder = getcpy(expandfol(cp));
79 app_msgarg(&msgs, cp);
83 app_msgarg(&msgs, seq_cur);
86 maildir = toabsdir(folder);
88 if (chdir(maildir) == NOTOK)
89 adios(maildir, "unable to change directory to");
91 /* read folder and create message structure */
92 if (!(mp = folder_read(folder)))
93 adios(NULL, "unable to read folder %s", folder);
95 /* check for empty folder */
97 adios(NULL, "no messages in %s", folder);
99 /* parse all the message ranges/sequences and set SELECTED */
100 for (msgnum = 0; msgnum < msgs.size; msgnum++)
101 if (!m_convert(mp, msgs.msgs[msgnum]))
103 seq_setprev(mp); /* set the previous-sequence */
107 /* "remove" the SELECTED messages */
108 folder_delmsgs(mp, 1);
111 context_replace(curfolder, folder);
119 ** This is hackish. If we don't unlink, but refile,
120 ** then we need to update the current folder in the
121 ** context so the external program will refile files
122 ** from the correct directory.
124 context_replace(curfolder, folder);
128 /* remove by refiling. */
129 /* Unset the EXISTS flag for each message to be removed */
130 for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) {
131 if (is_selected(mp, msgnum))
132 unset_exists(mp, msgnum);
135 /* Mark that the sequence information has changed */
136 mp->msgflags |= SEQMOD;
138 if (mp->numsel+4 > MAXARGS)
139 adios(NULL, "more than %d messages for refile exec",
141 vec = (char **)mh_xmalloc((size_t)(mp->numsel + 4) * sizeof(*vec));
142 vec[vecp++] = "refile";
143 vec[vecp++] = "-nolink";
144 vec[vecp++] = concat("+", trashfolder, NULL);
145 for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) {
146 if (!is_selected(mp, msgnum)) {
149 if (!(vec[vecp++] = strdup(m_name(msgnum)))) {
150 adios(NULL, "strdup failed");
156 switch (pid = fork()) {
158 adios("fork", "unable to");
162 fprintf(stderr, "unable to exec ");