]>
diplodocus.org Git - nmh/blob - sbr/folder_delmsgs.c
3 * folder_delmsgs.c -- "remove" SELECTED messages from a folder
11 * 1) If we are using an external rmmproc, then exec it.
12 * 2) Else if unlink_msgs is non-zero, then unlink the
14 * 3) Else rename SELECTED messages by prefixing name
15 * with a standard prefix.
17 * If there is an error, return -1, else return 0.
21 folder_delmsgs (struct msgs
*mp
, int unlink_msgs
)
24 int msgnum
, vecp
, retval
= 0;
25 char buf
[100], *dp
, **vec
;
28 * If "rmmproc" is defined, exec it to remove messages.
31 /* Unset the EXISTS flag for each message to be removed */
32 for (msgnum
= mp
->lowsel
; msgnum
<= mp
->hghsel
; msgnum
++) {
33 if (is_selected (mp
, msgnum
))
34 unset_exists (mp
, msgnum
);
37 /* Mark that the sequence information has changed */
38 mp
->msgflags
|= SEQMOD
;
40 if (mp
->numsel
> MAXARGS
- 2)
41 adios (NULL
, "more than %d messages for %s exec", MAXARGS
- 2,
43 vec
= (char **) calloc ((size_t) (mp
->numsel
+ 2), sizeof(*vec
));
45 adios (NULL
, "unable to allocate exec vector");
47 for (msgnum
= mp
->lowsel
; msgnum
<= mp
->hghsel
; msgnum
++) {
48 if (is_selected (mp
, msgnum
) &&
49 !(vec
[vecp
++] = strdup (m_name (msgnum
))))
50 adios (NULL
, "strdup failed");
55 vec
[0] = r1bindex (rmmproc
, '/');
57 switch (pid
= vfork()) {
59 advise ("fork", "unable to");
63 execvp (rmmproc
, vec
);
64 fprintf (stderr
, "unable to exec ");
69 return (pidwait (pid
, -1));
74 * Either unlink or rename the SELECTED messages
76 for (msgnum
= mp
->lowsel
; msgnum
<= mp
->hghsel
; msgnum
++) {
77 if (is_selected (mp
, msgnum
)) {
78 /* unselect message */
79 unset_selected (mp
, msgnum
);
85 /* just unlink the messages */
86 if (unlink (dp
) == -1) {
87 admonish (dp
, "unable to unlink");
92 /* or rename messages with standard prefix */
93 strncpy (buf
, m_backup (dp
), sizeof(buf
));
94 if (rename (dp
, buf
) == -1) {
95 admonish (buf
, "unable to rename %s to", dp
);
101 /* If removal was successful, decrement message count */
102 unset_exists (mp
, msgnum
);
109 adios (NULL
, "oops, mp->numsel should be 0");
111 /* Mark that the sequence information has changed */
112 mp
->msgflags
|= SEQMOD
;