1994-05-27 12:33:43 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1980, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the University of
|
|
|
|
* California, Berkeley and its contributors.
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef lint
|
2001-03-25 04:57:05 +00:00
|
|
|
#if 0
|
2001-12-18 20:52:09 +00:00
|
|
|
static char sccsid[] = "@(#)list.c 8.4 (Berkeley) 5/1/95";
|
2001-03-25 04:57:05 +00:00
|
|
|
#endif
|
1994-05-27 12:33:43 +00:00
|
|
|
#endif /* not lint */
|
2002-06-30 05:25:07 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
#include "rcv.h"
|
|
|
|
#include <ctype.h>
|
|
|
|
#include "extern.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Mail -- a mail program
|
|
|
|
*
|
|
|
|
* Message list handling.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Convert the user string of message numbers and
|
|
|
|
* store the numbers into vector.
|
|
|
|
*
|
|
|
|
* Returns the count of messages picked up or -1 on error.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
getmsglist(buf, vector, flags)
|
|
|
|
char *buf;
|
|
|
|
int *vector, flags;
|
|
|
|
{
|
2001-05-27 20:26:22 +00:00
|
|
|
int *ip;
|
|
|
|
struct message *mp;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
if (msgCount == 0) {
|
|
|
|
*vector = 0;
|
2001-05-27 20:26:22 +00:00
|
|
|
return (0);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
if (markall(buf, flags) < 0)
|
2001-05-27 20:26:22 +00:00
|
|
|
return (-1);
|
1994-05-27 12:33:43 +00:00
|
|
|
ip = vector;
|
|
|
|
for (mp = &message[0]; mp < &message[msgCount]; mp++)
|
|
|
|
if (mp->m_flag & MMARK)
|
|
|
|
*ip++ = mp - &message[0] + 1;
|
|
|
|
*ip = 0;
|
2001-05-27 20:26:22 +00:00
|
|
|
return (ip - vector);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Mark all messages that the user wanted from the command
|
|
|
|
* line in the message structure. Return 0 on success, -1
|
|
|
|
* on error.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Bit values for colon modifiers.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define CMNEW 01 /* New messages */
|
|
|
|
#define CMOLD 02 /* Old messages */
|
|
|
|
#define CMUNREAD 04 /* Unread messages */
|
|
|
|
#define CMDELETED 010 /* Deleted messages */
|
|
|
|
#define CMREAD 020 /* Read messages */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The following table describes the letters which can follow
|
|
|
|
* the colon and gives the corresponding modifier bit.
|
|
|
|
*/
|
|
|
|
|
2007-11-08 11:13:03 +00:00
|
|
|
static struct coltab {
|
1994-05-27 12:33:43 +00:00
|
|
|
char co_char; /* What to find past : */
|
|
|
|
int co_bit; /* Associated modifier bit */
|
|
|
|
int co_mask; /* m_status bits to mask */
|
|
|
|
int co_equal; /* ... must equal this */
|
|
|
|
} coltab[] = {
|
2001-05-27 20:26:22 +00:00
|
|
|
{ 'n', CMNEW, MNEW, MNEW },
|
|
|
|
{ 'o', CMOLD, MNEW, 0 },
|
|
|
|
{ 'u', CMUNREAD, MREAD, 0 },
|
|
|
|
{ 'd', CMDELETED, MDELETED, MDELETED},
|
|
|
|
{ 'r', CMREAD, MREAD, MREAD },
|
|
|
|
{ 0, 0, 0, 0 }
|
1994-05-27 12:33:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static int lastcolmod;
|
|
|
|
|
|
|
|
int
|
|
|
|
markall(buf, f)
|
|
|
|
char buf[];
|
|
|
|
int f;
|
|
|
|
{
|
2001-05-27 20:26:22 +00:00
|
|
|
char **np;
|
|
|
|
int i;
|
|
|
|
struct message *mp;
|
1994-05-27 12:33:43 +00:00
|
|
|
char *namelist[NMLSIZE], *bufp;
|
|
|
|
int tok, beg, mc, star, other, valdot, colmod, colresult;
|
|
|
|
|
|
|
|
valdot = dot - &message[0] + 1;
|
|
|
|
colmod = 0;
|
|
|
|
for (i = 1; i <= msgCount; i++)
|
|
|
|
unmark(i);
|
|
|
|
bufp = buf;
|
|
|
|
mc = 0;
|
|
|
|
np = &namelist[0];
|
|
|
|
scaninit();
|
|
|
|
tok = scan(&bufp);
|
|
|
|
star = 0;
|
|
|
|
other = 0;
|
|
|
|
beg = 0;
|
|
|
|
while (tok != TEOL) {
|
|
|
|
switch (tok) {
|
|
|
|
case TNUMBER:
|
|
|
|
number:
|
|
|
|
if (star) {
|
|
|
|
printf("No numbers mixed with *\n");
|
2001-05-27 20:26:22 +00:00
|
|
|
return (-1);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
mc++;
|
|
|
|
other++;
|
|
|
|
if (beg != 0) {
|
|
|
|
if (check(lexnumber, f))
|
2001-05-27 20:26:22 +00:00
|
|
|
return (-1);
|
1994-05-27 12:33:43 +00:00
|
|
|
for (i = beg; i <= lexnumber; i++)
|
|
|
|
if (f == MDELETED || (message[i - 1].m_flag & MDELETED) == 0)
|
|
|
|
mark(i);
|
|
|
|
beg = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
beg = lexnumber;
|
|
|
|
if (check(beg, f))
|
2001-05-27 20:26:22 +00:00
|
|
|
return (-1);
|
1994-05-27 12:33:43 +00:00
|
|
|
tok = scan(&bufp);
|
|
|
|
regret(tok);
|
|
|
|
if (tok != TDASH) {
|
|
|
|
mark(beg);
|
|
|
|
beg = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TPLUS:
|
|
|
|
if (beg != 0) {
|
|
|
|
printf("Non-numeric second argument\n");
|
2001-05-27 20:26:22 +00:00
|
|
|
return (-1);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
i = valdot;
|
|
|
|
do {
|
|
|
|
i++;
|
|
|
|
if (i > msgCount) {
|
|
|
|
printf("Referencing beyond EOF\n");
|
2001-05-27 20:26:22 +00:00
|
|
|
return (-1);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
} while ((message[i - 1].m_flag & MDELETED) != f);
|
|
|
|
mark(i);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TDASH:
|
|
|
|
if (beg == 0) {
|
|
|
|
i = valdot;
|
|
|
|
do {
|
|
|
|
i--;
|
|
|
|
if (i <= 0) {
|
|
|
|
printf("Referencing before 1\n");
|
2001-05-27 20:26:22 +00:00
|
|
|
return (-1);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
} while ((message[i - 1].m_flag & MDELETED) != f);
|
|
|
|
mark(i);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TSTRING:
|
|
|
|
if (beg != 0) {
|
|
|
|
printf("Non-numeric second argument\n");
|
2001-05-27 20:26:22 +00:00
|
|
|
return (-1);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
other++;
|
|
|
|
if (lexstring[0] == ':') {
|
|
|
|
colresult = evalcol(lexstring[1]);
|
|
|
|
if (colresult == 0) {
|
|
|
|
printf("Unknown colon modifier \"%s\"\n",
|
|
|
|
lexstring);
|
2001-05-27 20:26:22 +00:00
|
|
|
return (-1);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
colmod |= colresult;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
*np++ = savestr(lexstring);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TDOLLAR:
|
|
|
|
case TUP:
|
|
|
|
case TDOT:
|
|
|
|
lexnumber = metamess(lexstring[0], f);
|
|
|
|
if (lexnumber == -1)
|
2001-05-27 20:26:22 +00:00
|
|
|
return (-1);
|
1994-05-27 12:33:43 +00:00
|
|
|
goto number;
|
|
|
|
|
|
|
|
case TSTAR:
|
|
|
|
if (other) {
|
|
|
|
printf("Can't mix \"*\" with anything\n");
|
2001-05-27 20:26:22 +00:00
|
|
|
return (-1);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
star++;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TERROR:
|
2001-05-27 20:26:22 +00:00
|
|
|
return (-1);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
tok = scan(&bufp);
|
|
|
|
}
|
|
|
|
lastcolmod = colmod;
|
2001-05-27 20:26:22 +00:00
|
|
|
*np = NULL;
|
1994-05-27 12:33:43 +00:00
|
|
|
mc = 0;
|
|
|
|
if (star) {
|
|
|
|
for (i = 0; i < msgCount; i++)
|
|
|
|
if ((message[i].m_flag & MDELETED) == f) {
|
|
|
|
mark(i+1);
|
|
|
|
mc++;
|
|
|
|
}
|
|
|
|
if (mc == 0) {
|
|
|
|
printf("No applicable messages.\n");
|
2001-05-27 20:26:22 +00:00
|
|
|
return (-1);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
2001-05-27 20:26:22 +00:00
|
|
|
return (0);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If no numbers were given, mark all of the messages,
|
|
|
|
* so that we can unmark any whose sender was not selected
|
|
|
|
* if any user names were given.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if ((np > namelist || colmod != 0) && mc == 0)
|
|
|
|
for (i = 1; i <= msgCount; i++)
|
|
|
|
if ((message[i-1].m_flag & MDELETED) == f)
|
|
|
|
mark(i);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If any names were given, go through and eliminate any
|
|
|
|
* messages whose senders were not requested.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (np > namelist) {
|
|
|
|
for (i = 1; i <= msgCount; i++) {
|
2001-05-27 20:26:22 +00:00
|
|
|
for (mc = 0, np = &namelist[0]; *np != NULL; np++)
|
1994-05-27 12:33:43 +00:00
|
|
|
if (**np == '/') {
|
2002-06-25 05:24:30 +00:00
|
|
|
if (matchfield(*np, i)) {
|
1994-05-27 12:33:43 +00:00
|
|
|
mc++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (matchsender(*np, i)) {
|
|
|
|
mc++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (mc == 0)
|
|
|
|
unmark(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Make sure we got some decent messages.
|
|
|
|
*/
|
|
|
|
|
|
|
|
mc = 0;
|
|
|
|
for (i = 1; i <= msgCount; i++)
|
|
|
|
if (message[i-1].m_flag & MMARK) {
|
|
|
|
mc++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (mc == 0) {
|
|
|
|
printf("No applicable messages from {%s",
|
|
|
|
namelist[0]);
|
2001-05-27 20:26:22 +00:00
|
|
|
for (np = &namelist[1]; *np != NULL; np++)
|
1994-05-27 12:33:43 +00:00
|
|
|
printf(", %s", *np);
|
|
|
|
printf("}\n");
|
2001-05-27 20:26:22 +00:00
|
|
|
return (-1);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If any colon modifiers were given, go through and
|
|
|
|
* unmark any messages which do not satisfy the modifiers.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (colmod != 0) {
|
|
|
|
for (i = 1; i <= msgCount; i++) {
|
2001-05-27 20:26:22 +00:00
|
|
|
struct coltab *colp;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
mp = &message[i - 1];
|
2001-05-27 20:26:22 +00:00
|
|
|
for (colp = &coltab[0]; colp->co_char != '\0'; colp++)
|
1994-05-27 12:33:43 +00:00
|
|
|
if (colp->co_bit & colmod)
|
|
|
|
if ((mp->m_flag & colp->co_mask)
|
|
|
|
!= colp->co_equal)
|
|
|
|
unmark(i);
|
1995-05-30 06:41:30 +00:00
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
for (mp = &message[0]; mp < &message[msgCount]; mp++)
|
|
|
|
if (mp->m_flag & MMARK)
|
|
|
|
break;
|
|
|
|
if (mp >= &message[msgCount]) {
|
2001-05-27 20:26:22 +00:00
|
|
|
struct coltab *colp;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
printf("No messages satisfy");
|
2001-05-27 20:26:22 +00:00
|
|
|
for (colp = &coltab[0]; colp->co_char != '\0'; colp++)
|
1994-05-27 12:33:43 +00:00
|
|
|
if (colp->co_bit & colmod)
|
|
|
|
printf(" :%c", colp->co_char);
|
|
|
|
printf("\n");
|
2001-05-27 20:26:22 +00:00
|
|
|
return (-1);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
}
|
2001-05-27 20:26:22 +00:00
|
|
|
return (0);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Turn the character after a colon modifier into a bit
|
|
|
|
* value.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
evalcol(col)
|
|
|
|
int col;
|
|
|
|
{
|
2001-05-27 20:26:22 +00:00
|
|
|
struct coltab *colp;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
if (col == 0)
|
2001-05-27 20:26:22 +00:00
|
|
|
return (lastcolmod);
|
|
|
|
for (colp = &coltab[0]; colp->co_char != '\0'; colp++)
|
1994-05-27 12:33:43 +00:00
|
|
|
if (colp->co_char == col)
|
2001-05-27 20:26:22 +00:00
|
|
|
return (colp->co_bit);
|
|
|
|
return (0);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check the passed message number for legality and proper flags.
|
|
|
|
* If f is MDELETED, then either kind will do. Otherwise, the message
|
|
|
|
* has to be undeleted.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
check(mesg, f)
|
|
|
|
int mesg, f;
|
|
|
|
{
|
2001-05-27 20:26:22 +00:00
|
|
|
struct message *mp;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
if (mesg < 1 || mesg > msgCount) {
|
|
|
|
printf("%d: Invalid message number\n", mesg);
|
2001-05-27 20:26:22 +00:00
|
|
|
return (-1);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
mp = &message[mesg-1];
|
|
|
|
if (f != MDELETED && (mp->m_flag & MDELETED) != 0) {
|
|
|
|
printf("%d: Inappropriate message\n", mesg);
|
2001-05-27 20:26:22 +00:00
|
|
|
return (-1);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
2001-05-27 20:26:22 +00:00
|
|
|
return (0);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Scan out the list of string arguments, shell style
|
|
|
|
* for a RAWLIST.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
getrawlist(line, argv, argc)
|
|
|
|
char line[];
|
|
|
|
char **argv;
|
|
|
|
int argc;
|
|
|
|
{
|
2001-05-27 20:26:22 +00:00
|
|
|
char c, *cp, *cp2, quotec;
|
1994-05-27 12:33:43 +00:00
|
|
|
int argn;
|
2001-03-25 04:57:05 +00:00
|
|
|
char *linebuf;
|
|
|
|
size_t linebufsize = BUFSIZ;
|
|
|
|
|
2001-05-27 20:26:22 +00:00
|
|
|
if ((linebuf = malloc(linebufsize)) == NULL)
|
2001-03-25 04:57:05 +00:00
|
|
|
err(1, "Out of memory");
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
argn = 0;
|
|
|
|
cp = line;
|
|
|
|
for (;;) {
|
|
|
|
for (; *cp == ' ' || *cp == '\t'; cp++)
|
|
|
|
;
|
|
|
|
if (*cp == '\0')
|
|
|
|
break;
|
|
|
|
if (argn >= argc - 1) {
|
|
|
|
printf(
|
|
|
|
"Too many elements in the list; excess discarded.\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
cp2 = linebuf;
|
|
|
|
quotec = '\0';
|
|
|
|
while ((c = *cp) != '\0') {
|
2001-03-25 04:57:05 +00:00
|
|
|
/* Allocate more space if necessary */
|
|
|
|
if (cp2 - linebuf == linebufsize - 1) {
|
|
|
|
linebufsize += BUFSIZ;
|
|
|
|
if ((linebuf = realloc(linebuf, linebufsize)) == NULL)
|
|
|
|
err(1, "Out of memory");
|
|
|
|
cp2 = linebuf + linebufsize - BUFSIZ - 1;
|
|
|
|
}
|
1994-05-27 12:33:43 +00:00
|
|
|
cp++;
|
|
|
|
if (quotec != '\0') {
|
|
|
|
if (c == quotec)
|
|
|
|
quotec = '\0';
|
|
|
|
else if (c == '\\')
|
|
|
|
switch (c = *cp++) {
|
|
|
|
case '\0':
|
|
|
|
*cp2++ = '\\';
|
|
|
|
cp--;
|
|
|
|
break;
|
|
|
|
case '0': case '1': case '2': case '3':
|
|
|
|
case '4': case '5': case '6': case '7':
|
|
|
|
c -= '0';
|
|
|
|
if (*cp >= '0' && *cp <= '7')
|
|
|
|
c = c * 8 + *cp++ - '0';
|
|
|
|
if (*cp >= '0' && *cp <= '7')
|
|
|
|
c = c * 8 + *cp++ - '0';
|
|
|
|
*cp2++ = c;
|
|
|
|
break;
|
|
|
|
case 'b':
|
|
|
|
*cp2++ = '\b';
|
|
|
|
break;
|
|
|
|
case 'f':
|
|
|
|
*cp2++ = '\f';
|
|
|
|
break;
|
|
|
|
case 'n':
|
|
|
|
*cp2++ = '\n';
|
|
|
|
break;
|
|
|
|
case 'r':
|
|
|
|
*cp2++ = '\r';
|
|
|
|
break;
|
|
|
|
case 't':
|
|
|
|
*cp2++ = '\t';
|
|
|
|
break;
|
|
|
|
case 'v':
|
|
|
|
*cp2++ = '\v';
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
*cp2++ = c;
|
|
|
|
}
|
|
|
|
else if (c == '^') {
|
|
|
|
c = *cp++;
|
|
|
|
if (c == '?')
|
|
|
|
*cp2++ = '\177';
|
|
|
|
/* null doesn't show up anyway */
|
2001-05-27 20:26:22 +00:00
|
|
|
else if ((c >= 'A' && c <= '_') ||
|
|
|
|
(c >= 'a' && c <= 'z'))
|
1994-05-27 12:33:43 +00:00
|
|
|
*cp2++ = c & 037;
|
|
|
|
else {
|
|
|
|
*cp2++ = '^';
|
|
|
|
cp--;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
*cp2++ = c;
|
|
|
|
} else if (c == '"' || c == '\'')
|
|
|
|
quotec = c;
|
|
|
|
else if (c == ' ' || c == '\t')
|
|
|
|
break;
|
|
|
|
else
|
|
|
|
*cp2++ = c;
|
|
|
|
}
|
|
|
|
*cp2 = '\0';
|
|
|
|
argv[argn++] = savestr(linebuf);
|
|
|
|
}
|
2001-05-27 20:26:22 +00:00
|
|
|
argv[argn] = NULL;
|
|
|
|
(void)free(linebuf);
|
|
|
|
return (argn);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* scan out a single lexical item and return its token number,
|
|
|
|
* updating the string pointer passed **p. Also, store the value
|
|
|
|
* of the number or string scanned in lexnumber or lexstring as
|
|
|
|
* appropriate. In any event, store the scanned `thing' in lexstring.
|
|
|
|
*/
|
|
|
|
|
2007-11-08 11:13:03 +00:00
|
|
|
static struct lex {
|
1994-05-27 12:33:43 +00:00
|
|
|
char l_char;
|
|
|
|
char l_token;
|
|
|
|
} singles[] = {
|
2001-05-27 20:26:22 +00:00
|
|
|
{ '$', TDOLLAR },
|
|
|
|
{ '.', TDOT },
|
|
|
|
{ '^', TUP },
|
|
|
|
{ '*', TSTAR },
|
|
|
|
{ '-', TDASH },
|
|
|
|
{ '+', TPLUS },
|
|
|
|
{ '(', TOPEN },
|
|
|
|
{ ')', TCLOSE },
|
|
|
|
{ 0, 0 }
|
1994-05-27 12:33:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
int
|
|
|
|
scan(sp)
|
|
|
|
char **sp;
|
|
|
|
{
|
2001-05-27 20:26:22 +00:00
|
|
|
char *cp, *cp2;
|
|
|
|
int c;
|
|
|
|
struct lex *lp;
|
1994-05-27 12:33:43 +00:00
|
|
|
int quotec;
|
|
|
|
|
|
|
|
if (regretp >= 0) {
|
|
|
|
strcpy(lexstring, string_stack[regretp]);
|
|
|
|
lexnumber = numberstack[regretp];
|
2001-05-27 20:26:22 +00:00
|
|
|
return (regretstack[regretp--]);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
cp = *sp;
|
|
|
|
cp2 = lexstring;
|
|
|
|
c = *cp++;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* strip away leading white space.
|
|
|
|
*/
|
|
|
|
|
|
|
|
while (c == ' ' || c == '\t')
|
|
|
|
c = *cp++;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If no characters remain, we are at end of line,
|
|
|
|
* so report that.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (c == '\0') {
|
|
|
|
*sp = --cp;
|
2001-05-27 20:26:22 +00:00
|
|
|
return (TEOL);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the leading character is a digit, scan
|
|
|
|
* the number and convert it on the fly.
|
|
|
|
* Return TNUMBER when done.
|
|
|
|
*/
|
|
|
|
|
2001-12-19 21:50:22 +00:00
|
|
|
if (isdigit((unsigned char)c)) {
|
1994-05-27 12:33:43 +00:00
|
|
|
lexnumber = 0;
|
2001-12-19 21:50:22 +00:00
|
|
|
while (isdigit((unsigned char)c)) {
|
1994-05-27 12:33:43 +00:00
|
|
|
lexnumber = lexnumber*10 + c - '0';
|
|
|
|
*cp2++ = c;
|
|
|
|
c = *cp++;
|
|
|
|
}
|
|
|
|
*cp2 = '\0';
|
|
|
|
*sp = --cp;
|
2001-05-27 20:26:22 +00:00
|
|
|
return (TNUMBER);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check for single character tokens; return such
|
|
|
|
* if found.
|
|
|
|
*/
|
|
|
|
|
2001-05-27 20:26:22 +00:00
|
|
|
for (lp = &singles[0]; lp->l_char != '\0'; lp++)
|
1994-05-27 12:33:43 +00:00
|
|
|
if (c == lp->l_char) {
|
|
|
|
lexstring[0] = c;
|
|
|
|
lexstring[1] = '\0';
|
|
|
|
*sp = cp;
|
2001-05-27 20:26:22 +00:00
|
|
|
return (lp->l_token);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We've got a string! Copy all the characters
|
|
|
|
* of the string into lexstring, until we see
|
|
|
|
* a null, space, or tab.
|
|
|
|
* If the lead character is a " or ', save it
|
|
|
|
* and scan until you get another.
|
|
|
|
*/
|
|
|
|
|
|
|
|
quotec = 0;
|
|
|
|
if (c == '\'' || c == '"') {
|
|
|
|
quotec = c;
|
|
|
|
c = *cp++;
|
|
|
|
}
|
|
|
|
while (c != '\0') {
|
|
|
|
if (c == quotec) {
|
|
|
|
cp++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (quotec == 0 && (c == ' ' || c == '\t'))
|
|
|
|
break;
|
|
|
|
if (cp2 - lexstring < STRINGLEN-1)
|
|
|
|
*cp2++ = c;
|
|
|
|
c = *cp++;
|
|
|
|
}
|
2001-05-27 20:26:22 +00:00
|
|
|
if (quotec && c == '\0') {
|
1994-05-27 12:33:43 +00:00
|
|
|
fprintf(stderr, "Missing %c\n", quotec);
|
2001-05-27 20:26:22 +00:00
|
|
|
return (TERROR);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
*sp = --cp;
|
|
|
|
*cp2 = '\0';
|
2001-05-27 20:26:22 +00:00
|
|
|
return (TSTRING);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Unscan the named token by pushing it onto the regret stack.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
regret(token)
|
|
|
|
int token;
|
|
|
|
{
|
|
|
|
if (++regretp >= REGDEP)
|
2001-03-25 04:57:05 +00:00
|
|
|
errx(1, "Too many regrets");
|
1994-05-27 12:33:43 +00:00
|
|
|
regretstack[regretp] = token;
|
|
|
|
lexstring[STRINGLEN-1] = '\0';
|
|
|
|
string_stack[regretp] = savestr(lexstring);
|
|
|
|
numberstack[regretp] = lexnumber;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Reset all the scanner global variables.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
scaninit()
|
|
|
|
{
|
|
|
|
regretp = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Find the first message whose flags & m == f and return
|
|
|
|
* its message number.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
first(f, m)
|
|
|
|
int f, m;
|
|
|
|
{
|
2001-05-27 20:26:22 +00:00
|
|
|
struct message *mp;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
if (msgCount == 0)
|
2001-05-27 20:26:22 +00:00
|
|
|
return (0);
|
1994-05-27 12:33:43 +00:00
|
|
|
f &= MDELETED;
|
|
|
|
m &= MDELETED;
|
|
|
|
for (mp = dot; mp < &message[msgCount]; mp++)
|
|
|
|
if ((mp->m_flag & m) == f)
|
2001-05-27 20:26:22 +00:00
|
|
|
return (mp - message + 1);
|
1994-05-27 12:33:43 +00:00
|
|
|
for (mp = dot-1; mp >= &message[0]; mp--)
|
|
|
|
if ((mp->m_flag & m) == f)
|
2001-05-27 20:26:22 +00:00
|
|
|
return (mp - message + 1);
|
|
|
|
return (0);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* See if the passed name sent the passed message number. Return true
|
|
|
|
* if so.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
matchsender(str, mesg)
|
|
|
|
char *str;
|
|
|
|
int mesg;
|
|
|
|
{
|
2002-06-25 05:28:32 +00:00
|
|
|
char *cp;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2002-06-25 05:28:32 +00:00
|
|
|
/* null string matches nothing instead of everything */
|
|
|
|
if (*str == '\0')
|
2001-05-27 20:26:22 +00:00
|
|
|
return (0);
|
2002-06-25 05:28:32 +00:00
|
|
|
|
|
|
|
cp = nameof(&message[mesg - 1], 0);
|
|
|
|
return (strcasestr(cp, str) != NULL);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
2001-12-18 20:52:09 +00:00
|
|
|
/*
|
|
|
|
* See if the passed name received the passed message number. Return true
|
|
|
|
* if so.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static char *to_fields[] = { "to", "cc", "bcc", NULL };
|
|
|
|
|
2007-11-08 11:13:03 +00:00
|
|
|
static int
|
2001-12-18 20:52:09 +00:00
|
|
|
matchto(str, mesg)
|
|
|
|
char *str;
|
|
|
|
int mesg;
|
|
|
|
{
|
|
|
|
struct message *mp;
|
2002-06-25 05:28:32 +00:00
|
|
|
char *cp, **to;
|
2001-12-18 20:52:09 +00:00
|
|
|
|
|
|
|
str++;
|
|
|
|
|
|
|
|
/* null string matches nothing instead of everything */
|
|
|
|
if (*str == '\0')
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
mp = &message[mesg - 1];
|
|
|
|
|
|
|
|
for (to = to_fields; *to != NULL; to++) {
|
2002-06-25 05:28:32 +00:00
|
|
|
cp = hfield(*to, mp);
|
|
|
|
if (cp != NULL && strcasestr(cp, str) != NULL)
|
|
|
|
return (1);
|
2001-12-18 20:52:09 +00:00
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
/*
|
2002-06-25 05:24:30 +00:00
|
|
|
* See if the given substring is contained within the specified field. If
|
|
|
|
* 'searchheaders' is set, then the form '/x:y' will be accepted and matches
|
|
|
|
* any message with the substring 'y' in field 'x'. If 'x' is omitted or
|
|
|
|
* 'searchheaders' is not set, then the search matches any messages
|
|
|
|
* with the substring 'y' in the 'Subject'. The search is case insensitive.
|
|
|
|
*
|
|
|
|
* The form '/to:y' is a special case, and will match all messages
|
|
|
|
* containing the substring 'y' in the 'To', 'Cc', or 'Bcc' header
|
|
|
|
* fields. The search for 'to' is case sensitive, so that '/To:y' can
|
|
|
|
* be used to limit the search to just the 'To' field.
|
1994-05-27 12:33:43 +00:00
|
|
|
*/
|
|
|
|
|
2007-11-08 11:13:03 +00:00
|
|
|
static char lastscan[STRINGLEN];
|
1994-05-27 12:33:43 +00:00
|
|
|
int
|
2002-06-25 05:24:30 +00:00
|
|
|
matchfield(str, mesg)
|
1994-05-27 12:33:43 +00:00
|
|
|
char *str;
|
|
|
|
int mesg;
|
|
|
|
{
|
2001-05-27 20:26:22 +00:00
|
|
|
struct message *mp;
|
2002-06-25 05:28:32 +00:00
|
|
|
char *cp, *cp2;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
str++;
|
2001-03-25 04:57:05 +00:00
|
|
|
if (*str == '\0')
|
1994-05-27 12:33:43 +00:00
|
|
|
str = lastscan;
|
|
|
|
else
|
2001-03-25 04:57:05 +00:00
|
|
|
strlcpy(lastscan, str, sizeof(lastscan));
|
1994-05-27 12:33:43 +00:00
|
|
|
mp = &message[mesg-1];
|
1995-05-30 06:41:30 +00:00
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
/*
|
|
|
|
* Now look, ignoring case, for the word in the string.
|
|
|
|
*/
|
|
|
|
|
2001-05-27 20:26:22 +00:00
|
|
|
if (value("searchheaders") && (cp = strchr(str, ':')) != NULL) {
|
2002-06-25 05:24:30 +00:00
|
|
|
/* Check for special case "/to:" */
|
|
|
|
if (strncmp(str, "to:", 3) == 0)
|
2001-12-18 20:52:09 +00:00
|
|
|
return (matchto(cp, mesg));
|
1994-05-27 12:33:43 +00:00
|
|
|
*cp++ = '\0';
|
2001-12-18 20:52:09 +00:00
|
|
|
cp2 = hfield(*str != '\0' ? str : "subject", mp);
|
1994-05-27 12:33:43 +00:00
|
|
|
cp[-1] = ':';
|
|
|
|
str = cp;
|
2002-06-25 05:28:32 +00:00
|
|
|
cp = cp2;
|
|
|
|
} else
|
|
|
|
cp = hfield("subject", mp);
|
|
|
|
|
|
|
|
if (cp == NULL)
|
2001-05-27 20:26:22 +00:00
|
|
|
return (0);
|
2002-06-25 05:28:32 +00:00
|
|
|
|
|
|
|
return (strcasestr(cp, str) != NULL);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Mark the named message by setting its mark bit.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
mark(mesg)
|
|
|
|
int mesg;
|
|
|
|
{
|
2001-05-27 20:26:22 +00:00
|
|
|
int i;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
i = mesg;
|
|
|
|
if (i < 1 || i > msgCount)
|
2001-03-25 04:57:05 +00:00
|
|
|
errx(1, "Bad message number to mark");
|
1994-05-27 12:33:43 +00:00
|
|
|
message[i-1].m_flag |= MMARK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Unmark the named message.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
unmark(mesg)
|
|
|
|
int mesg;
|
|
|
|
{
|
2001-05-27 20:26:22 +00:00
|
|
|
int i;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
i = mesg;
|
|
|
|
if (i < 1 || i > msgCount)
|
2001-03-25 04:57:05 +00:00
|
|
|
errx(1, "Bad message number to unmark");
|
1994-05-27 12:33:43 +00:00
|
|
|
message[i-1].m_flag &= ~MMARK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return the message number corresponding to the passed meta character.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
metamess(meta, f)
|
|
|
|
int meta, f;
|
|
|
|
{
|
2001-05-27 20:26:22 +00:00
|
|
|
int c, m;
|
|
|
|
struct message *mp;
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
c = meta;
|
|
|
|
switch (c) {
|
|
|
|
case '^':
|
|
|
|
/*
|
|
|
|
* First 'good' message left.
|
|
|
|
*/
|
|
|
|
for (mp = &message[0]; mp < &message[msgCount]; mp++)
|
|
|
|
if ((mp->m_flag & MDELETED) == f)
|
2001-05-27 20:26:22 +00:00
|
|
|
return (mp - &message[0] + 1);
|
1994-05-27 12:33:43 +00:00
|
|
|
printf("No applicable messages\n");
|
2001-05-27 20:26:22 +00:00
|
|
|
return (-1);
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
case '$':
|
|
|
|
/*
|
|
|
|
* Last 'good message left.
|
|
|
|
*/
|
|
|
|
for (mp = &message[msgCount-1]; mp >= &message[0]; mp--)
|
|
|
|
if ((mp->m_flag & MDELETED) == f)
|
2001-05-27 20:26:22 +00:00
|
|
|
return (mp - &message[0] + 1);
|
1994-05-27 12:33:43 +00:00
|
|
|
printf("No applicable messages\n");
|
2001-05-27 20:26:22 +00:00
|
|
|
return (-1);
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
case '.':
|
1995-05-30 06:41:30 +00:00
|
|
|
/*
|
1994-05-27 12:33:43 +00:00
|
|
|
* Current message.
|
|
|
|
*/
|
|
|
|
m = dot - &message[0] + 1;
|
|
|
|
if ((dot->m_flag & MDELETED) != f) {
|
|
|
|
printf("%d: Inappropriate message\n", m);
|
2001-05-27 20:26:22 +00:00
|
|
|
return (-1);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
2001-05-27 20:26:22 +00:00
|
|
|
return (m);
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
printf("Unknown metachar (%c)\n", c);
|
2001-05-27 20:26:22 +00:00
|
|
|
return (-1);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
}
|