]>
diplodocus.org Git - nmh/blob - uip/rmm.c
2049e4ff8b5f6a1027d65399c9c218e4ab57e02d
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/m_convert.h"
10 #include "sbr/getfolder.h"
11 #include "sbr/folder_read.h"
12 #include "sbr/folder_free.h"
13 #include "sbr/folder_delmsgs.h"
14 #include "sbr/context_replace.h"
15 #include "sbr/context_find.h"
16 #include "sbr/ambigsw.h"
18 #include "sbr/print_version.h"
19 #include "sbr/print_help.h"
20 #include "sbr/error.h"
23 #include "sbr/m_maildir.h"
25 #define RMM_SWITCHES \
26 X("unlink", 0, UNLINKSW) \
27 X("nounlink", 0, NUNLINKSW) \
28 X("rmmproc program", 0, RPROCSW) \
29 X("normmproc", 0, NRPRCSW) \
30 X("version", 0, VERSIONSW) \
31 X("help", 0, HELPSW) \
33 #define X(sw, minchars, id) id,
34 DEFINE_SWITCH_ENUM(RMM
);
37 #define X(sw, minchars, id) { sw, minchars, id },
38 DEFINE_SWITCH_ARRAY(RMM
, switches
);
43 main (int argc
, char **argv
)
46 bool unlink_msgs
= false;
47 char *cp
, *maildir
, *folder
= NULL
;
48 char buf
[BUFSIZ
], **argp
;
50 struct msgs_array msgs
= { 0, 0, NULL
};
53 if (nmh_init(argv
[0], true, true)) { return 1; }
55 arguments
= getarguments (invo_name
, argc
, argv
, 1);
59 while ((cp
= *argp
++)) {
61 switch (smatch (++cp
, switches
)) {
63 ambigsw (cp
, switches
);
66 die("-%s unknown\n", cp
);
69 snprintf (buf
, sizeof(buf
), "%s [+folder] [msgs] [switches]",
71 print_help (buf
, switches
, 1);
74 print_version(invo_name
);
85 if (!(rmmproc
= *argp
++) || *rmmproc
== '-')
86 die("missing argument to %s", argp
[-2]);
93 if (*cp
== '+' || *cp
== '@') {
95 die("only one folder at a time!");
96 folder
= pluspath (cp
);
98 app_msgarg(&msgs
, cp
);
101 if (!context_find ("path"))
102 free (path ("./", TFOLDER
));
104 app_msgarg(&msgs
, "cur");
106 folder
= getfolder (1);
107 maildir
= m_maildir (folder
);
109 if (chdir (maildir
) == NOTOK
)
110 adios (maildir
, "unable to change directory to");
112 /* read folder and create message structure */
113 if (!(mp
= folder_read (folder
, 1)))
114 die("unable to read folder %s", folder
);
116 /* check for empty folder */
118 die("no messages in %s", folder
);
120 /* parse all the message ranges/sequences and set SELECTED */
121 for (msgnum
= 0; msgnum
< msgs
.size
; msgnum
++)
122 if (!m_convert (mp
, msgs
.msgs
[msgnum
]))
124 seq_setprev (mp
); /* set the previous-sequence */
127 * As part of the new world locking order, folder_delmsgs() now updates
128 * the sequence and context for us. But since folder_delmsgs() doesn't
129 * have access to the folder name, change the context now.
132 context_replace (pfolder
, folder
);
134 /* "remove" the SELECTED messages */
135 folder_delmsgs (mp
, unlink_msgs
, 0);
137 folder_free (mp
); /* free folder structure */