9 date 92.12.15.00.20.22; author jromine; state Exp;
14 date 92.11.04.00.54.26; author jromine; state Exp;
19 date 92.01.31.22.20.06; author jromine; state Exp;
24 date 92.01.31.22.19.55; author jromine; state Exp;
38 @/* pick.c - select messages by content */
40 static char ident[] = "@@(#)$Id: pick.c,v 1.3 1992/11/04 00:54:26 jromine Exp jromine $";
44 #include "../zotnet/tws.h"
52 static struct swit switches[] = {
77 "-othercomponent pattern", 0,
109 static int listsw = 0;
140 setlocale(LC_ALL, "");
142 invo_name = r1bindex (argv[0], '/');
143 if ((cp = m_find (invo_name)) != NULL) {
144 ap = brkstring (cp = getcpy (cp), " ", "\n");
145 ap = copyip (ap, arguments);
149 (void) copyip (argv + 1, ap);
154 while (cp = *argp++) {
160 switch (smatch (cp, switches)) {
162 ambigsw (cp, switches);
165 adios (NULLCP, "-%s unknown", cp);
167 (void) sprintf (buf, "%s [+folder] [msgs] [switches]",
169 help (buf, switches);
170 listsw = 0; /* HACK */
184 if (!(cp = *argp++))/* allow -xyz arguments */
185 adios (NULLCP, "missing argument to %s", argp[-2]);
189 adios (NULLCP, "internal error!");
200 if (!(cp = *argp++) || *cp == '-')
201 adios (NULLCP, "missing argument to %s", argp[-2]);
205 adios (NULLCP, "only %d sequences allowed!", NATTRS);
229 if (*cp == '+' || *cp == '@@')
231 adios (NULLCP, "only one folder at a time!");
233 folder = path (cp + 1, *cp == '+' ? TFOLDER : TSUBCWF);
241 if (!m_find ("path"))
242 free (path ("./", TFOLDER));
244 msgs[msgp++] = "all";
246 folder = m_getfolder ();
247 maildir = m_maildir (folder);
249 if (chdir (maildir) == NOTOK)
250 adios (maildir, "unable to change directory to");
251 if (!(mp = m_gmsg (folder)))
252 adios (NULLCP, "unable to read folder %s", folder);
253 if (mp -> hghmsg == 0)
254 adios (NULLCP, "no messages in %s", folder);
256 for (msgnum = 0; msgnum < msgp; msgnum++)
257 if (!m_convert (mp, msgs[msgnum]))
264 publicsw = mp -> msgflags & READONLY ? 0 : 1;
265 if (publicsw && (mp -> msgflags & READONLY))
266 adios (NULLCP, "folder %s is read-only, so -public not allowed",
271 if (!pcompile (vec, NULLCP))
277 for (msgnum = mp -> lowsel; msgnum <= mp -> hghsel; msgnum++)
278 if (mp -> msgstats[msgnum] & SELECTED) {
279 if ((fp = fopen (cp = m_name (msgnum), "r")) == NULL)
280 admonish (cp, "unable to read message");
281 if (fp && pmatches (fp, msgnum, 0L, 0L)) {
288 mp -> msgstats[msgnum] &= ~SELECTED;
298 if (mp -> numsel <= 0)
299 adios (NULLCP, "no messages match specification");
304 for (seqp = 0; seqs[seqp]; seqp++) {
305 if (zerosw && !m_seqnew (mp, seqs[seqp], publicsw))
307 for (msgnum = mp -> lowsel; msgnum <= mp -> hghsel; msgnum++)
308 if (mp -> msgstats[msgnum] & SELECTED)
309 if (!m_seqadd (mp, seqs[seqp], msgnum, publicsw))
314 for (msgnum = mp -> lowsel; msgnum <= mp -> hghsel; msgnum++)
315 if (mp -> msgstats[msgnum] & SELECTED)
316 printf ("%s\n", m_name (msgnum));
319 printf ("%d hit%s\n", mp -> numsel,
320 mp -> numsel == 1 ? "" : "s");
322 m_replace (pfolder, folder);
334 if (listsw && status && !isatty (fileno (stdout)))
348 static char ident[] = "@@(#)$Id: pick.c,v 1.2 1992/01/31 22:20:06 jromine Exp jromine $";
360 static char ident[] = "@@(#)$Id$";