]>
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.
9 #include "sbr/seq_setprev.h"
10 #include "sbr/smatch.h"
11 #include "sbr/m_convert.h"
12 #include "sbr/getfolder.h"
13 #include "sbr/folder_read.h"
14 #include "sbr/folder_free.h"
15 #include "sbr/folder_delmsgs.h"
16 #include "sbr/context_replace.h"
17 #include "sbr/context_find.h"
18 #include "sbr/ambigsw.h"
20 #include "sbr/print_version.h"
21 #include "sbr/print_help.h"
22 #include "sbr/error.h"
25 #include "sbr/m_maildir.h"
27 #define RMM_SWITCHES \
28 X("unlink", 0, UNLINKSW) \
29 X("nounlink", 0, NUNLINKSW) \
30 X("rmmproc program", 0, RPROCSW) \
31 X("normmproc", 0, NRPRCSW) \
32 X("version", 0, VERSIONSW) \
33 X("help", 0, HELPSW) \
35 #define X(sw, minchars, id) id,
36 DEFINE_SWITCH_ENUM(RMM
);
39 #define X(sw, minchars, id) { sw, minchars, id },
40 DEFINE_SWITCH_ARRAY(RMM
, switches
);
45 main (int argc
, char **argv
)
48 bool unlink_msgs
= false;
49 char *cp
, *maildir
, *folder
= NULL
;
50 char buf
[BUFSIZ
], **argp
;
52 struct msgs_array msgs
= { 0, 0, NULL
};
55 if (nmh_init(argv
[0], true, true)) { return 1; }
57 arguments
= getarguments (invo_name
, argc
, argv
, 1);
61 while ((cp
= *argp
++)) {
63 switch (smatch (++cp
, switches
)) {
65 ambigsw (cp
, switches
);
68 die("-%s unknown\n", cp
);
71 snprintf (buf
, sizeof(buf
), "%s [+folder] [msgs] [switches]",
73 print_help (buf
, switches
, 1);
76 print_version(invo_name
);
87 if (!(rmmproc
= *argp
++) || *rmmproc
== '-')
88 die("missing argument to %s", argp
[-2]);
95 if (*cp
== '+' || *cp
== '@') {
97 die("only one folder at a time!");
98 folder
= pluspath (cp
);
100 app_msgarg(&msgs
, cp
);
103 if (!context_find ("path"))
104 free (path ("./", TFOLDER
));
106 app_msgarg(&msgs
, "cur");
108 folder
= getfolder (1);
109 maildir
= m_maildir (folder
);
111 if (chdir (maildir
) == NOTOK
)
112 adios (maildir
, "unable to change directory to");
114 /* read folder and create message structure */
115 if (!(mp
= folder_read (folder
, 1)))
116 die("unable to read folder %s", folder
);
118 /* check for empty folder */
120 die("no messages in %s", folder
);
122 /* parse all the message ranges/sequences and set SELECTED */
123 for (msgnum
= 0; msgnum
< msgs
.size
; msgnum
++)
124 if (!m_convert (mp
, msgs
.msgs
[msgnum
]))
126 seq_setprev (mp
); /* set the previous-sequence */
129 * As part of the new world locking order, folder_delmsgs() now updates
130 * the sequence and context for us. But since folder_delmsgs() doesn't
131 * have access to the folder name, change the context now.
134 context_replace (pfolder
, folder
);
136 /* "remove" the SELECTED messages */
137 folder_delmsgs (mp
, unlink_msgs
, 0);
139 folder_free (mp
); /* free folder structure */