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 = r1bindex (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]",
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 = pluspath (cp);
79 app_msgarg(&msgs, cp);
82 if (!context_find ("path"))
83 free (path ("./", TFOLDER));
85 app_msgarg(&msgs, "cur");
87 folder = getfolder (1);
88 maildir = m_maildir (folder);
90 if (chdir (maildir) == NOTOK)
91 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);
97 /* check for empty folder */
99 adios (NULL, "no messages in %s", folder);
101 /* parse all the message ranges/sequences and set SELECTED */
102 for (msgnum = 0; msgnum < msgs.size; msgnum++)
103 if (!m_convert (mp, msgs.msgs[msgnum]))
105 seq_setprev (mp); /* set the previous-sequence */
108 * This is hackish. If we are using a external rmmproc,
109 * then we need to update the current folder in the
110 * context so the external rmmproc will remove files
111 * from the correct directory. This should be moved to
115 context_replace (pfolder, folder);
120 /* "remove" the SELECTED messages */
121 folder_delmsgs (mp, unlink_msgs, 0);
123 seq_save (mp); /* synchronize message sequences */
124 context_replace (pfolder, folder); /* update current folder */
125 context_save (); /* save the context file */
126 folder_free (mp); /* free folder structure */