122706Sdist /* 222706Sdist ** Sendmail 322706Sdist ** Copyright (c) 1983 Eric P. Allman 422706Sdist ** Berkeley, California 522706Sdist ** 622706Sdist ** Copyright (c) 1983 Regents of the University of California. 722706Sdist ** All rights reserved. The Berkeley software License Agreement 822706Sdist ** specifies the terms and conditions for redistribution. 922706Sdist */ 1022706Sdist 1122706Sdist #ifndef lint 12*33725Sbostic static char SccsId[] = "@(#)headers.c 5.8 (Berkeley) 03/13/88"; 1322706Sdist #endif not lint 1422706Sdist 154091Seric # include <errno.h> 164091Seric # include "sendmail.h" 174091Seric 184091Seric /* 194091Seric ** CHOMPHEADER -- process and save a header line. 204091Seric ** 214091Seric ** Called by collect and by readcf to deal with header lines. 224091Seric ** 234091Seric ** Parameters: 244091Seric ** line -- header as a text line. 254091Seric ** def -- if set, this is a default value. 264091Seric ** 274091Seric ** Returns: 284091Seric ** flags for this header. 294091Seric ** 304091Seric ** Side Effects: 314091Seric ** The header is saved on the header list. 324319Seric ** Contents of 'line' are destroyed. 334091Seric */ 344091Seric 354091Seric chompheader(line, def) 364091Seric char *line; 374091Seric bool def; 384091Seric { 394091Seric register char *p; 404091Seric register HDR *h; 414091Seric HDR **hp; 424091Seric char *fname; 434091Seric char *fvalue; 444091Seric struct hdrinfo *hi; 459059Seric bool cond = FALSE; 4610689Seric BITMAP mopts; 477890Seric extern char *crackaddr(); 484091Seric 497677Seric # ifdef DEBUG 507677Seric if (tTd(31, 6)) 517677Seric printf("chompheader: %s\n", line); 527677Seric # endif DEBUG 537677Seric 544627Seric /* strip off options */ 5510689Seric clrbitmap(mopts); 564627Seric p = line; 574627Seric if (*p == '?') 584627Seric { 594627Seric /* have some */ 604627Seric register char *q = index(p + 1, *p); 614627Seric 624627Seric if (q != NULL) 634627Seric { 644627Seric *q++ = '\0'; 6510689Seric while (*++p != '\0') 6610689Seric setbitn(*p, mopts); 674627Seric p = q; 684627Seric } 694627Seric else 704627Seric syserr("chompheader: syntax error, line \"%s\"", line); 719059Seric cond = TRUE; 724627Seric } 734627Seric 744091Seric /* find canonical name */ 754627Seric fname = p; 764627Seric p = index(p, ':'); 7710118Seric if (p == NULL) 7810118Seric { 7910118Seric syserr("chompheader: syntax error, line \"%s\"", line); 8010118Seric return (0); 8110118Seric } 824091Seric fvalue = &p[1]; 834091Seric while (isspace(*--p)) 844091Seric continue; 854091Seric *++p = '\0'; 864091Seric makelower(fname); 874091Seric 884091Seric /* strip field value on front */ 894091Seric if (*fvalue == ' ') 904091Seric fvalue++; 914091Seric 924091Seric /* see if it is a known type */ 934091Seric for (hi = HdrInfo; hi->hi_field != NULL; hi++) 944091Seric { 954091Seric if (strcmp(hi->hi_field, fname) == 0) 964091Seric break; 974091Seric } 984091Seric 9911414Seric /* see if this is a resent message */ 10011930Seric if (!def && bitset(H_RESENT, hi->hi_flags)) 10111414Seric CurEnv->e_flags |= EF_RESENT; 10211414Seric 1034091Seric /* if this means "end of header" quit now */ 1044091Seric if (bitset(H_EOH, hi->hi_flags)) 1054091Seric return (hi->hi_flags); 1064091Seric 10711414Seric /* drop explicit From: if same as what we would generate -- for MH */ 10814784Seric p = "resent-from"; 10914784Seric if (!bitset(EF_RESENT, CurEnv->e_flags)) 11014784Seric p += 7; 11114784Seric if (!def && !QueueRun && strcmp(fname, p) == 0) 11211414Seric { 11324941Seric if (CurEnv->e_from.q_paddr != NULL && 11424941Seric strcmp(fvalue, CurEnv->e_from.q_paddr) == 0) 11511414Seric return (hi->hi_flags); 11611414Seric } 11711414Seric 11814784Seric /* delete default value for this header */ 11914784Seric for (hp = &CurEnv->e_header; (h = *hp) != NULL; hp = &h->h_link) 12014784Seric { 12114784Seric if (strcmp(fname, h->h_field) == 0 && 12214784Seric bitset(H_DEFAULT, h->h_flags) && 12314784Seric !bitset(H_FORCE, h->h_flags)) 12414784Seric h->h_value = NULL; 12514784Seric } 12614784Seric 12713012Seric /* create a new node */ 12813012Seric h = (HDR *) xalloc(sizeof *h); 12913012Seric h->h_field = newstr(fname); 13013012Seric h->h_value = NULL; 13113012Seric h->h_link = NULL; 13223117Seric bcopy((char *) mopts, (char *) h->h_mflags, sizeof mopts); 13313012Seric *hp = h; 1348066Seric h->h_flags = hi->hi_flags; 1354091Seric if (def) 1364091Seric h->h_flags |= H_DEFAULT; 1379059Seric if (cond) 1389059Seric h->h_flags |= H_CHECK; 1394091Seric if (h->h_value != NULL) 1409351Seric free((char *) h->h_value); 1418066Seric h->h_value = newstr(fvalue); 1424091Seric 1435937Seric /* hack to see if this is a new format message */ 1448095Seric if (!def && bitset(H_RCPT|H_FROM, h->h_flags) && 1455937Seric (index(fvalue, ',') != NULL || index(fvalue, '(') != NULL || 1468089Seric index(fvalue, '<') != NULL || index(fvalue, ';') != NULL)) 1478089Seric { 1489342Seric CurEnv->e_flags &= ~EF_OLDSTYLE; 1498089Seric } 1505937Seric 1514091Seric return (h->h_flags); 1524091Seric } 1534091Seric /* 1546980Seric ** ADDHEADER -- add a header entry to the end of the queue. 1556980Seric ** 1566980Seric ** This bypasses the special checking of chompheader. 1576980Seric ** 1586980Seric ** Parameters: 1596980Seric ** field -- the name of the header field. 1606980Seric ** value -- the value of the field. It must be lower-cased. 1616980Seric ** e -- the envelope to add them to. 1626980Seric ** 1636980Seric ** Returns: 1646980Seric ** none. 1656980Seric ** 1666980Seric ** Side Effects: 1676980Seric ** adds the field on the list of headers for this envelope. 1686980Seric */ 1696980Seric 1706980Seric addheader(field, value, e) 1716980Seric char *field; 1726980Seric char *value; 1736980Seric ENVELOPE *e; 1746980Seric { 1756980Seric register HDR *h; 1766980Seric register struct hdrinfo *hi; 1776980Seric HDR **hp; 1786980Seric 1796980Seric /* find info struct */ 1806980Seric for (hi = HdrInfo; hi->hi_field != NULL; hi++) 1816980Seric { 1826980Seric if (strcmp(field, hi->hi_field) == 0) 1836980Seric break; 1846980Seric } 1856980Seric 1866980Seric /* find current place in list -- keep back pointer? */ 1876980Seric for (hp = &e->e_header; (h = *hp) != NULL; hp = &h->h_link) 1886980Seric { 1896980Seric if (strcmp(field, h->h_field) == 0) 1906980Seric break; 1916980Seric } 1926980Seric 1936980Seric /* allocate space for new header */ 1946980Seric h = (HDR *) xalloc(sizeof *h); 1956980Seric h->h_field = field; 1966980Seric h->h_value = newstr(value); 1977368Seric h->h_link = *hp; 1986980Seric h->h_flags = hi->hi_flags | H_DEFAULT; 19910689Seric clrbitmap(h->h_mflags); 2006980Seric *hp = h; 2016980Seric } 2026980Seric /* 2034091Seric ** HVALUE -- return value of a header. 2044091Seric ** 2054091Seric ** Only "real" fields (i.e., ones that have not been supplied 2064091Seric ** as a default) are used. 2074091Seric ** 2084091Seric ** Parameters: 2094091Seric ** field -- the field name. 2104091Seric ** 2114091Seric ** Returns: 2124091Seric ** pointer to the value part. 2134091Seric ** NULL if not found. 2144091Seric ** 2154091Seric ** Side Effects: 2169382Seric ** none. 2174091Seric */ 2184091Seric 2194091Seric char * 2204091Seric hvalue(field) 2214091Seric char *field; 2224091Seric { 2234091Seric register HDR *h; 2244091Seric 2256908Seric for (h = CurEnv->e_header; h != NULL; h = h->h_link) 2264091Seric { 2274091Seric if (!bitset(H_DEFAULT, h->h_flags) && strcmp(h->h_field, field) == 0) 2284091Seric return (h->h_value); 2294091Seric } 2304091Seric return (NULL); 2314091Seric } 2324091Seric /* 2334091Seric ** ISHEADER -- predicate telling if argument is a header. 2344091Seric ** 2354319Seric ** A line is a header if it has a single word followed by 2364319Seric ** optional white space followed by a colon. 2374319Seric ** 2384091Seric ** Parameters: 2394091Seric ** s -- string to check for possible headerness. 2404091Seric ** 2414091Seric ** Returns: 2424091Seric ** TRUE if s is a header. 2434091Seric ** FALSE otherwise. 2444091Seric ** 2454091Seric ** Side Effects: 2464091Seric ** none. 2474091Seric */ 2484091Seric 2494091Seric bool 2504091Seric isheader(s) 2514091Seric register char *s; 2524091Seric { 2539382Seric while (*s > ' ' && *s != ':' && *s != '\0') 2544091Seric s++; 2559382Seric 2569382Seric /* following technically violates RFC822 */ 2574091Seric while (isspace(*s)) 2584091Seric s++; 2599382Seric 2604091Seric return (*s == ':'); 2614091Seric } 2625919Seric /* 2637783Seric ** EATHEADER -- run through the stored header and extract info. 2647783Seric ** 2657783Seric ** Parameters: 2669382Seric ** e -- the envelope to process. 2677783Seric ** 2687783Seric ** Returns: 2697783Seric ** none. 2707783Seric ** 2717783Seric ** Side Effects: 2727783Seric ** Sets a bunch of global variables from information 2739382Seric ** in the collected header. 2749382Seric ** Aborts the message if the hop count is exceeded. 2757783Seric */ 2767783Seric 2779382Seric eatheader(e) 2789382Seric register ENVELOPE *e; 2797783Seric { 2807783Seric register HDR *h; 2817783Seric register char *p; 2829382Seric int hopcnt = 0; 2837783Seric 2849382Seric #ifdef DEBUG 2859382Seric if (tTd(32, 1)) 2869382Seric printf("----- collected header -----\n"); 2879382Seric #endif DEBUG 2889382Seric for (h = e->e_header; h != NULL; h = h->h_link) 2897783Seric { 2909382Seric #ifdef DEBUG 2917783Seric extern char *capitalize(); 2927783Seric 2939382Seric if (tTd(32, 1)) 2947783Seric printf("%s: %s\n", capitalize(h->h_field), h->h_value); 2959382Seric #endif DEBUG 29611414Seric /* count the number of times it has been processed */ 2979382Seric if (bitset(H_TRACE, h->h_flags)) 2989382Seric hopcnt++; 29911414Seric 30011414Seric /* send to this person if we so desire */ 30111414Seric if (GrabTo && bitset(H_RCPT, h->h_flags) && 30211414Seric !bitset(H_DEFAULT, h->h_flags) && 30311414Seric (!bitset(EF_RESENT, CurEnv->e_flags) || bitset(H_RESENT, h->h_flags))) 30411414Seric { 30511414Seric sendtolist(h->h_value, (ADDRESS *) NULL, &CurEnv->e_sendqueue); 30611414Seric } 30711414Seric 30811414Seric /* log the message-id */ 30911290Seric #ifdef LOG 31013103Seric if (!QueueRun && LogLevel > 8 && h->h_value != NULL && 31111299Seric strcmp(h->h_field, "message-id") == 0) 31211290Seric { 31311290Seric char buf[MAXNAME]; 31411290Seric 31511290Seric p = h->h_value; 31611290Seric if (bitset(H_DEFAULT, h->h_flags)) 31711290Seric { 31811290Seric expand(p, buf, &buf[sizeof buf], e); 31911290Seric p = buf; 32011290Seric } 32111290Seric syslog(LOG_INFO, "%s: message-id=%s", e->e_id, p); 32211290Seric } 32311290Seric #endif LOG 3249382Seric } 3259382Seric #ifdef DEBUG 3269382Seric if (tTd(32, 1)) 3277783Seric printf("----------------------------\n"); 3289382Seric #endif DEBUG 3297783Seric 3309382Seric /* store hop count */ 3319382Seric if (hopcnt > e->e_hopcount) 3329382Seric e->e_hopcount = hopcnt; 3339382Seric 3347783Seric /* message priority */ 3359382Seric p = hvalue("precedence"); 3369382Seric if (p != NULL) 3379382Seric e->e_class = priencode(p); 3387783Seric if (!QueueRun) 33925013Seric e->e_msgpriority = e->e_msgsize 34024981Seric - e->e_class * WkClassFact 34124981Seric + e->e_nrcpts * WkRecipFact; 3427783Seric 3438066Seric /* return receipt to */ 3448066Seric p = hvalue("return-receipt-to"); 3457783Seric if (p != NULL) 3469382Seric e->e_receiptto = p; 3477783Seric 3488253Seric /* errors to */ 3498253Seric p = hvalue("errors-to"); 3508253Seric if (p != NULL) 3519620Seric sendtolist(p, (ADDRESS *) NULL, &e->e_errorqueue); 3528253Seric 3537783Seric /* from person */ 3549285Seric if (OpMode == MD_ARPAFTP) 3558066Seric { 3568066Seric register struct hdrinfo *hi = HdrInfo; 3577783Seric 3588066Seric for (p = NULL; p == NULL && hi->hi_field != NULL; hi++) 3598066Seric { 3608066Seric if (bitset(H_FROM, hi->hi_flags)) 3618066Seric p = hvalue(hi->hi_field); 3628066Seric } 3638066Seric if (p != NULL) 3649382Seric setsender(p); 3658066Seric } 3668066Seric 3677783Seric /* full name of from person */ 3687783Seric p = hvalue("full-name"); 3697783Seric if (p != NULL) 3709382Seric define('x', p, e); 3717783Seric 3727783Seric /* date message originated */ 3737783Seric p = hvalue("posted-date"); 3747783Seric if (p == NULL) 3757783Seric p = hvalue("date"); 3767783Seric if (p != NULL) 3777783Seric { 3789382Seric define('a', p, e); 3797783Seric /* we don't have a good way to do canonical conversion .... 3809382Seric define('d', newstr(arpatounix(p)), e); 3817783Seric .... so we will ignore the problem for the time being */ 3827783Seric } 38311290Seric 38411290Seric /* 38511290Seric ** Log collection information. 38611290Seric */ 38711290Seric 38811290Seric # ifdef LOG 38911299Seric if (!QueueRun && LogLevel > 1) 39011290Seric { 39111290Seric syslog(LOG_INFO, "%s: from=%s, size=%ld, class=%d\n", 39211290Seric CurEnv->e_id, CurEnv->e_from.q_paddr, CurEnv->e_msgsize, 39311290Seric CurEnv->e_class); 39411290Seric } 39511290Seric # endif LOG 3967783Seric } 3977783Seric /* 3987783Seric ** PRIENCODE -- encode external priority names into internal values. 3997783Seric ** 4007783Seric ** Parameters: 4017783Seric ** p -- priority in ascii. 4027783Seric ** 4037783Seric ** Returns: 4047783Seric ** priority as a numeric level. 4057783Seric ** 4067783Seric ** Side Effects: 4077783Seric ** none. 4087783Seric */ 4097783Seric 4107783Seric priencode(p) 4117783Seric char *p; 4127783Seric { 4138253Seric register int i; 4147783Seric 4158253Seric for (i = 0; i < NumPriorities; i++) 4167783Seric { 417*33725Sbostic if (!strcasecmp(p, Priorities[i].pri_name)) 4188253Seric return (Priorities[i].pri_val); 4197783Seric } 4208253Seric 4218253Seric /* unknown priority */ 4228253Seric return (0); 4237783Seric } 4247783Seric /* 4257890Seric ** CRACKADDR -- parse an address and turn it into a macro 4267783Seric ** 4277783Seric ** This doesn't actually parse the address -- it just extracts 4287783Seric ** it and replaces it with "$g". The parse is totally ad hoc 4297783Seric ** and isn't even guaranteed to leave something syntactically 4307783Seric ** identical to what it started with. However, it does leave 4317783Seric ** something semantically identical. 4327783Seric ** 4337783Seric ** The process is kind of strange. There are a number of 4347783Seric ** interesting cases: 4357783Seric ** 1. comment <address> comment ==> comment <$g> comment 4367783Seric ** 2. address ==> address 4377783Seric ** 3. address (comment) ==> $g (comment) 4387783Seric ** 4. (comment) address ==> (comment) $g 4397783Seric ** And then there are the hard cases.... 4407783Seric ** 5. add (comment) ress ==> $g (comment) 4417783Seric ** 6. comment <address (comment)> ==> comment <$g (comment)> 4427783Seric ** 7. .... etc .... 4437783Seric ** 4447783Seric ** Parameters: 4457890Seric ** addr -- the address to be cracked. 4467783Seric ** 4477783Seric ** Returns: 4487783Seric ** a pointer to the new version. 4497783Seric ** 4507783Seric ** Side Effects: 4517890Seric ** none. 4527783Seric ** 4537783Seric ** Warning: 4547783Seric ** The return value is saved in local storage and should 4557783Seric ** be copied if it is to be reused. 4567783Seric */ 4577783Seric 4587783Seric char * 4597890Seric crackaddr(addr) 4607890Seric register char *addr; 4617783Seric { 4627783Seric register char *p; 4637783Seric register int i; 4647783Seric static char buf[MAXNAME]; 4657783Seric char *rhs; 4667783Seric bool gotaddr; 4677783Seric register char *bp; 4687783Seric 4697783Seric # ifdef DEBUG 4707783Seric if (tTd(33, 1)) 4717890Seric printf("crackaddr(%s)\n", addr); 4727783Seric # endif DEBUG 4737783Seric 47423099Seric (void) strcpy(buf, ""); 4757783Seric rhs = NULL; 4767783Seric 4778082Seric /* strip leading spaces */ 4788082Seric while (*addr != '\0' && isspace(*addr)) 4798082Seric addr++; 4808082Seric 4817783Seric /* 4827783Seric ** See if we have anything in angle brackets. If so, that is 4837783Seric ** the address part, and the rest is the comment. 4847783Seric */ 4857783Seric 4867890Seric p = index(addr, '<'); 4877783Seric if (p != NULL) 4887783Seric { 4897890Seric /* copy the beginning of the addr field to the buffer */ 4907783Seric *p = '\0'; 49123099Seric (void) strcpy(buf, addr); 49223099Seric (void) strcat(buf, "<"); 4938082Seric *p++ = '<'; 4947783Seric 4958082Seric /* skip spaces */ 4968082Seric while (isspace(*p)) 4978082Seric p++; 4988082Seric 4997783Seric /* find the matching right angle bracket */ 5008082Seric addr = p; 5017783Seric for (i = 0; *p != '\0'; p++) 5027783Seric { 5037783Seric switch (*p) 5047783Seric { 5057783Seric case '<': 5067783Seric i++; 5077783Seric break; 5087783Seric 5097783Seric case '>': 5107783Seric i--; 5117783Seric break; 5127783Seric } 5137783Seric if (i < 0) 5147783Seric break; 5157783Seric } 5167783Seric 5177783Seric /* p now points to the closing quote (or a null byte) */ 5187783Seric if (*p != '\0') 5197783Seric { 5207783Seric /* make rhs point to the extra stuff at the end */ 5217783Seric rhs = p; 5227783Seric *p++ = '\0'; 5237783Seric } 5247783Seric } 5257783Seric 5267783Seric /* 5277944Seric ** Now parse the real address part. "addr" points to the (null 5287783Seric ** terminated) version of what we are inerested in; rhs points 5297783Seric ** to the extra stuff at the end of the line, if any. 5307783Seric */ 5317783Seric 5327890Seric p = addr; 5337783Seric 5347783Seric /* now strip out comments */ 5357783Seric bp = &buf[strlen(buf)]; 5367783Seric gotaddr = FALSE; 5377783Seric for (; *p != '\0'; p++) 5387783Seric { 5397783Seric if (*p == '(') 5407783Seric { 5417783Seric /* copy to matching close paren */ 5427783Seric *bp++ = *p++; 5437783Seric for (i = 0; *p != '\0'; p++) 5447783Seric { 5457783Seric *bp++ = *p; 5467783Seric switch (*p) 5477783Seric { 5487783Seric case '(': 5497783Seric i++; 5507783Seric break; 5517783Seric 5527783Seric case ')': 5537783Seric i--; 5547783Seric break; 5557783Seric } 5567783Seric if (i < 0) 5577783Seric break; 5587783Seric } 5597783Seric continue; 5607783Seric } 5617783Seric 5627783Seric /* 5637783Seric ** If this is the first "real" character we have seen, 5647783Seric ** then we put the "$g" in the buffer now. 5657783Seric */ 5667783Seric 5677783Seric if (isspace(*p)) 5687783Seric *bp++ = *p; 5697783Seric else if (!gotaddr) 5707783Seric { 57123099Seric (void) strcpy(bp, "\001g"); 5727783Seric bp += 2; 5737783Seric gotaddr = TRUE; 5747783Seric } 5757783Seric } 5767783Seric 5777944Seric /* hack, hack.... strip trailing blanks */ 5787944Seric do 5797944Seric { 5807944Seric *bp-- = '\0'; 5817944Seric } while (isspace(*bp)); 5827944Seric bp++; 5837783Seric 5847944Seric /* put any right hand side back on */ 5857783Seric if (rhs != NULL) 5867783Seric { 5877783Seric *rhs = '>'; 58823099Seric (void) strcpy(bp, rhs); 5897783Seric } 5907783Seric 5917783Seric # ifdef DEBUG 5927783Seric if (tTd(33, 1)) 5937944Seric printf("crackaddr=>`%s'\n", buf); 5947783Seric # endif DEBUG 5957783Seric 5967783Seric return (buf); 5977783Seric } 5989382Seric /* 5999382Seric ** PUTHEADER -- put the header part of a message from the in-core copy 6009382Seric ** 6019382Seric ** Parameters: 6029382Seric ** fp -- file to put it on. 6039382Seric ** m -- mailer to use. 6049382Seric ** e -- envelope to use. 6059382Seric ** 6069382Seric ** Returns: 6079382Seric ** none. 6089382Seric ** 6099382Seric ** Side Effects: 6109382Seric ** none. 6119382Seric */ 6129382Seric 61310176Seric putheader(fp, m, e) 6149382Seric register FILE *fp; 6159382Seric register MAILER *m; 6169382Seric register ENVELOPE *e; 6179382Seric { 6189382Seric char buf[BUFSIZ]; 6199382Seric register HDR *h; 6209382Seric extern char *arpadate(); 6219382Seric extern char *capitalize(); 6229382Seric char obuf[MAXLINE]; 6239382Seric 6249382Seric for (h = e->e_header; h != NULL; h = h->h_link) 6259382Seric { 6269382Seric register char *p; 62710689Seric extern bool bitintersect(); 6289382Seric 6299382Seric if (bitset(H_CHECK|H_ACHECK, h->h_flags) && 63010689Seric !bitintersect(h->h_mflags, m->m_flags)) 6319382Seric continue; 6329382Seric 63311414Seric /* handle Resent-... headers specially */ 63411414Seric if (bitset(H_RESENT, h->h_flags) && !bitset(EF_RESENT, e->e_flags)) 63511414Seric continue; 63611414Seric 6379382Seric p = h->h_value; 6389382Seric if (bitset(H_DEFAULT, h->h_flags)) 6399382Seric { 6409382Seric /* macro expand value if generated internally */ 6419382Seric expand(p, buf, &buf[sizeof buf], e); 6429382Seric p = buf; 6439382Seric if (p == NULL || *p == '\0') 6449382Seric continue; 6459382Seric } 6469382Seric 6479382Seric if (bitset(H_FROM|H_RCPT, h->h_flags)) 6489382Seric { 6499382Seric /* address field */ 6509382Seric bool oldstyle = bitset(EF_OLDSTYLE, e->e_flags); 6519382Seric 6529382Seric if (bitset(H_FROM, h->h_flags)) 6539382Seric oldstyle = FALSE; 65410176Seric commaize(h, p, fp, oldstyle, m); 6559382Seric } 6569382Seric else 6579382Seric { 6589382Seric /* vanilla header line */ 65912159Seric register char *nlp; 66012159Seric 66112159Seric (void) sprintf(obuf, "%s: ", capitalize(h->h_field)); 66212159Seric while ((nlp = index(p, '\n')) != NULL) 66312159Seric { 66412159Seric *nlp = '\0'; 66512159Seric (void) strcat(obuf, p); 66612159Seric *nlp = '\n'; 66712159Seric putline(obuf, fp, m); 66812159Seric p = ++nlp; 66912161Seric obuf[0] = '\0'; 67012159Seric } 67112159Seric (void) strcat(obuf, p); 67210176Seric putline(obuf, fp, m); 6739382Seric } 6749382Seric } 6759382Seric } 6769382Seric /* 6779382Seric ** COMMAIZE -- output a header field, making a comma-translated list. 6789382Seric ** 6799382Seric ** Parameters: 6809382Seric ** h -- the header field to output. 6819382Seric ** p -- the value to put in it. 6829382Seric ** fp -- file to put it to. 6839382Seric ** oldstyle -- TRUE if this is an old style header. 6849382Seric ** m -- a pointer to the mailer descriptor. If NULL, 6859382Seric ** don't transform the name at all. 6869382Seric ** 6879382Seric ** Returns: 6889382Seric ** none. 6899382Seric ** 6909382Seric ** Side Effects: 6919382Seric ** outputs "p" to file "fp". 6929382Seric */ 6939382Seric 69410176Seric commaize(h, p, fp, oldstyle, m) 6959382Seric register HDR *h; 6969382Seric register char *p; 6979382Seric FILE *fp; 6989382Seric bool oldstyle; 6999382Seric register MAILER *m; 7009382Seric { 7019382Seric register char *obp; 7029382Seric int opos; 7039382Seric bool firstone = TRUE; 70411157Seric char obuf[MAXLINE + 3]; 7059382Seric 7069382Seric /* 7079382Seric ** Output the address list translated by the 7089382Seric ** mailer and with commas. 7099382Seric */ 7109382Seric 7119382Seric # ifdef DEBUG 7129382Seric if (tTd(14, 2)) 7139382Seric printf("commaize(%s: %s)\n", h->h_field, p); 7149382Seric # endif DEBUG 7159382Seric 7169382Seric obp = obuf; 7179382Seric (void) sprintf(obp, "%s: ", capitalize(h->h_field)); 7189382Seric opos = strlen(h->h_field) + 2; 7199382Seric obp += opos; 7209382Seric 7219382Seric /* 7229382Seric ** Run through the list of values. 7239382Seric */ 7249382Seric 7259382Seric while (*p != '\0') 7269382Seric { 7279382Seric register char *name; 7289382Seric char savechar; 7299382Seric extern char *remotename(); 7309382Seric extern char *DelimChar; /* defined in prescan */ 7319382Seric 7329382Seric /* 7339382Seric ** Find the end of the name. New style names 7349382Seric ** end with a comma, old style names end with 7359382Seric ** a space character. However, spaces do not 7369382Seric ** necessarily delimit an old-style name -- at 7379382Seric ** signs mean keep going. 7389382Seric */ 7399382Seric 7409382Seric /* find end of name */ 7419382Seric while (isspace(*p) || *p == ',') 7429382Seric p++; 7439382Seric name = p; 7449382Seric for (;;) 7459382Seric { 7469382Seric char *oldp; 74716909Seric char pvpbuf[PSBUFSIZE]; 7489382Seric extern bool isatword(); 7499382Seric extern char **prescan(); 7509382Seric 75116909Seric (void) prescan(p, oldstyle ? ' ' : ',', pvpbuf); 7529382Seric p = DelimChar; 7539382Seric 7549382Seric /* look to see if we have an at sign */ 7559382Seric oldp = p; 7569382Seric while (*p != '\0' && isspace(*p)) 7579382Seric p++; 7589382Seric 7599382Seric if (*p != '@' && !isatword(p)) 7609382Seric { 7619382Seric p = oldp; 7629382Seric break; 7639382Seric } 7649382Seric p += *p == '@' ? 1 : 2; 7659382Seric while (*p != '\0' && isspace(*p)) 7669382Seric p++; 7679382Seric } 7689382Seric /* at the end of one complete name */ 7699382Seric 7709382Seric /* strip off trailing white space */ 7719382Seric while (p >= name && (isspace(*p) || *p == ',' || *p == '\0')) 7729382Seric p--; 7739382Seric if (++p == name) 7749382Seric continue; 7759382Seric savechar = *p; 7769382Seric *p = '\0'; 7779382Seric 7789382Seric /* translate the name to be relative */ 77910309Seric name = remotename(name, m, bitset(H_FROM, h->h_flags), FALSE); 7809382Seric if (*name == '\0') 7819382Seric { 7829382Seric *p = savechar; 7839382Seric continue; 7849382Seric } 7859382Seric 7869382Seric /* output the name with nice formatting */ 7879382Seric opos += qstrlen(name); 7889382Seric if (!firstone) 7899382Seric opos += 2; 7909382Seric if (opos > 78 && !firstone) 7919382Seric { 79210178Seric (void) strcpy(obp, ",\n"); 79310176Seric putline(obuf, fp, m); 7949382Seric obp = obuf; 7959382Seric (void) sprintf(obp, " "); 79610161Seric opos = strlen(obp); 79710161Seric obp += opos; 79810161Seric opos += qstrlen(name); 7999382Seric } 8009382Seric else if (!firstone) 8019382Seric { 8029382Seric (void) sprintf(obp, ", "); 8039382Seric obp += 2; 8049382Seric } 8059382Seric 8069382Seric /* strip off quote bits as we output */ 80711157Seric while (*name != '\0' && obp < &obuf[MAXLINE]) 8089382Seric { 8099382Seric if (bitset(0200, *name)) 8109382Seric *obp++ = '\\'; 8119382Seric *obp++ = *name++ & ~0200; 8129382Seric } 8139382Seric firstone = FALSE; 8149382Seric *p = savechar; 8159382Seric } 8169382Seric (void) strcpy(obp, "\n"); 81710176Seric putline(obuf, fp, m); 8189382Seric } 8199382Seric /* 8209382Seric ** ISATWORD -- tell if the word we are pointing to is "at". 8219382Seric ** 8229382Seric ** Parameters: 8239382Seric ** p -- word to check. 8249382Seric ** 8259382Seric ** Returns: 8269382Seric ** TRUE -- if p is the word at. 8279382Seric ** FALSE -- otherwise. 8289382Seric ** 8299382Seric ** Side Effects: 8309382Seric ** none. 8319382Seric */ 8329382Seric 8339382Seric bool 8349382Seric isatword(p) 8359382Seric register char *p; 8369382Seric { 8379382Seric extern char lower(); 8389382Seric 8399382Seric if (lower(p[0]) == 'a' && lower(p[1]) == 't' && 8409382Seric p[2] != '\0' && isspace(p[2])) 8419382Seric return (TRUE); 8429382Seric return (FALSE); 8439382Seric } 844