]>
diplodocus.org Git - nmh/blob - uip/rmm.c
9dab87febcf4bd41ae04b3de2945f65f6e323c1d
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/smatch.h"
10 #include "sbr/m_convert.h"
11 #include "sbr/getfolder.h"
12 #include "sbr/folder_read.h"
13 #include "sbr/folder_free.h"
14 #include "sbr/folder_delmsgs.h"
15 #include "sbr/context_replace.h"
16 #include "sbr/context_find.h"
17 #include "sbr/ambigsw.h"
19 #include "sbr/print_version.h"
20 #include "sbr/print_help.h"
21 #include "sbr/error.h"
24 #include "sbr/m_maildir.h"
26 #define RMM_SWITCHES \
27 X("unlink", 0, UNLINKSW) \
28 X("nounlink", 0, NUNLINKSW) \
29 X("rmmproc program", 0, RPROCSW) \
30 X("normmproc", 0, NRPRCSW) \
31 X("version", 0, VERSIONSW) \
32 X("help", 0, HELPSW) \
34 #define X(sw, minchars, id) id,
35 DEFINE_SWITCH_ENUM(RMM
);
38 #define X(sw, minchars, id) { sw, minchars, id },
39 DEFINE_SWITCH_ARRAY(RMM
, switches
);
44 main (int argc
, char **argv
)
47 bool unlink_msgs
= false;
48 char *cp
, *maildir
, *folder
= NULL
;
49 char buf
[BUFSIZ
], **argp
;
51 struct msgs_array msgs
= { 0, 0, NULL
};
54 if (nmh_init(argv
[0], true, true)) { return 1; }
56 arguments
= getarguments (invo_name
, argc
, argv
, 1);
60 while ((cp
= *argp
++)) {
62 switch (smatch (++cp
, switches
)) {
64 ambigsw (cp
, switches
);
67 die("-%s unknown\n", cp
);
70 snprintf (buf
, sizeof(buf
), "%s [+folder] [msgs] [switches]",
72 print_help (buf
, switches
, 1);
75 print_version(invo_name
);
86 if (!(rmmproc
= *argp
++) || *rmmproc
== '-')
87 die("missing argument to %s", argp
[-2]);
94 if (*cp
== '+' || *cp
== '@') {
96 die("only one folder at a time!");
97 folder
= pluspath (cp
);
99 app_msgarg(&msgs
, cp
);
102 if (!context_find ("path"))
103 free (path ("./", TFOLDER
));
105 app_msgarg(&msgs
, "cur");
107 folder
= getfolder (1);
108 maildir
= m_maildir (folder
);
110 if (chdir (maildir
) == NOTOK
)
111 adios (maildir
, "unable to change directory to");
113 /* read folder and create message structure */
114 if (!(mp
= folder_read (folder
, 1)))
115 die("unable to read folder %s", folder
);
117 /* check for empty folder */
119 die("no messages in %s", folder
);
121 /* parse all the message ranges/sequences and set SELECTED */
122 for (msgnum
= 0; msgnum
< msgs
.size
; msgnum
++)
123 if (!m_convert (mp
, msgs
.msgs
[msgnum
]))
125 seq_setprev (mp
); /* set the previous-sequence */
128 * As part of the new world locking order, folder_delmsgs() now updates
129 * the sequence and context for us. But since folder_delmsgs() doesn't
130 * have access to the folder name, change the context now.
133 context_replace (pfolder
, folder
);
135 /* "remove" the SELECTED messages */
136 folder_delmsgs (mp
, unlink_msgs
, 0);
138 folder_free (mp
); /* free folder structure */