]>
diplodocus.org Git - nmh/blob - uip/rmm.c
126ef3281e46a587efba5f27e11aced4617b3462
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/ambigsw.h"
11 #include "sbr/print_version.h"
12 #include "sbr/print_help.h"
13 #include "sbr/error.h"
16 #include "sbr/m_maildir.h"
18 #define RMM_SWITCHES \
19 X("unlink", 0, UNLINKSW) \
20 X("nounlink", 0, NUNLINKSW) \
21 X("rmmproc program", 0, RPROCSW) \
22 X("normmproc", 0, NRPRCSW) \
23 X("version", 0, VERSIONSW) \
24 X("help", 0, HELPSW) \
26 #define X(sw, minchars, id) id,
27 DEFINE_SWITCH_ENUM(RMM
);
30 #define X(sw, minchars, id) { sw, minchars, id },
31 DEFINE_SWITCH_ARRAY(RMM
, switches
);
36 main (int argc
, char **argv
)
39 bool unlink_msgs
= false;
40 char *cp
, *maildir
, *folder
= NULL
;
41 char buf
[BUFSIZ
], **argp
;
43 struct msgs_array msgs
= { 0, 0, NULL
};
46 if (nmh_init(argv
[0], true, true)) { return 1; }
48 arguments
= getarguments (invo_name
, argc
, argv
, 1);
52 while ((cp
= *argp
++)) {
54 switch (smatch (++cp
, switches
)) {
56 ambigsw (cp
, switches
);
59 die("-%s unknown\n", cp
);
62 snprintf (buf
, sizeof(buf
), "%s [+folder] [msgs] [switches]",
64 print_help (buf
, switches
, 1);
67 print_version(invo_name
);
78 if (!(rmmproc
= *argp
++) || *rmmproc
== '-')
79 die("missing argument to %s", argp
[-2]);
86 if (*cp
== '+' || *cp
== '@') {
88 die("only one folder at a time!");
89 folder
= pluspath (cp
);
91 app_msgarg(&msgs
, cp
);
94 if (!context_find ("path"))
95 free (path ("./", TFOLDER
));
97 app_msgarg(&msgs
, "cur");
99 folder
= getfolder (1);
100 maildir
= m_maildir (folder
);
102 if (chdir (maildir
) == NOTOK
)
103 adios (maildir
, "unable to change directory to");
105 /* read folder and create message structure */
106 if (!(mp
= folder_read (folder
, 1)))
107 die("unable to read folder %s", folder
);
109 /* check for empty folder */
111 die("no messages in %s", folder
);
113 /* parse all the message ranges/sequences and set SELECTED */
114 for (msgnum
= 0; msgnum
< msgs
.size
; msgnum
++)
115 if (!m_convert (mp
, msgs
.msgs
[msgnum
]))
117 seq_setprev (mp
); /* set the previous-sequence */
120 * As part of the new world locking order, folder_delmsgs() now updates
121 * the sequence and context for us. But since folder_delmsgs() doesn't
122 * have access to the folder name, change the context now.
125 context_replace (pfolder
, folder
);
127 /* "remove" the SELECTED messages */
128 folder_delmsgs (mp
, unlink_msgs
, 0);
130 folder_free (mp
); /* free folder structure */