- if (*cp == '+' || *cp == '@') {
- if (folder)
- adios (NULL, "only one folder at a time!");
- else
- folder = path (cp + 1, *cp == '+' ? TFOLDER : TSUBCWF);
- } else {
- /*
- * Check if we need to allocate more space
- * for message name/ranges/sequences.
- */
- if (nummsgs >= maxmsgs) {
- maxmsgs += MAXMSGS;
- if (!(msgs = (char **) realloc (msgs,
- (size_t) (maxmsgs * sizeof(*msgs)))))
- adios (NULL, "unable to reallocate msgs storage");
- }
- msgs[nummsgs++] = cp;
+ vec[vecp] = NULL;
+
+ /*
+ ** If we didn't specify which messages to search,
+ ** then search the whole folder.
+ */
+ if (!msgs.size)
+ app_msgarg(&msgs, seq_all);
+
+ if (!folder)
+ folder = getcurfol();
+ maildir = toabsdir(folder);
+
+ if (chdir(maildir) == NOTOK)
+ adios(maildir, "unable to change directory to");
+
+ /* read folder and create message structure */
+ if (!(mp = folder_read(folder)))
+ adios(NULL, "unable to read folder %s", folder);
+
+ /* check for empty folder */
+ if (mp->nummsg == 0)
+ adios(NULL, "no messages in %s", folder);
+
+ /* parse all the message ranges/sequences and set SELECTED */
+ for (msgnum = 0; msgnum < msgs.size; msgnum++)
+ if (!m_convert(mp, msgs.msgs[msgnum]))
+ done(1);
+ seq_setprev(mp); /* set the previous-sequence */
+
+ /*
+ ** If we aren't saving the results to a sequence,
+ ** we default to list the results.
+ */
+ if (listsw == -1)
+ listsw = !seqp;
+
+ if (publicsw == 1 && is_readonly(mp))
+ adios(NULL, "folder %s is read-only, so -public not allowed",
+ folder);
+
+ if (!pcompile(vec, NULL))
+ done(1);
+
+ lo = mp->lowsel;
+ hi = mp->hghsel;
+
+ /*
+ ** If printing message numbers to standard out,
+ ** force line buffering on.
+ */
+ if (listsw)
+ setvbuf(stdout, NULL, _IOLBF, 0);
+
+ /*
+ ** Scan through all the SELECTED messages and check for a
+ ** match. If the message does not match, then unselect it.
+ */
+ for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) {
+ if (is_selected(mp, msgnum)) {
+ if ((fp = fopen(cp = m_name(msgnum), "r")) == NULL)
+ admonish(cp, "unable to read message");
+ if (fp && pmatches(fp, msgnum, 0L, 0L)) {
+ if (msgnum < lo)
+ lo = msgnum;
+ if (msgnum > hi)
+ hi = msgnum;
+
+ if (listsw)
+ printf("%s\n", m_name(msgnum));
+ } else {
+ /* if it doesn't match, then unselect it */
+ unset_selected(mp, msgnum);
+ mp->numsel--;
+ }
+ if (fp)
+ fclose(fp);
+ }