/*-
* 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. 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.
*/
#include <sys/cdefs.h>
#ifndef lint
__COPYRIGHT("@(#) Copyright (c) 1980, 1993\
The Regents of the University of California. All rights reserved.");
#endif /* not lint */
/*
* msgs - a user bulletin board program
*
* usage:
* msgs [fhlopqr] [[-]number] to read messages
* msgs -s to place messages
* msgs -c [-days] to clean up the bulletin board
*
* prompt commands are:
* y print message
* n flush message, go to next message
* q flush message, quit
* p print message, turn on 'pipe thru more' mode
* P print message, turn off 'pipe thru more' mode
* - reprint last message
* s[-][<num>] [<filename>] save message
* m[-][<num>] mail with message in temp mbox
* x exit without flushing this message
* <num> print message number <num>
*/
#define V7 /* will look for TERM in the environment */
#define OBJECT /* will object to messages without Subjects */
#define REJECT /* will reject messages without Subjects
(OBJECT must be defined also) */
/*#define UNBUFFERED */ /* use unbuffered output */
int
main(int argc, char *argv[])
{
bool newrc, already;
int rcfirst = 0; /* first message to print (from .rc) */
int rcback = 0; /* amount to back off of rcfirst */
int firstmsg, nextmsg, lastmsg = 0;
int blast = 0;
FILE *bounds;
struct passwd *pw;
lct = linecnt(newmsg);
if (lct)
printf("(%d%slines) ", lct, seensubj? " " : " more ");
if (hdrs) {
printf("\n-----\n");
fclose(newmsg);
continue;
}
/*
* Ask user for command
*/
if (totty)
ask(lct? MORE : (msg==lastmsg? NOMORE : NEXT));
else
inbuf[0] = 'y';
if (totty)
signal(SIGTSTP, SIG_DFL);
cmnd:
in = inbuf;
switch (*in) {
case 'x':
case 'X':
exit(0);
case 'q':
case 'Q':
quitit = YES;
printf("--Postponed--\n");
exit(0);
/* intentional fall-thru */
case 'n':
case 'N':
if (msg >= nextmsg) sep = "Flushed";
prevmsg = msg;
break;
case 'p':
case 'P':
use_pager = (*in++ == 'p');
/* intentional fallthru */
case '\n':
case 'y':
default:
if (*in == '-') {
msg = prevmsg-1;
sep = "replay";
break;
}
if (isdigit((unsigned char)*in)) {
msg = next(in, sizeof(inbuf) -
(in - inbuf));
sep = in;
break;
}
/*
* Is this a normal message?
*/
if (fgets(inbuf, sizeof inbuf, infile)) {
if (strncmp(inbuf, "From", 4)==0) {
/*
* expected form starts with From
*/
seenfrom = YES;
frompos = ftell(infile);
ptr = from;
in = nxtfld(inbuf);
if (*in) while (*in && *in > ' ') {
if (*in == ':' || *in == '@' || *in == '!')
local = NO;
*ptr++ = *in++;
/* what about sizeof from ? */
}
*ptr = '\0';
if (*(in = nxtfld(in)))
strncpy(date, in, sizeof date);
else {
date[0] = '\n';
date[1] = '\0';
}
}
else {
/*
* not the expected form
*/
fseek(infile, 0L, 0);
return;
}
}
else
/*
* empty file ?
*/
return;
/*
* look for Subject line until EOF or a blank line
*/
while (fgets(inbuf, sizeof inbuf, infile)
&& !(blankline = (inbuf[0] == '\n'))) {
/*
* extract Subject line
*/
if (!seensubj && strncmp(inbuf, "Subj", 4)==0) {
seensubj = YES;
frompos = ftell(infile);
strncpy(subj, nxtfld(inbuf), sizeof subj);
}
}
if (!blankline)
/*
* ran into EOF
*/
fseek(infile, frompos, 0);
if (!seensubj)
/*
* for possible use with Mail
*/
strncpy(subj, "(No Subject)\n", sizeof subj);
}
char *
nxtfld(char *s)
{
if (*s) while (*s && *s > ' ') s++; /* skip over this field */
if (*s) while (*s && *s <= ' ') s++; /* find start of next field */
return (s);
}