]>
diplodocus.org Git - nmh/blob - uip/rmm.c
9f1d60e1aac3de6480a07cce4e386fec02cd63e1
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.
12 #include "sbr/m_maildir.h"
14 #define RMM_SWITCHES \
15 X("unlink", 0, UNLINKSW) \
16 X("nounlink", 0, NUNLINKSW) \
17 X("rmmproc program", 0, RPROCSW) \
18 X("normmproc", 0, NRPRCSW) \
19 X("version", 0, VERSIONSW) \
20 X("help", 0, HELPSW) \
22 #define X(sw, minchars, id) id,
23 DEFINE_SWITCH_ENUM(RMM
);
26 #define X(sw, minchars, id) { sw, minchars, id },
27 DEFINE_SWITCH_ARRAY(RMM
, switches
);
32 main (int argc
, char **argv
)
35 bool unlink_msgs
= false;
36 char *cp
, *maildir
, *folder
= NULL
;
37 char buf
[BUFSIZ
], **argp
;
39 struct msgs_array msgs
= { 0, 0, NULL
};
42 if (nmh_init(argv
[0], true, true)) { return 1; }
44 arguments
= getarguments (invo_name
, argc
, argv
, 1);
48 while ((cp
= *argp
++)) {
50 switch (smatch (++cp
, switches
)) {
52 ambigsw (cp
, switches
);
55 die("-%s unknown\n", cp
);
58 snprintf (buf
, sizeof(buf
), "%s [+folder] [msgs] [switches]",
60 print_help (buf
, switches
, 1);
63 print_version(invo_name
);
74 if (!(rmmproc
= *argp
++) || *rmmproc
== '-')
75 die("missing argument to %s", argp
[-2]);
82 if (*cp
== '+' || *cp
== '@') {
84 die("only one folder at a time!");
85 folder
= pluspath (cp
);
87 app_msgarg(&msgs
, cp
);
90 if (!context_find ("path"))
91 free (path ("./", TFOLDER
));
93 app_msgarg(&msgs
, "cur");
95 folder
= getfolder (1);
96 maildir
= m_maildir (folder
);
98 if (chdir (maildir
) == NOTOK
)
99 adios (maildir
, "unable to change directory to");
101 /* read folder and create message structure */
102 if (!(mp
= folder_read (folder
, 1)))
103 die("unable to read folder %s", folder
);
105 /* check for empty folder */
107 die("no messages in %s", folder
);
109 /* parse all the message ranges/sequences and set SELECTED */
110 for (msgnum
= 0; msgnum
< msgs
.size
; msgnum
++)
111 if (!m_convert (mp
, msgs
.msgs
[msgnum
]))
113 seq_setprev (mp
); /* set the previous-sequence */
116 * As part of the new world locking order, folder_delmsgs() now updates
117 * the sequence and context for us. But since folder_delmsgs() doesn't
118 * have access to the folder name, change the context now.
121 context_replace (pfolder
, folder
);
123 /* "remove" the SELECTED messages */
124 folder_delmsgs (mp
, unlink_msgs
, 0);
126 folder_free (mp
); /* free folder structure */