]>
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.
10 #include "sbr/m_maildir.h"
12 #define RMM_SWITCHES \
13 X("unlink", 0, UNLINKSW) \
14 X("nounlink", 0, NUNLINKSW) \
15 X("rmmproc program", 0, RPROCSW) \
16 X("normmproc", 0, NRPRCSW) \
17 X("version", 0, VERSIONSW) \
18 X("help", 0, HELPSW) \
20 #define X(sw, minchars, id) id,
21 DEFINE_SWITCH_ENUM(RMM
);
24 #define X(sw, minchars, id) { sw, minchars, id },
25 DEFINE_SWITCH_ARRAY(RMM
, switches
);
30 main (int argc
, char **argv
)
32 int msgnum
, unlink_msgs
= 0;
33 char *cp
, *maildir
, *folder
= NULL
;
34 char buf
[BUFSIZ
], **argp
;
36 struct msgs_array msgs
= { 0, 0, NULL
};
39 if (nmh_init(argv
[0], 1)) { return 1; }
41 arguments
= getarguments (invo_name
, argc
, argv
, 1);
45 while ((cp
= *argp
++)) {
47 switch (smatch (++cp
, switches
)) {
49 ambigsw (cp
, switches
);
52 adios (NULL
, "-%s unknown\n", cp
);
55 snprintf (buf
, sizeof(buf
), "%s [+folder] [msgs] [switches]",
57 print_help (buf
, switches
, 1);
60 print_version(invo_name
);
71 if (!(rmmproc
= *argp
++) || *rmmproc
== '-')
72 adios (NULL
, "missing argument to %s", argp
[-2]);
79 if (*cp
== '+' || *cp
== '@') {
81 adios (NULL
, "only one folder at a time!");
82 folder
= pluspath (cp
);
84 app_msgarg(&msgs
, cp
);
87 if (!context_find ("path"))
88 free (path ("./", TFOLDER
));
90 app_msgarg(&msgs
, "cur");
92 folder
= getfolder (1);
93 maildir
= m_maildir (folder
);
95 if (chdir (maildir
) == NOTOK
)
96 adios (maildir
, "unable to change directory to");
98 /* read folder and create message structure */
99 if (!(mp
= folder_read (folder
, 1)))
100 adios (NULL
, "unable to read folder %s", folder
);
102 /* check for empty folder */
104 adios (NULL
, "no messages in %s", folder
);
106 /* parse all the message ranges/sequences and set SELECTED */
107 for (msgnum
= 0; msgnum
< msgs
.size
; msgnum
++)
108 if (!m_convert (mp
, msgs
.msgs
[msgnum
]))
110 seq_setprev (mp
); /* set the previous-sequence */
113 * As part of the new world locking order, folder_delmsgs() now updates
114 * the sequence and context for us. But since folder_delmsgs() doesn't
115 * have access to the folder name, change the context now.
118 context_replace (pfolder
, folder
);
120 /* "remove" the SELECTED messages */
121 folder_delmsgs (mp
, unlink_msgs
, 0);
123 folder_free (mp
); /* free folder structure */