]>
diplodocus.org Git - nmh/blob - uip/rmm.c
766fd722d13afbea9a78ee972823951db1ef8ae0
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_version.h"
10 #include "sbr/print_help.h"
11 #include "sbr/error.h"
14 #include "sbr/m_maildir.h"
16 #define RMM_SWITCHES \
17 X("unlink", 0, UNLINKSW) \
18 X("nounlink", 0, NUNLINKSW) \
19 X("rmmproc program", 0, RPROCSW) \
20 X("normmproc", 0, NRPRCSW) \
21 X("version", 0, VERSIONSW) \
22 X("help", 0, HELPSW) \
24 #define X(sw, minchars, id) id,
25 DEFINE_SWITCH_ENUM(RMM
);
28 #define X(sw, minchars, id) { sw, minchars, id },
29 DEFINE_SWITCH_ARRAY(RMM
, switches
);
34 main (int argc
, char **argv
)
37 bool unlink_msgs
= false;
38 char *cp
, *maildir
, *folder
= NULL
;
39 char buf
[BUFSIZ
], **argp
;
41 struct msgs_array msgs
= { 0, 0, NULL
};
44 if (nmh_init(argv
[0], true, true)) { return 1; }
46 arguments
= getarguments (invo_name
, argc
, argv
, 1);
50 while ((cp
= *argp
++)) {
52 switch (smatch (++cp
, switches
)) {
54 ambigsw (cp
, switches
);
57 die("-%s unknown\n", cp
);
60 snprintf (buf
, sizeof(buf
), "%s [+folder] [msgs] [switches]",
62 print_help (buf
, switches
, 1);
65 print_version(invo_name
);
76 if (!(rmmproc
= *argp
++) || *rmmproc
== '-')
77 die("missing argument to %s", argp
[-2]);
84 if (*cp
== '+' || *cp
== '@') {
86 die("only one folder at a time!");
87 folder
= pluspath (cp
);
89 app_msgarg(&msgs
, cp
);
92 if (!context_find ("path"))
93 free (path ("./", TFOLDER
));
95 app_msgarg(&msgs
, "cur");
97 folder
= getfolder (1);
98 maildir
= m_maildir (folder
);
100 if (chdir (maildir
) == NOTOK
)
101 adios (maildir
, "unable to change directory to");
103 /* read folder and create message structure */
104 if (!(mp
= folder_read (folder
, 1)))
105 die("unable to read folder %s", folder
);
107 /* check for empty folder */
109 die("no messages in %s", folder
);
111 /* parse all the message ranges/sequences and set SELECTED */
112 for (msgnum
= 0; msgnum
< msgs
.size
; msgnum
++)
113 if (!m_convert (mp
, msgs
.msgs
[msgnum
]))
115 seq_setprev (mp
); /* set the previous-sequence */
118 * As part of the new world locking order, folder_delmsgs() now updates
119 * the sequence and context for us. But since folder_delmsgs() doesn't
120 * have access to the folder name, change the context now.
123 context_replace (pfolder
, folder
);
125 /* "remove" the SELECTED messages */
126 folder_delmsgs (mp
, unlink_msgs
, 0);
128 folder_free (mp
); /* free folder structure */