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);
98 /* check for empty folder */
99 if (mp->nummsg == 0) {
100 adios(NULL, "no messages in %s", folder);
103 /* parse all the message ranges/sequences and set SELECTED */
104 for (msgnum = 0; msgnum < msgs.size; msgnum++) {
105 if (!m_convert(mp, msgs.msgs[msgnum])) {
109 seq_setprev(mp); /* set the previous-sequence */
113 /* "remove" the SELECTED messages */
114 folder_delmsgs(mp, 1);
117 context_replace(curfolder, folder);
125 ** This is hackish. If we don't unlink, but refile,
126 ** then we need to update the current folder in the
127 ** context so the external program will refile files
128 ** from the correct directory.
130 context_replace(curfolder, folder);
134 /* remove by refiling. */
135 /* Unset the EXISTS flag for each message to be removed */
136 for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) {
137 if (is_selected(mp, msgnum)) {
138 unset_exists(mp, msgnum);
142 /* Mark that the sequence information has changed */
143 mp->msgflags |= SEQMOD;
145 if (mp->numsel+4 > MAXARGS) {
146 adios(NULL, "more than %d messages for refile exec",
149 vec = (char **)mh_xmalloc((size_t)(mp->numsel + 4) * sizeof(*vec));
150 vec[vecp++] = "refile";
151 vec[vecp++] = "-nolink";
152 vec[vecp++] = concat("+", trashfolder, NULL);
153 for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) {
154 if (!is_selected(mp, msgnum)) {
157 if (!(vec[vecp++] = strdup(m_name(msgnum)))) {
158 adios(NULL, "strdup failed");
164 switch (pid = fork()) {
166 adios("fork", "unable to");
170 fprintf(stderr, "unable to exec ");