]>
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/getarguments.h"
10 #include "sbr/seq_setprev.h"
11 #include "sbr/smatch.h"
12 #include "sbr/m_convert.h"
13 #include "sbr/getfolder.h"
14 #include "sbr/folder_read.h"
15 #include "sbr/folder_free.h"
16 #include "sbr/folder_delmsgs.h"
17 #include "sbr/context_replace.h"
18 #include "sbr/context_find.h"
19 #include "sbr/ambigsw.h"
21 #include "sbr/print_version.h"
22 #include "sbr/print_help.h"
23 #include "sbr/error.h"
26 #include "sbr/m_maildir.h"
28 #define RMM_SWITCHES \
29 X("unlink", 0, UNLINKSW) \
30 X("nounlink", 0, NUNLINKSW) \
31 X("rmmproc program", 0, RPROCSW) \
32 X("normmproc", 0, NRPRCSW) \
33 X("version", 0, VERSIONSW) \
34 X("help", 0, HELPSW) \
36 #define X(sw, minchars, id) id,
37 DEFINE_SWITCH_ENUM(RMM
);
40 #define X(sw, minchars, id) { sw, minchars, id },
41 DEFINE_SWITCH_ARRAY(RMM
, switches
);
46 main (int argc
, char **argv
)
49 bool unlink_msgs
= false;
50 char *cp
, *maildir
, *folder
= NULL
;
51 char buf
[BUFSIZ
], **argp
;
53 struct msgs_array msgs
= { 0, 0, NULL
};
56 if (nmh_init(argv
[0], true, true)) { return 1; }
58 arguments
= getarguments (invo_name
, argc
, argv
, 1);
62 while ((cp
= *argp
++)) {
64 switch (smatch (++cp
, switches
)) {
66 ambigsw (cp
, switches
);
69 die("-%s unknown\n", cp
);
72 snprintf (buf
, sizeof(buf
), "%s [+folder] [msgs] [switches]",
74 print_help (buf
, switches
, 1);
77 print_version(invo_name
);
88 if (!(rmmproc
= *argp
++) || *rmmproc
== '-')
89 die("missing argument to %s", argp
[-2]);
96 if (*cp
== '+' || *cp
== '@') {
98 die("only one folder at a time!");
99 folder
= pluspath (cp
);
101 app_msgarg(&msgs
, cp
);
104 if (!context_find ("path"))
105 free (path ("./", TFOLDER
));
107 app_msgarg(&msgs
, "cur");
109 folder
= getfolder (1);
110 maildir
= m_maildir (folder
);
112 if (chdir (maildir
) == NOTOK
)
113 adios (maildir
, "unable to change directory to");
115 /* read folder and create message structure */
116 if (!(mp
= folder_read (folder
, 1)))
117 die("unable to read folder %s", folder
);
119 /* check for empty folder */
121 die("no messages in %s", folder
);
123 /* parse all the message ranges/sequences and set SELECTED */
124 for (msgnum
= 0; msgnum
< msgs
.size
; msgnum
++)
125 if (!m_convert (mp
, msgs
.msgs
[msgnum
]))
127 seq_setprev (mp
); /* set the previous-sequence */
130 * As part of the new world locking order, folder_delmsgs() now updates
131 * the sequence and context for us. But since folder_delmsgs() doesn't
132 * have access to the folder name, change the context now.
135 context_replace (pfolder
, folder
);
137 /* "remove" the SELECTED messages */
138 folder_delmsgs (mp
, unlink_msgs
, 0);
140 folder_free (mp
); /* free folder structure */