]>
diplodocus.org Git - nmh/blob - uip/rmm.c
1 /* rmm.c -- remove a message(s)
3 * This code is Copyright (c) 2002, by the authors of nmh. See the
4 * COPYRIGHT file in the root directory of the nmh distribution for
5 * complete copyright information.
10 #include "sbr/print_version.h"
11 #include "sbr/print_help.h"
12 #include "sbr/error.h"
15 #include "sbr/m_maildir.h"
17 #define RMM_SWITCHES \
18 X("unlink", 0, UNLINKSW) \
19 X("nounlink", 0, NUNLINKSW) \
20 X("rmmproc program", 0, RPROCSW) \
21 X("normmproc", 0, NRPRCSW) \
22 X("version", 0, VERSIONSW) \
23 X("help", 0, HELPSW) \
25 #define X(sw, minchars, id) id,
26 DEFINE_SWITCH_ENUM(RMM
);
29 #define X(sw, minchars, id) { sw, minchars, id },
30 DEFINE_SWITCH_ARRAY(RMM
, switches
);
35 main (int argc
, char **argv
)
38 bool unlink_msgs
= false;
39 char *cp
, *maildir
, *folder
= NULL
;
40 char buf
[BUFSIZ
], **argp
;
42 struct msgs_array msgs
= { 0, 0, NULL
};
45 if (nmh_init(argv
[0], true, true)) { return 1; }
47 arguments
= getarguments (invo_name
, argc
, argv
, 1);
51 while ((cp
= *argp
++)) {
53 switch (smatch (++cp
, switches
)) {
55 ambigsw (cp
, switches
);
58 die("-%s unknown\n", cp
);
61 snprintf (buf
, sizeof(buf
), "%s [+folder] [msgs] [switches]",
63 print_help (buf
, switches
, 1);
66 print_version(invo_name
);
77 if (!(rmmproc
= *argp
++) || *rmmproc
== '-')
78 die("missing argument to %s", argp
[-2]);
85 if (*cp
== '+' || *cp
== '@') {
87 die("only one folder at a time!");
88 folder
= pluspath (cp
);
90 app_msgarg(&msgs
, cp
);
93 if (!context_find ("path"))
94 free (path ("./", TFOLDER
));
96 app_msgarg(&msgs
, "cur");
98 folder
= getfolder (1);
99 maildir
= m_maildir (folder
);
101 if (chdir (maildir
) == NOTOK
)
102 adios (maildir
, "unable to change directory to");
104 /* read folder and create message structure */
105 if (!(mp
= folder_read (folder
, 1)))
106 die("unable to read folder %s", folder
);
108 /* check for empty folder */
110 die("no messages in %s", folder
);
112 /* parse all the message ranges/sequences and set SELECTED */
113 for (msgnum
= 0; msgnum
< msgs
.size
; msgnum
++)
114 if (!m_convert (mp
, msgs
.msgs
[msgnum
]))
116 seq_setprev (mp
); /* set the previous-sequence */
119 * As part of the new world locking order, folder_delmsgs() now updates
120 * the sequence and context for us. But since folder_delmsgs() doesn't
121 * have access to the folder name, change the context now.
124 context_replace (pfolder
, folder
);
126 /* "remove" the SELECTED messages */
127 folder_delmsgs (mp
, unlink_msgs
, 0);
129 folder_free (mp
); /* free folder structure */