10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
50Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
60Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
70Sstevel@tonic-gate * with the License.
80Sstevel@tonic-gate *
90Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
100Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
110Sstevel@tonic-gate * See the License for the specific language governing permissions
120Sstevel@tonic-gate * and limitations under the License.
130Sstevel@tonic-gate *
140Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
150Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
160Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
170Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
180Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
190Sstevel@tonic-gate *
200Sstevel@tonic-gate * CDDL HEADER END
210Sstevel@tonic-gate */
220Sstevel@tonic-gate /*
230Sstevel@tonic-gate * Copyright 1995 Sun Microsystems, Inc. All rights reserved.
240Sstevel@tonic-gate * Use is subject to license terms.
250Sstevel@tonic-gate */
260Sstevel@tonic-gate
270Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
280Sstevel@tonic-gate /* All Rights Reserved */
290Sstevel@tonic-gate
300Sstevel@tonic-gate
310Sstevel@tonic-gate /*
320Sstevel@tonic-gate * University Copyright- Copyright (c) 1982, 1986, 1988
330Sstevel@tonic-gate * The Regents of the University of California
340Sstevel@tonic-gate * All Rights Reserved
350Sstevel@tonic-gate *
360Sstevel@tonic-gate * University Acknowledgment- Portions of this document are derived from
370Sstevel@tonic-gate * software developed by the University of California, Berkeley, and its
380Sstevel@tonic-gate * contributors.
390Sstevel@tonic-gate */
400Sstevel@tonic-gate
410Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
420Sstevel@tonic-gate
430Sstevel@tonic-gate #include "rcv.h"
440Sstevel@tonic-gate
450Sstevel@tonic-gate /*
460Sstevel@tonic-gate * mailx -- a modified version of a University of California at Berkeley
470Sstevel@tonic-gate * mail program
480Sstevel@tonic-gate *
490Sstevel@tonic-gate * Routines for processing and detecting headlines.
500Sstevel@tonic-gate */
510Sstevel@tonic-gate
520Sstevel@tonic-gate static char *copyin(char src[], char **space);
530Sstevel@tonic-gate static char *nextword(char wp[], char wbuf[]);
540Sstevel@tonic-gate
550Sstevel@tonic-gate /*
560Sstevel@tonic-gate * See if the passed line buffer is a mail header.
570Sstevel@tonic-gate * Return true if yes.
580Sstevel@tonic-gate */
590Sstevel@tonic-gate
600Sstevel@tonic-gate int
ishead(char linebuf[])610Sstevel@tonic-gate ishead(char linebuf[])
620Sstevel@tonic-gate {
630Sstevel@tonic-gate register char *cp;
640Sstevel@tonic-gate struct headline hl;
650Sstevel@tonic-gate char parbuf[BUFSIZ];
660Sstevel@tonic-gate
670Sstevel@tonic-gate cp = linebuf;
680Sstevel@tonic-gate if (strncmp("From ", cp, 5) != 0)
690Sstevel@tonic-gate return(0);
700Sstevel@tonic-gate parse(cp, &hl, parbuf);
710Sstevel@tonic-gate if (hl.l_from == NOSTR) {
720Sstevel@tonic-gate return(0);
730Sstevel@tonic-gate }
740Sstevel@tonic-gate return(1);
750Sstevel@tonic-gate }
760Sstevel@tonic-gate
770Sstevel@tonic-gate /*
780Sstevel@tonic-gate * Split a headline into its useful components.
790Sstevel@tonic-gate * Copy the line into dynamic string space, then set
800Sstevel@tonic-gate * pointers into the copied line in the passed headline
810Sstevel@tonic-gate * structure. Actually, it scans.
820Sstevel@tonic-gate */
830Sstevel@tonic-gate void
parse(char line[],struct headline * hl,char pbuf[])840Sstevel@tonic-gate parse(char line[], struct headline *hl, char pbuf[])
850Sstevel@tonic-gate {
860Sstevel@tonic-gate register char *cp, *dp;
870Sstevel@tonic-gate char *sp;
880Sstevel@tonic-gate char word[LINESIZE];
890Sstevel@tonic-gate
900Sstevel@tonic-gate hl->l_from = NOSTR;
910Sstevel@tonic-gate hl->l_date = NOSTR;
920Sstevel@tonic-gate cp = line;
930Sstevel@tonic-gate sp = pbuf;
940Sstevel@tonic-gate
950Sstevel@tonic-gate /*
960Sstevel@tonic-gate * Skip the first "word" of the line, which should be "From"
970Sstevel@tonic-gate * anyway.
980Sstevel@tonic-gate */
990Sstevel@tonic-gate
1000Sstevel@tonic-gate cp = nextword(cp, word);
1010Sstevel@tonic-gate dp = nextword(cp, word);
1020Sstevel@tonic-gate if (!equal(word, ""))
1030Sstevel@tonic-gate hl->l_from = copyin(word, &sp);
1040Sstevel@tonic-gate if (dp != NOSTR)
1050Sstevel@tonic-gate hl->l_date = copyin(dp, &sp);
1060Sstevel@tonic-gate }
1070Sstevel@tonic-gate
1080Sstevel@tonic-gate /*
1090Sstevel@tonic-gate * Copy the string on the left into the string on the right
1100Sstevel@tonic-gate * and bump the right (reference) string pointer by the length.
1110Sstevel@tonic-gate * Thus, dynamically allocate space in the right string, copying
1120Sstevel@tonic-gate * the left string into it.
1130Sstevel@tonic-gate */
1140Sstevel@tonic-gate
1150Sstevel@tonic-gate static char *
copyin(char src[],char ** space)1160Sstevel@tonic-gate copyin(char src[], char **space)
1170Sstevel@tonic-gate {
1180Sstevel@tonic-gate register char *cp, *top;
1190Sstevel@tonic-gate register int s;
1200Sstevel@tonic-gate
1210Sstevel@tonic-gate s = strlen(src);
1220Sstevel@tonic-gate cp = *space;
1230Sstevel@tonic-gate top = cp;
1240Sstevel@tonic-gate strcpy(cp, src);
1250Sstevel@tonic-gate cp += s + 1;
1260Sstevel@tonic-gate *space = cp;
1270Sstevel@tonic-gate return(top);
1280Sstevel@tonic-gate }
1290Sstevel@tonic-gate
1300Sstevel@tonic-gate /*
1310Sstevel@tonic-gate * Collect a liberal (space, tab delimited) word into the word buffer
1320Sstevel@tonic-gate * passed. Also, return a pointer to the next word following that,
1330Sstevel@tonic-gate * or NOSTR if none follow.
1340Sstevel@tonic-gate */
1350Sstevel@tonic-gate
1360Sstevel@tonic-gate static char *
nextword(char wp[],char wbuf[])1370Sstevel@tonic-gate nextword(char wp[], char wbuf[])
1380Sstevel@tonic-gate {
1390Sstevel@tonic-gate register char *cp, *cp2;
1400Sstevel@tonic-gate
1410Sstevel@tonic-gate if ((cp = wp) == NOSTR) {
1420Sstevel@tonic-gate copy("", wbuf);
1430Sstevel@tonic-gate return(NOSTR);
1440Sstevel@tonic-gate }
1450Sstevel@tonic-gate cp2 = wbuf;
1460Sstevel@tonic-gate while (!any(*cp, " \t") && *cp != '\0')
1470Sstevel@tonic-gate if (*cp == '"') {
1480Sstevel@tonic-gate *cp2++ = *cp++;
1490Sstevel@tonic-gate while (*cp != '\0' && *cp != '"')
1500Sstevel@tonic-gate *cp2++ = *cp++;
1510Sstevel@tonic-gate if (*cp == '"')
1520Sstevel@tonic-gate *cp2++ = *cp++;
1530Sstevel@tonic-gate } else
1540Sstevel@tonic-gate *cp2++ = *cp++;
1550Sstevel@tonic-gate *cp2 = '\0';
1560Sstevel@tonic-gate while (any(*cp, " \t"))
1570Sstevel@tonic-gate cp++;
1580Sstevel@tonic-gate if (*cp == '\0')
1590Sstevel@tonic-gate return(NOSTR);
1600Sstevel@tonic-gate return(cp);
1610Sstevel@tonic-gate }
1620Sstevel@tonic-gate
1630Sstevel@tonic-gate /*
1640Sstevel@tonic-gate * Copy str1 to str2, return pointer to null in str2.
1650Sstevel@tonic-gate */
1660Sstevel@tonic-gate
1670Sstevel@tonic-gate char *
copy(char * str1,char * str2)1680Sstevel@tonic-gate copy(char *str1, char *str2)
1690Sstevel@tonic-gate {
1700Sstevel@tonic-gate register char *s1, *s2;
1710Sstevel@tonic-gate
1720Sstevel@tonic-gate s1 = str1;
1730Sstevel@tonic-gate s2 = str2;
1740Sstevel@tonic-gate while (*s1)
1750Sstevel@tonic-gate *s2++ = *s1++;
1760Sstevel@tonic-gate *s2 = 0;
1770Sstevel@tonic-gate return(s2);
1780Sstevel@tonic-gate }
1790Sstevel@tonic-gate
1800Sstevel@tonic-gate /*
1810Sstevel@tonic-gate * Is ch any of the characters in str?
1820Sstevel@tonic-gate */
1830Sstevel@tonic-gate
1840Sstevel@tonic-gate int
any(int ch,char * str)1850Sstevel@tonic-gate any(int ch, char *str)
1860Sstevel@tonic-gate {
1870Sstevel@tonic-gate register char *f;
188*18Srobbin int c;
1890Sstevel@tonic-gate
1900Sstevel@tonic-gate f = str;
1910Sstevel@tonic-gate c = ch;
1920Sstevel@tonic-gate while (*f)
1930Sstevel@tonic-gate if (c == *f++)
1940Sstevel@tonic-gate return(1);
1950Sstevel@tonic-gate return(0);
1960Sstevel@tonic-gate }
197