- invo_name = r1bindex (argv[0], '/');
-
- /* read user profile/context */
- context_read();
-
- arguments = getarguments (invo_name, argc, argv, 1);
- argp = arguments;
-
- while ((cp = *argp++)) {
- if (*cp == '-') {
- if (*++cp == '-') {
- vec[vecp++] = --cp;
- goto pattern;
- }
- switch (smatch (cp, switches)) {
- case AMBIGSW:
- ambigsw (cp, switches);
- listsw = 0; /* HACK */
- done (1);
- case UNKWNSW:
- adios (NULL, "-%s unknown", cp);
-
- case HELPSW:
- snprintf (buf, sizeof(buf), "%s [+folder] [msgs] [switches]",
- invo_name);
- print_help (buf, switches, 1);
- listsw = 0; /* HACK */
- done (1);
- case VERSIONSW:
- print_version(invo_name);
- listsw = 0; /* HACK */
- done (1);
-
- case CCSW:
- case DATESW:
- case FROMSW:
- case SUBJSW:
- case TOSW:
- case DATFDSW:
- case AFTRSW:
- case BEFRSW:
- case SRCHSW:
- vec[vecp++] = --cp;
- pattern:
- if (!(cp = *argp++))/* allow -xyz arguments */
- adios (NULL, "missing argument to %s", argp[-2]);
- vec[vecp++] = cp;
- continue;
- case OTHRSW:
- adios (NULL, "internal error!");
-
- case ANDSW:
- case ORSW:
- case NOTSW:
- case LBRSW:
- case RBRSW:
- vec[vecp++] = --cp;
- continue;
-
- case SEQSW:
- if (!(cp = *argp++) || *cp == '-')
- adios (NULL, "missing argument to %s", argp[-2]);
-
- /* check if too many sequences specified */
- if (seqp >= NUMATTRS)
- adios (NULL, "too many sequences (more than %d) specified", NUMATTRS);
-
- if (!seq_nameok (cp))
- done (1);
-
- seqs[seqp++] = cp;
- continue;
- case PUBLSW:
- publicsw = 1;
- continue;
- case NPUBLSW:
- publicsw = 0;
- continue;
- case ZEROSW:
- zerosw++;
- continue;
- case NZEROSW:
- zerosw = 0;
- continue;
-
- case LISTSW:
- listsw = 1;
- continue;
- case NLISTSW:
- listsw = 0;
- continue;
- }
+ invo_name = mhbasename(argv[0]);
+
+ /* read user profile/context */
+ context_read();
+
+ arguments = getarguments(invo_name, argc, argv, 1);
+ argp = arguments;
+
+ while ((cp = *argp++)) {
+ if (*cp == '-') {
+ if (*++cp == '-') {
+ vec[vecp++] = --cp;
+ goto pattern;
+ }
+ switch (smatch(cp, switches)) {
+ case AMBIGSW:
+ ambigsw(cp, switches);
+ listsw = 0; /* HACK */
+ done(1);
+ case UNKWNSW:
+ adios(NULL, "-%s unknown", cp);
+
+ case HELPSW:
+ snprintf(buf, sizeof(buf), "%s [+folder] [msgs] [switches]", invo_name);
+ print_help(buf, switches, 1);
+ listsw = 0; /* HACK */
+ done(1);
+ case VERSIONSW:
+ print_version(invo_name);
+ listsw = 0; /* HACK */
+ done(1);
+
+ case CCSW:
+ case DATESW:
+ case FROMSW:
+ case SUBJSW:
+ case TOSW:
+ case DATFDSW:
+ case AFTRSW:
+ case BEFRSW:
+ case SRCHSW:
+ vec[vecp++] = --cp;
+ pattern:
+ if (!(cp = *argp++)) /* allow -xyz arguments */
+ adios(NULL, "missing argument to %s",
+ argp[-2]);
+ vec[vecp++] = cp;
+ continue;
+ case OTHRSW:
+ adios(NULL, "internal error!");
+
+ case ANDSW:
+ case ORSW:
+ case NOTSW:
+ case LBRSW:
+ case RBRSW:
+ vec[vecp++] = --cp;
+ continue;
+
+ case SEQSW:
+ if (!(cp = *argp++) || *cp == '-')
+ adios(NULL, "missing argument to %s",
+ argp[-2]);
+
+ /* check if too many sequences specified */
+ if (seqp >= NUMATTRS)
+ adios(NULL, "too many sequences (more than %d) specified", NUMATTRS);
+
+ if (!seq_nameok(cp))
+ done(1);
+
+ seqs[seqp++] = cp;
+ continue;
+ case PUBLSW:
+ publicsw = 1;
+ continue;
+ case NPUBLSW:
+ publicsw = 0;
+ continue;
+ case ZEROSW:
+ zerosw++;
+ continue;
+ case NZEROSW:
+ zerosw = 0;
+ continue;
+
+ case LISTSW:
+ listsw = 1;
+ continue;
+ case NLISTSW:
+ listsw = 0;
+ continue;
+ }
+ }
+ if (*cp == '+' || *cp == '@') {
+ if (folder)
+ adios(NULL, "only one folder at a time!");
+ else
+ folder = getcpy(expandfol(cp));
+ } else
+ app_msgarg(&msgs, 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);
+ }