mhl and mhbuild ignore to long lines
[mmh] / sbr / folder_delmsgs.c
1 /*
2 ** folder_delmsgs.c -- remove (= unlink) SELECTED messages from a folder
3 **
4 ** This code is Copyright (c) 2002, by the authors of nmh.  See the
5 ** COPYRIGHT file in the root directory of the nmh distribution for
6 ** complete copyright information.
7 */
8
9 #include <sysexits.h>
10 #include <unistd.h>
11 #include <h/mh.h>
12
13 /*
14 ** Unlink the SELECTED messages.
15 **
16 ** If there is an error, return -1, else return 0.
17 */
18 int
19 folder_delmsgs(struct msgs *mp, int hook)
20 {
21         int msgnum, retval = 0;
22         char msgpath[BUFSIZ];
23
24         for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) {
25                 if (!is_selected(mp, msgnum)) {
26                         continue;
27                 }
28
29                 /* unselect message */
30                 unset_selected(mp, msgnum);
31
32                 snprintf(msgpath, sizeof (msgpath), "%s/%d",
33                                 mp->foldpath, msgnum);
34
35                 if (hook) {
36                         /* Run the external hook on the message. */
37                         ext_hook("del-hook", msgpath, NULL);
38                 }
39
40                 /* just unlink the messages */
41                 if (unlink(msgpath) == -1) {
42                         admonish(msgpath, "unable to unlink");
43                         retval = -1;
44                         continue;
45                 }
46
47                 /* If removal was successful, decrement message count */
48                 clear_msg_flags(mp, msgnum);
49                 mp->nummsg--;
50         }
51
52         /* Sanity check */
53         if (mp->numsel != 0)
54                 adios(EX_SOFTWARE, NULL, "oops, mp->numsel should be 0");
55
56         /* Mark that the sequence information has changed */
57         mp->msgflags |= SEQMOD;
58
59         return retval;
60 }