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;
29 char *cp, *maildir, *folder = NULL;
30 char buf[BUFSIZ], **argp;
32 struct msgs_array msgs = { 0, 0, NULL };
36 setlocale(LC_ALL, "");
38 invo_name = mhbasename(argv[0]);
40 /* read user profile/context */
43 arguments = getarguments(invo_name, argc, argv, 1);
47 while ((cp = *argp++)) {
49 switch (smatch(++cp, switches)) {
51 ambigsw(cp, switches);
54 adios(NULL, "-%s unknown\n", cp);
57 snprintf(buf, sizeof(buf), "%s [+folder] [msgs] [switches]", invo_name);
58 print_help(buf, switches, 1);
61 print_version(invo_name);
72 if (*cp == '+' || *cp == '@') {
74 adios(NULL, "only one folder at a time!");
76 folder = getcpy(expandfol(cp));
78 app_msgarg(&msgs, cp);
82 app_msgarg(&msgs, "cur");
85 maildir = toabsdir(folder);
87 if (chdir(maildir) == NOTOK)
88 adios(maildir, "unable to change directory to");
90 /* read folder and create message structure */
91 if (!(mp = folder_read(folder)))
92 adios(NULL, "unable to read folder %s", folder);
94 /* check for empty folder */
96 adios(NULL, "no messages in %s", folder);
98 /* parse all the message ranges/sequences and set SELECTED */
99 for (msgnum = 0; msgnum < msgs.size; msgnum++)
100 if (!m_convert(mp, msgs.msgs[msgnum]))
102 seq_setprev(mp); /* set the previous-sequence */
105 ** This is hackish. If we are using a external rmmproc,
106 ** then we need to update the current folder in the
107 ** context so the external rmmproc will remove files
108 ** from the correct directory. This should be moved to
112 context_replace(curfolder, folder);
117 /* "remove" the SELECTED messages */
118 folder_delmsgs(mp, unlink_msgs, 0);
120 seq_save(mp); /* synchronize message sequences */
121 context_replace(curfolder, folder); /* update current folder */
122 context_save(); /* save the context file */
123 folder_free(mp); /* free folder structure */