]>
diplodocus.org Git - nmh/blob - uip/rmm.c
6f52a08ba0e8d5da71a55d3a28ae6ff51bdd9e00
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/print_help.h"
10 #include "sbr/error.h"
13 #include "sbr/m_maildir.h"
15 #define RMM_SWITCHES \
16 X("unlink", 0, UNLINKSW) \
17 X("nounlink", 0, NUNLINKSW) \
18 X("rmmproc program", 0, RPROCSW) \
19 X("normmproc", 0, NRPRCSW) \
20 X("version", 0, VERSIONSW) \
21 X("help", 0, HELPSW) \
23 #define X(sw, minchars, id) id,
24 DEFINE_SWITCH_ENUM(RMM
);
27 #define X(sw, minchars, id) { sw, minchars, id },
28 DEFINE_SWITCH_ARRAY(RMM
, switches
);
33 main (int argc
, char **argv
)
36 bool unlink_msgs
= false;
37 char *cp
, *maildir
, *folder
= NULL
;
38 char buf
[BUFSIZ
], **argp
;
40 struct msgs_array msgs
= { 0, 0, NULL
};
43 if (nmh_init(argv
[0], true, true)) { return 1; }
45 arguments
= getarguments (invo_name
, argc
, argv
, 1);
49 while ((cp
= *argp
++)) {
51 switch (smatch (++cp
, switches
)) {
53 ambigsw (cp
, switches
);
56 die("-%s unknown\n", cp
);
59 snprintf (buf
, sizeof(buf
), "%s [+folder] [msgs] [switches]",
61 print_help (buf
, switches
, 1);
64 print_version(invo_name
);
75 if (!(rmmproc
= *argp
++) || *rmmproc
== '-')
76 die("missing argument to %s", argp
[-2]);
83 if (*cp
== '+' || *cp
== '@') {
85 die("only one folder at a time!");
86 folder
= pluspath (cp
);
88 app_msgarg(&msgs
, cp
);
91 if (!context_find ("path"))
92 free (path ("./", TFOLDER
));
94 app_msgarg(&msgs
, "cur");
96 folder
= getfolder (1);
97 maildir
= m_maildir (folder
);
99 if (chdir (maildir
) == NOTOK
)
100 adios (maildir
, "unable to change directory to");
102 /* read folder and create message structure */
103 if (!(mp
= folder_read (folder
, 1)))
104 die("unable to read folder %s", folder
);
106 /* check for empty folder */
108 die("no messages in %s", folder
);
110 /* parse all the message ranges/sequences and set SELECTED */
111 for (msgnum
= 0; msgnum
< msgs
.size
; msgnum
++)
112 if (!m_convert (mp
, msgs
.msgs
[msgnum
]))
114 seq_setprev (mp
); /* set the previous-sequence */
117 * As part of the new world locking order, folder_delmsgs() now updates
118 * the sequence and context for us. But since folder_delmsgs() doesn't
119 * have access to the folder name, change the context now.
122 context_replace (pfolder
, folder
);
124 /* "remove" the SELECTED messages */
125 folder_delmsgs (mp
, unlink_msgs
, 0);
127 folder_free (mp
); /* free folder structure */