/***********************************************************************
* *
* This software is part of the BSD package *
*Copyright (c) 1978-2004 The Regents of the University of California an*
* *
* 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 *
* materials provided with the distribution. *
* *
* 3. Neither the name of The Regents of the University of California*
* 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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. *
* *
* 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 *
* distribution. *
* 3. 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. *
* *
* Kurt Shoens (UCB) *
* gsf *
* *
***********************************************************************/
#pragma prototyped
/*
* Mail -- a mail program
*
* Message list handling.
*/
#include "mailx.h"
/*
* Bit values for colon modifiers.
*/
/*
* The following table describes the letters which can follow
* the colon and gives the corresponding modifier bit.
*/
struct coltab {
} coltab[] = {
0, 0, 0, 0
};
/*
* See if the passed name sent the passed message number.
*/
int
{
char* s;
return 0;
return !strcasecmp(name, s);
}
/*
* See if the passed name received the passed message number.
*/
static int
{
register char* s;
register char* t;
register char* b;
int i;
return 0;
for (i = 0; i < elementsof(fields); i++)
s = name;
b = t;
while (*t) {
if (!*s)
return 1;
t = ++b;
s = name;
}
}
if (!*s)
return 1;
}
return 0;
}
/*
* See if the given string matches inside the header field of the
* given message. For the purpose of the scan, we ignore case differences.
* If it does, return true. The string search argument is assumed to
* have the form "/search-string." If it is of the form "/," we use the
* previous search string.
*/
static int
{
register char* s;
register char* t;
register char* b;
if (!*str)
else
for (s += 3; isspace(*s); s++);
}
*s++ = 0;
s[-1] = ':';
while (isspace(*s))
s++;
str = s;
}
else {
s = str;
}
if (!t)
return 0;
b = t;
while (*t) {
if (!*s)
return 1;
t = ++b;
s = str;
}
}
return !*s;
}
/*
* See if the passed name sent the passed message number.
*/
static int
{
register char* t;
do {
if (!*s)
return !isalnum(*t);
return 0;
}
/*
* Return the message number corresponding to the passed meta character.
*/
static int
{
register int c;
register int m;
c = meta;
switch (c) {
case '^':
/*
* First 'good' message left.
*/
note(0, "No applicable messages");
return -1;
case '$':
/*
* Last 'good message left.
*/
note(0, "No applicable messages");
return -1;
case '.':
/*
* Current message.
*/
note(0, "%d: inappropriate message", m);
return -1;
}
return m;
default:
note(0, "\"%c\": unknown metachar", c);
return -1;
}
}
/*
* Unscan the named token by pushing it onto the regret stack.
*/
static void
{
}
/*
* Reset all the scanner global variables.
*/
static void
scaninit(void)
{
}
/*
* Unmark the named message.
*/
static void
{
register int i;
i = mesg;
}
/*
* Turn the character(s) after a colon modifier into a bit value.
*/
static int
evalcol(char* s)
{
register int c;
register int neg;
if (neg = *s == '!')
s++;
if (!(c = *s))
}
return 0;
}
/*
* Mark the named message by setting its mark bit.
*/
static void
markone(register int i)
{
}
/*
* Mark all messages that the user wanted from the command
* line in the message structure. Return 0 on success, -1
* on error.
*/
static int
{
register char** np;
register int i;
char* bufp;
int beg;
int colmod;
int colresult;
int lone;
int mc;
int other;
int star;
int tok;
int valdot;
colmod = 0;
unmark(i);
mc = 0;
scaninit();
star = 0;
other = 0;
lone = 0;
beg = 0;
switch (tok) {
case TNUMBER:
if (star) {
note(0, "No numbers mixed with *");
return -1;
}
mc++;
other++;
if (beg) {
return -1;
markone(i);
beg = 0;
break;
}
return -1;
beg = 0;
}
break;
case TPLUS:
if (beg) {
note(0, "Non-numeric second argument");
return -1;
}
i = valdot;
do {
i++;
note(0, "Referencing beyond EOF");
return -1;
}
markone(i);
break;
case TDASH:
if (!beg) {
lone = 1;
i = valdot;
do {
i--;
if (i <= 0) {
note(0, "Referencing before 1");
return -1;
}
markone(i);
}
break;
case TSTRING:
if (beg) {
note(0, "Non-numeric second argument");
return -1;
}
other++;
if (!colresult) {
return -1;
}
}
else
break;
case TDOLLAR:
case TUP:
case TDOT:
return -1;
goto number;
case TSTAR:
if (other) {
note(0, "Can't mix \"*\" with anything");
return -1;
}
star++;
break;
case TERROR:
return -1;
}
i = tok;
bufp = "$";
}
}
*np = 0;
mc = 0;
if (star) {
markone(i + 1);
mc++;
}
if (!mc) {
note(0, "No applicable messages");
return -1;
}
return 0;
}
/*
* 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.
*/
markone(i);
/*
* If any names were given, go through and eliminate any
* messages whose senders were not requested.
*/
if (**np == '/') {
mc++;
break;
}
}
else {
if (matchsender(*np, i)) {
mc++;
break;
}
}
if (!mc)
unmark(i);
}
/*
* Make sure we got some decent messages.
*/
mc = 0;
mc++;
break;
}
if (!mc) {
printf("No applicable messages from {%s",
namelist[0]);
printf("}.\n");
return -1;
}
}
/*
* If any colon modifiers were given, go through and
* unmark any messages which do not satisfy the modifiers.
*/
if (colmod) {
unmark(i);
}
break;
printf("No messages satisfy");
printf("\n");
return -1;
}
}
return 0;
}
/*
* Convert the user string of message numbers and
* stuff the indices in state.msg.list.m_index.
*
* Returns the count of messages picked up or -1 on error.
*/
int
{
if (ip) {
return 0;
}
note(0, "No appropriate messages");
return -1;
}
if (*buf == '(')
return imap_msglist(buf);
}
return -1;
ip++;
}
}
/*
* Check the passed message number for legality and proper flags.
* If f is MDELETE, then either kind will do. Otherwise, the message
* has to be undeleted.
*/
int
{
return -1;
}
return -1;
}
return 0;
}
/*
* Add a single arg to the arg vector.
* 0 returned on success
*/
int
{
note(0, "Too many arguments; excess discarded");
return -1;
}
return 0;
}
/*
* Scan out the list of string arguments, shell style
* and append to the vector.
*/
void
{
register char* t;
char* e;
register int c;
register int quote;
int n;
char* pop;
pop = 0;
for (;;) {
while (isspace(*s))
s++;
if (!*s) {
if (s = pop) {
pop = 0;
continue;
}
break;
}
quote = 0;
t = buf;
for (;;) {
if (!(c = *s)) {
if (pop) {
s = pop;
pop = 0;
continue;
}
break;
}
s++;
if (!pop) {
c = *e;
*e = 0;
if (*++s == '<') {
mac[n] = 0;
s = mac;
}
else {
s = 0;
}
}
else {
s = 0;
}
}
else
s = varget(s);
*e++ = c;
if (s)
pop = e;
else
s = e;
continue;
}
else if (quote) {
if (c == quote) {
quote = 0;
continue;
}
if (c == '\\') {
c = chresc(s - 1, &e);
s = e;
}
}
else if (c == '"' || c == '\'') {
quote = c;
continue;
}
else if (isspace(c))
break;
}
else if (isspace(c)) {
if (!quote) {
continue;
c = ' ';
}
else if (c == '\n' && !*s || c == '\r' && *s == '\n' && !*(s + 1))
continue;
}
*t++ = c;
}
*t = 0;
break;
}
}
/*
* 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.
*/
struct lex {
char l_char;
char l_token;
} singles[] = {
'$', TDOLLAR,
'.', TDOT,
'^', TUP,
'*', TSTAR,
'-', TDASH,
'+', TPLUS,
'(', TOPEN,
')', TCLOSE,
0, 0
};
int
{
register char* cp;
register char* cp2;
register int c;
int quotec;
}
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) {
return TEOL;
}
/*
* If the leading character is a digit, scan
* the number and convert it on the fly.
* Return TNUMBER when done.
*/
if (isdigit(c)) {
while (isdigit(c)) {
*cp2++ = c;
c = *cp++;
}
*cp2 = 0;
return TNUMBER;
}
/*
* Check for single character tokens; return such
* if found.
*/
}
/*
* 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) {
if (c == quotec) {
cp++;
break;
}
break;
*cp2++ = c;
c = *cp++;
}
if (quotec && !c) {
return TERROR;
}
*cp2 = 0;
return TSTRING;
}
/*
* Find the first message whose flags & m == f and return
* its message number.
*/
int
first(int f, int m)
{
return 0;
return 0;
}