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 = pluspath(cp);
78 app_msgarg(&msgs, cp);
81 if (!context_find("path"))
82 free(path("./", TFOLDER));
84 app_msgarg(&msgs, "cur");
86 folder = getfolder(1);
87 maildir = m_maildir(folder);
89 if (chdir(maildir) == NOTOK)
90 adios(maildir, "unable to change directory to");
92 /* read folder and create message structure */
93 if (!(mp = folder_read(folder)))
94 adios(NULL, "unable to read folder %s", folder);
96 /* check for empty folder */
98 adios(NULL, "no messages in %s", folder);
100 /* parse all the message ranges/sequences and set SELECTED */
101 for (msgnum = 0; msgnum < msgs.size; msgnum++)
102 if (!m_convert(mp, msgs.msgs[msgnum]))
104 seq_setprev(mp); /* set the previous-sequence */
107 ** This is hackish. If we are using a external rmmproc,
108 ** then we need to update the current folder in the
109 ** context so the external rmmproc will remove files
110 ** from the correct directory. This should be moved to
114 context_replace(pfolder, folder);
119 /* "remove" the SELECTED messages */
120 folder_delmsgs(mp, unlink_msgs, 0);
122 seq_save(mp); /* synchronize message sequences */
123 context_replace(pfolder, folder); /* update current folder */
124 context_save(); /* save the context file */
125 folder_free(mp); /* free folder structure */