1 /* rmm.c - remove a message */
3 static char ident[] = "@(#)$Id: rmm.c,v 1.5 1992/12/15 00:20:22 jromine Exp $";
14 static struct swit switches[] = {
45 setlocale(LC_ALL, "");
47 invo_name = r1bindex (argv[0], '/');
48 if ((cp = m_find (invo_name)) != NULL) {
49 ap = brkstring (cp = getcpy (cp), " ", "\n");
50 ap = copyip (ap, arguments);
54 (void) copyip (argv + 1, ap);
59 while (cp = *argp++) {
61 switch (smatch (++cp, switches)) {
63 ambigsw (cp, switches);
66 adios (NULLCP, "-%s unknown\n", cp);
68 (void) sprintf (buf, "%s [+folder] [msgs] [switches]",
73 if (*cp == '+' || *cp == '@') {
75 adios (NULLCP, "only one folder at a time!");
77 folder = path (cp + 1, *cp == '+' ? TFOLDER : TSUBCWF);
86 free (path ("./", TFOLDER));
90 folder = m_getfolder ();
91 maildir = m_maildir (folder);
93 if (chdir (maildir) == NOTOK)
94 adios (maildir, "unable to change directory to");
95 if (!(mp = m_gmsg (folder)))
96 adios (NULLCP, "unable to read folder %s", folder);
97 if (mp -> hghmsg == 0)
98 adios (NULLCP, "no messages in %s", folder);
100 for (msgnum = 0; msgnum < msgp; msgnum++)
101 if (!m_convert (mp, msgs[msgnum]))
105 for (msgnum = mp -> lowsel; msgnum <= mp -> hghsel; msgnum++)
106 if (mp -> msgstats[msgnum] & SELECTED) {
108 mp -> msgstats[msgnum] |= DELETED;
110 mp -> msgstats[msgnum] &= ~EXISTS;
112 mp -> msgflags |= SEQMOD;
114 m_replace (pfolder, folder);
119 if (mp -> numsel > MAXARGS - 2)
120 adios (NULLCP, "more than %d messages for %s exec", MAXARGS - 2,
122 vec = (char **) calloc ((unsigned) (mp -> numsel + 2), sizeof *vec);
124 adios (NULLCP, "unable to allocate exec vector");
126 for (msgnum = mp -> lowsel; msgnum <= mp -> hghsel; msgnum++)
127 if (mp -> msgstats[msgnum] & SELECTED)
128 vec[vecp++] = getcpy (m_name (msgnum));
131 (void) fflush (stdout);
132 vec[0] = r1bindex (rmmproc, '/');
133 execvp (rmmproc, vec);
134 adios (rmmproc, "unable to exec");
137 for (msgnum = mp -> lowsel; msgnum <= mp -> hghsel; msgnum++)
138 if (mp -> msgstats[msgnum] & SELECTED) {
139 (void) strcpy (buf, m_backup (dp = m_name (msgnum)));
140 if (rename (dp, buf) == NOTOK)
141 admonish (buf, "unable to rename %s to", dp);