1 /* pick.c - select messages by content */
3 static char ident[] = "@(#)$Id: pick.c,v 1.4 1992/12/15 00:20:22 jromine Exp $";
7 #include "../zotnet/tws.h"
15 static struct swit switches[] = {
40 "-othercomponent pattern", 0,
72 static int listsw = 0;
103 setlocale(LC_ALL, "");
105 invo_name = r1bindex (argv[0], '/');
106 if ((cp = m_find (invo_name)) != NULL) {
107 ap = brkstring (cp = getcpy (cp), " ", "\n");
108 ap = copyip (ap, arguments);
112 (void) copyip (argv + 1, ap);
117 while (cp = *argp++) {
123 switch (smatch (cp, switches)) {
125 ambigsw (cp, switches);
128 adios (NULLCP, "-%s unknown", cp);
130 (void) sprintf (buf, "%s [+folder] [msgs] [switches]",
132 help (buf, switches);
133 listsw = 0; /* HACK */
147 if (!(cp = *argp++))/* allow -xyz arguments */
148 adios (NULLCP, "missing argument to %s", argp[-2]);
152 adios (NULLCP, "internal error!");
163 if (!(cp = *argp++) || *cp == '-')
164 adios (NULLCP, "missing argument to %s", argp[-2]);
168 adios (NULLCP, "only %d sequences allowed!", NATTRS);
192 if (*cp == '+' || *cp == '@')
194 adios (NULLCP, "only one folder at a time!");
196 folder = path (cp + 1, *cp == '+' ? TFOLDER : TSUBCWF);
204 if (!m_find ("path"))
205 free (path ("./", TFOLDER));
207 msgs[msgp++] = "all";
209 folder = m_getfolder ();
210 maildir = m_maildir (folder);
212 if (chdir (maildir) == NOTOK)
213 adios (maildir, "unable to change directory to");
214 if (!(mp = m_gmsg (folder)))
215 adios (NULLCP, "unable to read folder %s", folder);
216 if (mp -> hghmsg == 0)
217 adios (NULLCP, "no messages in %s", folder);
219 for (msgnum = 0; msgnum < msgp; msgnum++)
220 if (!m_convert (mp, msgs[msgnum]))
227 publicsw = mp -> msgflags & READONLY ? 0 : 1;
228 if (publicsw && (mp -> msgflags & READONLY))
229 adios (NULLCP, "folder %s is read-only, so -public not allowed",
234 if (!pcompile (vec, NULLCP))
240 for (msgnum = mp -> lowsel; msgnum <= mp -> hghsel; msgnum++)
241 if (mp -> msgstats[msgnum] & SELECTED) {
242 if ((fp = fopen (cp = m_name (msgnum), "r")) == NULL)
243 admonish (cp, "unable to read message");
244 if (fp && pmatches (fp, msgnum, 0L, 0L)) {
251 mp -> msgstats[msgnum] &= ~SELECTED;
261 if (mp -> numsel <= 0)
262 adios (NULLCP, "no messages match specification");
267 for (seqp = 0; seqs[seqp]; seqp++) {
268 if (zerosw && !m_seqnew (mp, seqs[seqp], publicsw))
270 for (msgnum = mp -> lowsel; msgnum <= mp -> hghsel; msgnum++)
271 if (mp -> msgstats[msgnum] & SELECTED)
272 if (!m_seqadd (mp, seqs[seqp], msgnum, publicsw))
277 for (msgnum = mp -> lowsel; msgnum <= mp -> hghsel; msgnum++)
278 if (mp -> msgstats[msgnum] & SELECTED)
279 printf ("%s\n", m_name (msgnum));
282 printf ("%d hit%s\n", mp -> numsel,
283 mp -> numsel == 1 ? "" : "s");
285 m_replace (pfolder, folder);
297 if (listsw && status && !isatty (fileno (stdout)))