]>
diplodocus.org Git - nmh/blob - uip/rmm.c
08214a09204cbd1ac0fddbb6ab112c3b14e2e659
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/folder_free.h"
10 #include "sbr/folder_delmsgs.h"
11 #include "sbr/context_replace.h"
12 #include "sbr/context_find.h"
13 #include "sbr/ambigsw.h"
15 #include "sbr/print_version.h"
16 #include "sbr/print_help.h"
17 #include "sbr/error.h"
20 #include "sbr/m_maildir.h"
22 #define RMM_SWITCHES \
23 X("unlink", 0, UNLINKSW) \
24 X("nounlink", 0, NUNLINKSW) \
25 X("rmmproc program", 0, RPROCSW) \
26 X("normmproc", 0, NRPRCSW) \
27 X("version", 0, VERSIONSW) \
28 X("help", 0, HELPSW) \
30 #define X(sw, minchars, id) id,
31 DEFINE_SWITCH_ENUM(RMM
);
34 #define X(sw, minchars, id) { sw, minchars, id },
35 DEFINE_SWITCH_ARRAY(RMM
, switches
);
40 main (int argc
, char **argv
)
43 bool unlink_msgs
= false;
44 char *cp
, *maildir
, *folder
= NULL
;
45 char buf
[BUFSIZ
], **argp
;
47 struct msgs_array msgs
= { 0, 0, NULL
};
50 if (nmh_init(argv
[0], true, true)) { return 1; }
52 arguments
= getarguments (invo_name
, argc
, argv
, 1);
56 while ((cp
= *argp
++)) {
58 switch (smatch (++cp
, switches
)) {
60 ambigsw (cp
, switches
);
63 die("-%s unknown\n", cp
);
66 snprintf (buf
, sizeof(buf
), "%s [+folder] [msgs] [switches]",
68 print_help (buf
, switches
, 1);
71 print_version(invo_name
);
82 if (!(rmmproc
= *argp
++) || *rmmproc
== '-')
83 die("missing argument to %s", argp
[-2]);
90 if (*cp
== '+' || *cp
== '@') {
92 die("only one folder at a time!");
93 folder
= pluspath (cp
);
95 app_msgarg(&msgs
, cp
);
98 if (!context_find ("path"))
99 free (path ("./", TFOLDER
));
101 app_msgarg(&msgs
, "cur");
103 folder
= getfolder (1);
104 maildir
= m_maildir (folder
);
106 if (chdir (maildir
) == NOTOK
)
107 adios (maildir
, "unable to change directory to");
109 /* read folder and create message structure */
110 if (!(mp
= folder_read (folder
, 1)))
111 die("unable to read folder %s", folder
);
113 /* check for empty folder */
115 die("no messages in %s", folder
);
117 /* parse all the message ranges/sequences and set SELECTED */
118 for (msgnum
= 0; msgnum
< msgs
.size
; msgnum
++)
119 if (!m_convert (mp
, msgs
.msgs
[msgnum
]))
121 seq_setprev (mp
); /* set the previous-sequence */
124 * As part of the new world locking order, folder_delmsgs() now updates
125 * the sequence and context for us. But since folder_delmsgs() doesn't
126 * have access to the folder name, change the context now.
129 context_replace (pfolder
, folder
);
131 /* "remove" the SELECTED messages */
132 folder_delmsgs (mp
, unlink_msgs
, 0);
134 folder_free (mp
); /* free folder structure */