]>
diplodocus.org Git - nmh/blob - uip/rmm.c
f238daee1efcf99636c9e441d755c96134965c74
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_delmsgs.h"
10 #include "sbr/context_replace.h"
11 #include "sbr/context_find.h"
12 #include "sbr/ambigsw.h"
14 #include "sbr/print_version.h"
15 #include "sbr/print_help.h"
16 #include "sbr/error.h"
19 #include "sbr/m_maildir.h"
21 #define RMM_SWITCHES \
22 X("unlink", 0, UNLINKSW) \
23 X("nounlink", 0, NUNLINKSW) \
24 X("rmmproc program", 0, RPROCSW) \
25 X("normmproc", 0, NRPRCSW) \
26 X("version", 0, VERSIONSW) \
27 X("help", 0, HELPSW) \
29 #define X(sw, minchars, id) id,
30 DEFINE_SWITCH_ENUM(RMM
);
33 #define X(sw, minchars, id) { sw, minchars, id },
34 DEFINE_SWITCH_ARRAY(RMM
, switches
);
39 main (int argc
, char **argv
)
42 bool unlink_msgs
= false;
43 char *cp
, *maildir
, *folder
= NULL
;
44 char buf
[BUFSIZ
], **argp
;
46 struct msgs_array msgs
= { 0, 0, NULL
};
49 if (nmh_init(argv
[0], true, true)) { return 1; }
51 arguments
= getarguments (invo_name
, argc
, argv
, 1);
55 while ((cp
= *argp
++)) {
57 switch (smatch (++cp
, switches
)) {
59 ambigsw (cp
, switches
);
62 die("-%s unknown\n", cp
);
65 snprintf (buf
, sizeof(buf
), "%s [+folder] [msgs] [switches]",
67 print_help (buf
, switches
, 1);
70 print_version(invo_name
);
81 if (!(rmmproc
= *argp
++) || *rmmproc
== '-')
82 die("missing argument to %s", argp
[-2]);
89 if (*cp
== '+' || *cp
== '@') {
91 die("only one folder at a time!");
92 folder
= pluspath (cp
);
94 app_msgarg(&msgs
, cp
);
97 if (!context_find ("path"))
98 free (path ("./", TFOLDER
));
100 app_msgarg(&msgs
, "cur");
102 folder
= getfolder (1);
103 maildir
= m_maildir (folder
);
105 if (chdir (maildir
) == NOTOK
)
106 adios (maildir
, "unable to change directory to");
108 /* read folder and create message structure */
109 if (!(mp
= folder_read (folder
, 1)))
110 die("unable to read folder %s", folder
);
112 /* check for empty folder */
114 die("no messages in %s", folder
);
116 /* parse all the message ranges/sequences and set SELECTED */
117 for (msgnum
= 0; msgnum
< msgs
.size
; msgnum
++)
118 if (!m_convert (mp
, msgs
.msgs
[msgnum
]))
120 seq_setprev (mp
); /* set the previous-sequence */
123 * As part of the new world locking order, folder_delmsgs() now updates
124 * the sequence and context for us. But since folder_delmsgs() doesn't
125 * have access to the folder name, change the context now.
128 context_replace (pfolder
, folder
);
130 /* "remove" the SELECTED messages */
131 folder_delmsgs (mp
, unlink_msgs
, 0);
133 folder_free (mp
); /* free folder structure */