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