1*0Sstevel@tonic-gate /* 2*0Sstevel@tonic-gate * CDDL HEADER START 3*0Sstevel@tonic-gate * 4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*0Sstevel@tonic-gate * with the License. 8*0Sstevel@tonic-gate * 9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*0Sstevel@tonic-gate * See the License for the specific language governing permissions 12*0Sstevel@tonic-gate * and limitations under the License. 13*0Sstevel@tonic-gate * 14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*0Sstevel@tonic-gate * 20*0Sstevel@tonic-gate * CDDL HEADER END 21*0Sstevel@tonic-gate */ 22*0Sstevel@tonic-gate /* 23*0Sstevel@tonic-gate * Copyright 1995 Sun Microsystems, Inc. All rights reserved. 24*0Sstevel@tonic-gate * Use is subject to license terms. 25*0Sstevel@tonic-gate */ 26*0Sstevel@tonic-gate 27*0Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 28*0Sstevel@tonic-gate /* All Rights Reserved */ 29*0Sstevel@tonic-gate 30*0Sstevel@tonic-gate 31*0Sstevel@tonic-gate /* 32*0Sstevel@tonic-gate * University Copyright- Copyright (c) 1982, 1986, 1988 33*0Sstevel@tonic-gate * The Regents of the University of California 34*0Sstevel@tonic-gate * All Rights Reserved 35*0Sstevel@tonic-gate * 36*0Sstevel@tonic-gate * University Acknowledgment- Portions of this document are derived from 37*0Sstevel@tonic-gate * software developed by the University of California, Berkeley, and its 38*0Sstevel@tonic-gate * contributors. 39*0Sstevel@tonic-gate */ 40*0Sstevel@tonic-gate 41*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 42*0Sstevel@tonic-gate 43*0Sstevel@tonic-gate #include "rcv.h" 44*0Sstevel@tonic-gate 45*0Sstevel@tonic-gate /* 46*0Sstevel@tonic-gate * mailx -- a modified version of a University of California at Berkeley 47*0Sstevel@tonic-gate * mail program 48*0Sstevel@tonic-gate * 49*0Sstevel@tonic-gate * Routines for processing and detecting headlines. 50*0Sstevel@tonic-gate */ 51*0Sstevel@tonic-gate 52*0Sstevel@tonic-gate static char *copyin(char src[], char **space); 53*0Sstevel@tonic-gate static char *nextword(char wp[], char wbuf[]); 54*0Sstevel@tonic-gate 55*0Sstevel@tonic-gate /* 56*0Sstevel@tonic-gate * See if the passed line buffer is a mail header. 57*0Sstevel@tonic-gate * Return true if yes. 58*0Sstevel@tonic-gate */ 59*0Sstevel@tonic-gate 60*0Sstevel@tonic-gate int 61*0Sstevel@tonic-gate ishead(char linebuf[]) 62*0Sstevel@tonic-gate { 63*0Sstevel@tonic-gate register char *cp; 64*0Sstevel@tonic-gate struct headline hl; 65*0Sstevel@tonic-gate char parbuf[BUFSIZ]; 66*0Sstevel@tonic-gate 67*0Sstevel@tonic-gate cp = linebuf; 68*0Sstevel@tonic-gate if (strncmp("From ", cp, 5) != 0) 69*0Sstevel@tonic-gate return(0); 70*0Sstevel@tonic-gate parse(cp, &hl, parbuf); 71*0Sstevel@tonic-gate if (hl.l_from == NOSTR) { 72*0Sstevel@tonic-gate return(0); 73*0Sstevel@tonic-gate } 74*0Sstevel@tonic-gate return(1); 75*0Sstevel@tonic-gate } 76*0Sstevel@tonic-gate 77*0Sstevel@tonic-gate /* 78*0Sstevel@tonic-gate * Split a headline into its useful components. 79*0Sstevel@tonic-gate * Copy the line into dynamic string space, then set 80*0Sstevel@tonic-gate * pointers into the copied line in the passed headline 81*0Sstevel@tonic-gate * structure. Actually, it scans. 82*0Sstevel@tonic-gate */ 83*0Sstevel@tonic-gate void 84*0Sstevel@tonic-gate parse(char line[], struct headline *hl, char pbuf[]) 85*0Sstevel@tonic-gate { 86*0Sstevel@tonic-gate register char *cp, *dp; 87*0Sstevel@tonic-gate char *sp; 88*0Sstevel@tonic-gate char word[LINESIZE]; 89*0Sstevel@tonic-gate 90*0Sstevel@tonic-gate hl->l_from = NOSTR; 91*0Sstevel@tonic-gate hl->l_date = NOSTR; 92*0Sstevel@tonic-gate cp = line; 93*0Sstevel@tonic-gate sp = pbuf; 94*0Sstevel@tonic-gate 95*0Sstevel@tonic-gate /* 96*0Sstevel@tonic-gate * Skip the first "word" of the line, which should be "From" 97*0Sstevel@tonic-gate * anyway. 98*0Sstevel@tonic-gate */ 99*0Sstevel@tonic-gate 100*0Sstevel@tonic-gate cp = nextword(cp, word); 101*0Sstevel@tonic-gate dp = nextword(cp, word); 102*0Sstevel@tonic-gate if (!equal(word, "")) 103*0Sstevel@tonic-gate hl->l_from = copyin(word, &sp); 104*0Sstevel@tonic-gate if (dp != NOSTR) 105*0Sstevel@tonic-gate hl->l_date = copyin(dp, &sp); 106*0Sstevel@tonic-gate } 107*0Sstevel@tonic-gate 108*0Sstevel@tonic-gate /* 109*0Sstevel@tonic-gate * Copy the string on the left into the string on the right 110*0Sstevel@tonic-gate * and bump the right (reference) string pointer by the length. 111*0Sstevel@tonic-gate * Thus, dynamically allocate space in the right string, copying 112*0Sstevel@tonic-gate * the left string into it. 113*0Sstevel@tonic-gate */ 114*0Sstevel@tonic-gate 115*0Sstevel@tonic-gate static char * 116*0Sstevel@tonic-gate copyin(char src[], char **space) 117*0Sstevel@tonic-gate { 118*0Sstevel@tonic-gate register char *cp, *top; 119*0Sstevel@tonic-gate register int s; 120*0Sstevel@tonic-gate 121*0Sstevel@tonic-gate s = strlen(src); 122*0Sstevel@tonic-gate cp = *space; 123*0Sstevel@tonic-gate top = cp; 124*0Sstevel@tonic-gate strcpy(cp, src); 125*0Sstevel@tonic-gate cp += s + 1; 126*0Sstevel@tonic-gate *space = cp; 127*0Sstevel@tonic-gate return(top); 128*0Sstevel@tonic-gate } 129*0Sstevel@tonic-gate 130*0Sstevel@tonic-gate /* 131*0Sstevel@tonic-gate * Collect a liberal (space, tab delimited) word into the word buffer 132*0Sstevel@tonic-gate * passed. Also, return a pointer to the next word following that, 133*0Sstevel@tonic-gate * or NOSTR if none follow. 134*0Sstevel@tonic-gate */ 135*0Sstevel@tonic-gate 136*0Sstevel@tonic-gate static char * 137*0Sstevel@tonic-gate nextword(char wp[], char wbuf[]) 138*0Sstevel@tonic-gate { 139*0Sstevel@tonic-gate register char *cp, *cp2; 140*0Sstevel@tonic-gate 141*0Sstevel@tonic-gate if ((cp = wp) == NOSTR) { 142*0Sstevel@tonic-gate copy("", wbuf); 143*0Sstevel@tonic-gate return(NOSTR); 144*0Sstevel@tonic-gate } 145*0Sstevel@tonic-gate cp2 = wbuf; 146*0Sstevel@tonic-gate while (!any(*cp, " \t") && *cp != '\0') 147*0Sstevel@tonic-gate if (*cp == '"') { 148*0Sstevel@tonic-gate *cp2++ = *cp++; 149*0Sstevel@tonic-gate while (*cp != '\0' && *cp != '"') 150*0Sstevel@tonic-gate *cp2++ = *cp++; 151*0Sstevel@tonic-gate if (*cp == '"') 152*0Sstevel@tonic-gate *cp2++ = *cp++; 153*0Sstevel@tonic-gate } else 154*0Sstevel@tonic-gate *cp2++ = *cp++; 155*0Sstevel@tonic-gate *cp2 = '\0'; 156*0Sstevel@tonic-gate while (any(*cp, " \t")) 157*0Sstevel@tonic-gate cp++; 158*0Sstevel@tonic-gate if (*cp == '\0') 159*0Sstevel@tonic-gate return(NOSTR); 160*0Sstevel@tonic-gate return(cp); 161*0Sstevel@tonic-gate } 162*0Sstevel@tonic-gate 163*0Sstevel@tonic-gate /* 164*0Sstevel@tonic-gate * Copy str1 to str2, return pointer to null in str2. 165*0Sstevel@tonic-gate */ 166*0Sstevel@tonic-gate 167*0Sstevel@tonic-gate char * 168*0Sstevel@tonic-gate copy(char *str1, char *str2) 169*0Sstevel@tonic-gate { 170*0Sstevel@tonic-gate register char *s1, *s2; 171*0Sstevel@tonic-gate 172*0Sstevel@tonic-gate s1 = str1; 173*0Sstevel@tonic-gate s2 = str2; 174*0Sstevel@tonic-gate while (*s1) 175*0Sstevel@tonic-gate *s2++ = *s1++; 176*0Sstevel@tonic-gate *s2 = 0; 177*0Sstevel@tonic-gate return(s2); 178*0Sstevel@tonic-gate } 179*0Sstevel@tonic-gate 180*0Sstevel@tonic-gate /* 181*0Sstevel@tonic-gate * Is ch any of the characters in str? 182*0Sstevel@tonic-gate */ 183*0Sstevel@tonic-gate 184*0Sstevel@tonic-gate int 185*0Sstevel@tonic-gate any(int ch, char *str) 186*0Sstevel@tonic-gate { 187*0Sstevel@tonic-gate register char *f; 188*0Sstevel@tonic-gate register c; 189*0Sstevel@tonic-gate 190*0Sstevel@tonic-gate f = str; 191*0Sstevel@tonic-gate c = ch; 192*0Sstevel@tonic-gate while (*f) 193*0Sstevel@tonic-gate if (c == *f++) 194*0Sstevel@tonic-gate return(1); 195*0Sstevel@tonic-gate return(0); 196*0Sstevel@tonic-gate } 197