X-Git-Url: http://git.marmaro.de/?p=mmh;a=blobdiff_plain;f=sbr%2Ffolder_delmsgs.c;h=3165883837153424441fb7f800eba8b486373c69;hp=4567f6d1912f2514df61dbdc79865e04280d213e;hb=5cb46b33551f28e4168989e752e09bd927e993f9;hpb=a259594cc41e41bfbb90562d3977b8194d1446f5 diff --git a/sbr/folder_delmsgs.c b/sbr/folder_delmsgs.c index 4567f6d..3165883 100644 --- a/sbr/folder_delmsgs.c +++ b/sbr/folder_delmsgs.c @@ -1,133 +1,60 @@ - /* - * folder_delmsgs.c -- "remove" SELECTED messages from a folder - * - * $Id$ - * - * This code is Copyright (c) 2002, by the authors of nmh. See the - * COPYRIGHT file in the root directory of the nmh distribution for - * complete copyright information. - */ - +** folder_delmsgs.c -- remove (= unlink) SELECTED messages from a folder +** +** This code is Copyright (c) 2002, by the authors of nmh. See the +** COPYRIGHT file in the root directory of the nmh distribution for +** complete copyright information. +*/ + +#include +#include #include /* - * 1) If we are using an external rmmproc, then exec it. - * 2) Else if unlink_msgs is non-zero, then unlink the - * SELECTED messages. - * 3) Else rename SELECTED messages by prefixing name - * with a standard prefix. - * - * If there is an error, return -1, else return 0. - */ - +** Unlink the SELECTED messages. +** +** If there is an error, return -1, else return 0. +*/ int -folder_delmsgs (struct msgs *mp, int unlink_msgs, int nohook) +folder_delmsgs(struct msgs *mp, int hook) { - pid_t pid; - int msgnum, vecp, retval = 0; - char buf[100], *dp, **vec; - char msgpath[BUFSIZ]; - - /* - * If "rmmproc" is defined, exec it to remove messages. - */ - if (rmmproc) { - /* Unset the EXISTS flag for each message to be removed */ - for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) { - if (is_selected (mp, msgnum)) - unset_exists (mp, msgnum); - } + int msgnum, retval = 0; + char msgpath[BUFSIZ]; - /* Mark that the sequence information has changed */ - mp->msgflags |= SEQMOD; - - if (mp->numsel > MAXARGS - 2) - adios (NULL, "more than %d messages for %s exec", MAXARGS - 2, - rmmproc); - vec = (char **) calloc ((size_t) (mp->numsel + 2), sizeof(*vec)); - if (vec == NULL) - adios (NULL, "unable to allocate exec vector"); - vecp = 1; for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) { - if (is_selected (mp, msgnum) && - !(vec[vecp++] = strdup (m_name (msgnum)))) - adios (NULL, "strdup failed"); - } - vec[vecp] = NULL; - - fflush (stdout); - vec[0] = r1bindex (rmmproc, '/'); - - switch (pid = vfork()) { - case -1: - advise ("fork", "unable to"); - return -1; - - case 0: - execvp (rmmproc, vec); - fprintf (stderr, "unable to exec "); - perror (rmmproc); - _exit (-1); - - default: - return (pidwait (pid, -1)); - } - } + if (!is_selected(mp, msgnum)) { + continue; + } - /* - * Either unlink or rename the SELECTED messages - */ - for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) { - if (is_selected (mp, msgnum)) { - /* unselect message */ - unset_selected (mp, msgnum); - mp->numsel--; + /* unselect message */ + unset_selected(mp, msgnum); - /* - * Run the external hook on the message if one was specified in the context. - * All we have is the message number; we have changed to the directory - * containing the message. So, we need to extract that directory to form - * the complete path. Note that the caller knows the directory, but has - * no way of passing that to us. - */ + snprintf(msgpath, sizeof (msgpath), "%s/%d", + mp->foldpath, msgnum); - if (!nohook) { - (void)snprintf(msgpath, sizeof (msgpath), "%s/%d", getcwd(msgpath, sizeof (msgpath)), msgnum); - (void)ext_hook("del-hook", msgpath, (char *)0); + if (hook) { + /* Run the external hook on the message. */ + ext_hook("del-hook", msgpath, NULL); } - dp = m_name (msgnum); - - if (unlink_msgs) { /* just unlink the messages */ - if (unlink (dp) == -1) { - admonish (dp, "unable to unlink"); - retval = -1; - continue; - } - } else { - /* or rename messages with standard prefix */ - strncpy (buf, m_backup (dp), sizeof(buf)); - if (rename (dp, buf) == -1) { - admonish (buf, "unable to rename %s to", dp); - retval = -1; - continue; + if (unlink(msgpath) == -1) { + admonish(msgpath, "unable to unlink"); + retval = -1; + continue; } - } - /* If removal was successful, decrement message count */ - unset_exists (mp, msgnum); - mp->nummsg--; + /* If removal was successful, decrement message count */ + unset_exists(mp, msgnum); + mp->nummsg--; } - } - /* Sanity check */ - if (mp->numsel != 0) - adios (NULL, "oops, mp->numsel should be 0"); + /* Sanity check */ + if (mp->numsel != 0) + adios(EX_SOFTWARE, NULL, "oops, mp->numsel should be 0"); - /* Mark that the sequence information has changed */ - mp->msgflags |= SEQMOD; + /* Mark that the sequence information has changed */ + mp->msgflags |= SEQMOD; - return retval; + return retval; }