]>
diplodocus.org Git - nmh/blob - uip/rmm.c
eb6fbf17082bc8dca29ded78298e0a0879997270
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/getfolder.h"
10 #include "sbr/folder_read.h"
11 #include "sbr/folder_free.h"
12 #include "sbr/folder_delmsgs.h"
13 #include "sbr/context_replace.h"
14 #include "sbr/context_find.h"
15 #include "sbr/ambigsw.h"
17 #include "sbr/print_version.h"
18 #include "sbr/print_help.h"
19 #include "sbr/error.h"
22 #include "sbr/m_maildir.h"
24 #define RMM_SWITCHES \
25 X("unlink", 0, UNLINKSW) \
26 X("nounlink", 0, NUNLINKSW) \
27 X("rmmproc program", 0, RPROCSW) \
28 X("normmproc", 0, NRPRCSW) \
29 X("version", 0, VERSIONSW) \
30 X("help", 0, HELPSW) \
32 #define X(sw, minchars, id) id,
33 DEFINE_SWITCH_ENUM(RMM
);
36 #define X(sw, minchars, id) { sw, minchars, id },
37 DEFINE_SWITCH_ARRAY(RMM
, switches
);
42 main (int argc
, char **argv
)
45 bool unlink_msgs
= false;
46 char *cp
, *maildir
, *folder
= NULL
;
47 char buf
[BUFSIZ
], **argp
;
49 struct msgs_array msgs
= { 0, 0, NULL
};
52 if (nmh_init(argv
[0], true, true)) { return 1; }
54 arguments
= getarguments (invo_name
, argc
, argv
, 1);
58 while ((cp
= *argp
++)) {
60 switch (smatch (++cp
, switches
)) {
62 ambigsw (cp
, switches
);
65 die("-%s unknown\n", cp
);
68 snprintf (buf
, sizeof(buf
), "%s [+folder] [msgs] [switches]",
70 print_help (buf
, switches
, 1);
73 print_version(invo_name
);
84 if (!(rmmproc
= *argp
++) || *rmmproc
== '-')
85 die("missing argument to %s", argp
[-2]);
92 if (*cp
== '+' || *cp
== '@') {
94 die("only one folder at a time!");
95 folder
= pluspath (cp
);
97 app_msgarg(&msgs
, cp
);
100 if (!context_find ("path"))
101 free (path ("./", TFOLDER
));
103 app_msgarg(&msgs
, "cur");
105 folder
= getfolder (1);
106 maildir
= m_maildir (folder
);
108 if (chdir (maildir
) == NOTOK
)
109 adios (maildir
, "unable to change directory to");
111 /* read folder and create message structure */
112 if (!(mp
= folder_read (folder
, 1)))
113 die("unable to read folder %s", folder
);
115 /* check for empty folder */
117 die("no messages in %s", folder
);
119 /* parse all the message ranges/sequences and set SELECTED */
120 for (msgnum
= 0; msgnum
< msgs
.size
; msgnum
++)
121 if (!m_convert (mp
, msgs
.msgs
[msgnum
]))
123 seq_setprev (mp
); /* set the previous-sequence */
126 * As part of the new world locking order, folder_delmsgs() now updates
127 * the sequence and context for us. But since folder_delmsgs() doesn't
128 * have access to the folder name, change the context now.
131 context_replace (pfolder
, folder
);
133 /* "remove" the SELECTED messages */
134 folder_delmsgs (mp
, unlink_msgs
, 0);
136 folder_free (mp
); /* free folder structure */