122706Sdist /* 234921Sbostic * Copyright (c) 1983 Eric P. Allman 333729Sbostic * Copyright (c) 1988 Regents of the University of California. 433729Sbostic * All rights reserved. 533729Sbostic * 642826Sbostic * %sccs.include.redist.c% 733729Sbostic */ 822706Sdist 922706Sdist #ifndef lint 10*54999Seric static char sccsid[] = "@(#)headers.c 5.19 (Berkeley) 07/12/92"; 1133729Sbostic #endif /* not lint */ 1222706Sdist 1340960Sbostic # include <sys/param.h> 144091Seric # include <errno.h> 154091Seric # include "sendmail.h" 164091Seric 174091Seric /* 184091Seric ** CHOMPHEADER -- process and save a header line. 194091Seric ** 204091Seric ** Called by collect and by readcf to deal with header lines. 214091Seric ** 224091Seric ** Parameters: 234091Seric ** line -- header as a text line. 244091Seric ** def -- if set, this is a default value. 254091Seric ** 264091Seric ** Returns: 274091Seric ** flags for this header. 284091Seric ** 294091Seric ** Side Effects: 304091Seric ** The header is saved on the header list. 314319Seric ** Contents of 'line' are destroyed. 324091Seric */ 334091Seric 344091Seric chompheader(line, def) 354091Seric char *line; 364091Seric bool def; 374091Seric { 384091Seric register char *p; 394091Seric register HDR *h; 404091Seric HDR **hp; 414091Seric char *fname; 424091Seric char *fvalue; 434091Seric struct hdrinfo *hi; 449059Seric bool cond = FALSE; 4510689Seric BITMAP mopts; 467890Seric extern char *crackaddr(); 474091Seric 487677Seric if (tTd(31, 6)) 497677Seric printf("chompheader: %s\n", line); 507677Seric 514627Seric /* strip off options */ 5210689Seric clrbitmap(mopts); 534627Seric p = line; 544627Seric if (*p == '?') 554627Seric { 564627Seric /* have some */ 574627Seric register char *q = index(p + 1, *p); 584627Seric 594627Seric if (q != NULL) 604627Seric { 614627Seric *q++ = '\0'; 6210689Seric while (*++p != '\0') 6310689Seric setbitn(*p, mopts); 644627Seric p = q; 654627Seric } 664627Seric else 6736233Skarels usrerr("chompheader: syntax error, line \"%s\"", line); 689059Seric cond = TRUE; 694627Seric } 704627Seric 714091Seric /* find canonical name */ 724627Seric fname = p; 734627Seric p = index(p, ':'); 7410118Seric if (p == NULL) 7510118Seric { 7610118Seric syserr("chompheader: syntax error, line \"%s\"", line); 7710118Seric return (0); 7810118Seric } 794091Seric fvalue = &p[1]; 804091Seric while (isspace(*--p)) 814091Seric continue; 824091Seric *++p = '\0'; 834091Seric makelower(fname); 844091Seric 854091Seric /* strip field value on front */ 864091Seric if (*fvalue == ' ') 874091Seric fvalue++; 884091Seric 894091Seric /* see if it is a known type */ 904091Seric for (hi = HdrInfo; hi->hi_field != NULL; hi++) 914091Seric { 924091Seric if (strcmp(hi->hi_field, fname) == 0) 934091Seric break; 944091Seric } 954091Seric 9611414Seric /* see if this is a resent message */ 9711930Seric if (!def && bitset(H_RESENT, hi->hi_flags)) 9811414Seric CurEnv->e_flags |= EF_RESENT; 9911414Seric 1004091Seric /* if this means "end of header" quit now */ 1014091Seric if (bitset(H_EOH, hi->hi_flags)) 1024091Seric return (hi->hi_flags); 1034091Seric 10411414Seric /* drop explicit From: if same as what we would generate -- for MH */ 10514784Seric p = "resent-from"; 10614784Seric if (!bitset(EF_RESENT, CurEnv->e_flags)) 10714784Seric p += 7; 10814784Seric if (!def && !QueueRun && strcmp(fname, p) == 0) 10911414Seric { 11024941Seric if (CurEnv->e_from.q_paddr != NULL && 11124941Seric strcmp(fvalue, CurEnv->e_from.q_paddr) == 0) 11211414Seric return (hi->hi_flags); 11311414Seric } 11411414Seric 11514784Seric /* delete default value for this header */ 11614784Seric for (hp = &CurEnv->e_header; (h = *hp) != NULL; hp = &h->h_link) 11714784Seric { 11814784Seric if (strcmp(fname, h->h_field) == 0 && 11914784Seric bitset(H_DEFAULT, h->h_flags) && 12014784Seric !bitset(H_FORCE, h->h_flags)) 12114784Seric h->h_value = NULL; 12214784Seric } 12314784Seric 12413012Seric /* create a new node */ 12513012Seric h = (HDR *) xalloc(sizeof *h); 12613012Seric h->h_field = newstr(fname); 12713012Seric h->h_value = NULL; 12813012Seric h->h_link = NULL; 12923117Seric bcopy((char *) mopts, (char *) h->h_mflags, sizeof mopts); 13013012Seric *hp = h; 1318066Seric h->h_flags = hi->hi_flags; 1324091Seric if (def) 1334091Seric h->h_flags |= H_DEFAULT; 1349059Seric if (cond) 1359059Seric h->h_flags |= H_CHECK; 1364091Seric if (h->h_value != NULL) 1379351Seric free((char *) h->h_value); 1388066Seric h->h_value = newstr(fvalue); 1394091Seric 1405937Seric /* hack to see if this is a new format message */ 1418095Seric if (!def && bitset(H_RCPT|H_FROM, h->h_flags) && 1425937Seric (index(fvalue, ',') != NULL || index(fvalue, '(') != NULL || 1438089Seric index(fvalue, '<') != NULL || index(fvalue, ';') != NULL)) 1448089Seric { 1459342Seric CurEnv->e_flags &= ~EF_OLDSTYLE; 1468089Seric } 1475937Seric 1484091Seric return (h->h_flags); 1494091Seric } 1504091Seric /* 1516980Seric ** ADDHEADER -- add a header entry to the end of the queue. 1526980Seric ** 1536980Seric ** This bypasses the special checking of chompheader. 1546980Seric ** 1556980Seric ** Parameters: 1566980Seric ** field -- the name of the header field. 1576980Seric ** value -- the value of the field. It must be lower-cased. 1586980Seric ** e -- the envelope to add them to. 1596980Seric ** 1606980Seric ** Returns: 1616980Seric ** none. 1626980Seric ** 1636980Seric ** Side Effects: 1646980Seric ** adds the field on the list of headers for this envelope. 1656980Seric */ 1666980Seric 1676980Seric addheader(field, value, e) 1686980Seric char *field; 1696980Seric char *value; 1706980Seric ENVELOPE *e; 1716980Seric { 1726980Seric register HDR *h; 1736980Seric register struct hdrinfo *hi; 1746980Seric HDR **hp; 1756980Seric 1766980Seric /* find info struct */ 1776980Seric for (hi = HdrInfo; hi->hi_field != NULL; hi++) 1786980Seric { 1796980Seric if (strcmp(field, hi->hi_field) == 0) 1806980Seric break; 1816980Seric } 1826980Seric 1836980Seric /* find current place in list -- keep back pointer? */ 1846980Seric for (hp = &e->e_header; (h = *hp) != NULL; hp = &h->h_link) 1856980Seric { 1866980Seric if (strcmp(field, h->h_field) == 0) 1876980Seric break; 1886980Seric } 1896980Seric 1906980Seric /* allocate space for new header */ 1916980Seric h = (HDR *) xalloc(sizeof *h); 1926980Seric h->h_field = field; 1936980Seric h->h_value = newstr(value); 1947368Seric h->h_link = *hp; 1956980Seric h->h_flags = hi->hi_flags | H_DEFAULT; 19610689Seric clrbitmap(h->h_mflags); 1976980Seric *hp = h; 1986980Seric } 1996980Seric /* 2004091Seric ** HVALUE -- return value of a header. 2014091Seric ** 2024091Seric ** Only "real" fields (i.e., ones that have not been supplied 2034091Seric ** as a default) are used. 2044091Seric ** 2054091Seric ** Parameters: 2064091Seric ** field -- the field name. 2074091Seric ** 2084091Seric ** Returns: 2094091Seric ** pointer to the value part. 2104091Seric ** NULL if not found. 2114091Seric ** 2124091Seric ** Side Effects: 2139382Seric ** none. 2144091Seric */ 2154091Seric 2164091Seric char * 2174091Seric hvalue(field) 2184091Seric char *field; 2194091Seric { 2204091Seric register HDR *h; 2214091Seric 2226908Seric for (h = CurEnv->e_header; h != NULL; h = h->h_link) 2234091Seric { 2244091Seric if (!bitset(H_DEFAULT, h->h_flags) && strcmp(h->h_field, field) == 0) 2254091Seric return (h->h_value); 2264091Seric } 2274091Seric return (NULL); 2284091Seric } 2294091Seric /* 2304091Seric ** ISHEADER -- predicate telling if argument is a header. 2314091Seric ** 2324319Seric ** A line is a header if it has a single word followed by 2334319Seric ** optional white space followed by a colon. 2344319Seric ** 2354091Seric ** Parameters: 2364091Seric ** s -- string to check for possible headerness. 2374091Seric ** 2384091Seric ** Returns: 2394091Seric ** TRUE if s is a header. 2404091Seric ** FALSE otherwise. 2414091Seric ** 2424091Seric ** Side Effects: 2434091Seric ** none. 2444091Seric */ 2454091Seric 2464091Seric bool 2474091Seric isheader(s) 2484091Seric register char *s; 2494091Seric { 2509382Seric while (*s > ' ' && *s != ':' && *s != '\0') 2514091Seric s++; 2529382Seric 2539382Seric /* following technically violates RFC822 */ 2544091Seric while (isspace(*s)) 2554091Seric s++; 2569382Seric 2574091Seric return (*s == ':'); 2584091Seric } 2595919Seric /* 2607783Seric ** EATHEADER -- run through the stored header and extract info. 2617783Seric ** 2627783Seric ** Parameters: 2639382Seric ** e -- the envelope to process. 2647783Seric ** 2657783Seric ** Returns: 2667783Seric ** none. 2677783Seric ** 2687783Seric ** Side Effects: 2697783Seric ** Sets a bunch of global variables from information 2709382Seric ** in the collected header. 2719382Seric ** Aborts the message if the hop count is exceeded. 2727783Seric */ 2737783Seric 2749382Seric eatheader(e) 2759382Seric register ENVELOPE *e; 2767783Seric { 2777783Seric register HDR *h; 2787783Seric register char *p; 2799382Seric int hopcnt = 0; 2807783Seric 2819382Seric if (tTd(32, 1)) 2829382Seric printf("----- collected header -----\n"); 2839382Seric for (h = e->e_header; h != NULL; h = h->h_link) 2847783Seric { 2857783Seric extern char *capitalize(); 2867783Seric 2879382Seric if (tTd(32, 1)) 2887783Seric printf("%s: %s\n", capitalize(h->h_field), h->h_value); 28911414Seric /* count the number of times it has been processed */ 2909382Seric if (bitset(H_TRACE, h->h_flags)) 2919382Seric hopcnt++; 29211414Seric 29311414Seric /* send to this person if we so desire */ 29411414Seric if (GrabTo && bitset(H_RCPT, h->h_flags) && 29511414Seric !bitset(H_DEFAULT, h->h_flags) && 29611414Seric (!bitset(EF_RESENT, CurEnv->e_flags) || bitset(H_RESENT, h->h_flags))) 29711414Seric { 29811414Seric sendtolist(h->h_value, (ADDRESS *) NULL, &CurEnv->e_sendqueue); 29911414Seric } 30011414Seric 30111414Seric /* log the message-id */ 30211290Seric #ifdef LOG 30313103Seric if (!QueueRun && LogLevel > 8 && h->h_value != NULL && 30411299Seric strcmp(h->h_field, "message-id") == 0) 30511290Seric { 30611290Seric char buf[MAXNAME]; 30711290Seric 30811290Seric p = h->h_value; 30911290Seric if (bitset(H_DEFAULT, h->h_flags)) 31011290Seric { 31111290Seric expand(p, buf, &buf[sizeof buf], e); 31211290Seric p = buf; 31311290Seric } 31411290Seric syslog(LOG_INFO, "%s: message-id=%s", e->e_id, p); 31511290Seric } 31611290Seric #endif LOG 3179382Seric } 3189382Seric if (tTd(32, 1)) 3197783Seric printf("----------------------------\n"); 3207783Seric 3219382Seric /* store hop count */ 3229382Seric if (hopcnt > e->e_hopcount) 3239382Seric e->e_hopcount = hopcnt; 3249382Seric 3257783Seric /* message priority */ 3269382Seric p = hvalue("precedence"); 3279382Seric if (p != NULL) 3289382Seric e->e_class = priencode(p); 3297783Seric if (!QueueRun) 33025013Seric e->e_msgpriority = e->e_msgsize 33124981Seric - e->e_class * WkClassFact 33224981Seric + e->e_nrcpts * WkRecipFact; 3337783Seric 3348066Seric /* return receipt to */ 3358066Seric p = hvalue("return-receipt-to"); 3367783Seric if (p != NULL) 3379382Seric e->e_receiptto = p; 3387783Seric 3398253Seric /* errors to */ 3408253Seric p = hvalue("errors-to"); 3418253Seric if (p != NULL) 3429620Seric sendtolist(p, (ADDRESS *) NULL, &e->e_errorqueue); 3438253Seric 3447783Seric /* full name of from person */ 3457783Seric p = hvalue("full-name"); 3467783Seric if (p != NULL) 3479382Seric define('x', p, e); 3487783Seric 3497783Seric /* date message originated */ 3507783Seric p = hvalue("posted-date"); 3517783Seric if (p == NULL) 3527783Seric p = hvalue("date"); 3537783Seric if (p != NULL) 3547783Seric { 3559382Seric define('a', p, e); 3567783Seric /* we don't have a good way to do canonical conversion .... 3579382Seric define('d', newstr(arpatounix(p)), e); 3587783Seric .... so we will ignore the problem for the time being */ 3597783Seric } 36011290Seric 36111290Seric /* 36211290Seric ** Log collection information. 36311290Seric */ 36411290Seric 36511290Seric # ifdef LOG 36611299Seric if (!QueueRun && LogLevel > 1) 36711290Seric { 36836230Skarels char hbuf[100], *name = hbuf; 36936230Skarels 37036230Skarels if (RealHostName == NULL) 37136230Skarels name = "local"; 37236230Skarels else if (RealHostName[0] == '[') 37336230Skarels name = RealHostName; 37436230Skarels else 375*54999Seric (void)sprintf(hbuf, "%.80s (%s)", 37636230Skarels RealHostName, inet_ntoa(RealHostAddr.sin_addr)); 37736230Skarels syslog(LOG_INFO, 37836230Skarels "%s: from=%s, size=%ld, class=%d, received from %s\n", 37936230Skarels CurEnv->e_id, CurEnv->e_from.q_paddr, CurEnv->e_msgsize, 38036230Skarels CurEnv->e_class, name); 38111290Seric } 38211290Seric # endif LOG 3837783Seric } 3847783Seric /* 3857783Seric ** PRIENCODE -- encode external priority names into internal values. 3867783Seric ** 3877783Seric ** Parameters: 3887783Seric ** p -- priority in ascii. 3897783Seric ** 3907783Seric ** Returns: 3917783Seric ** priority as a numeric level. 3927783Seric ** 3937783Seric ** Side Effects: 3947783Seric ** none. 3957783Seric */ 3967783Seric 3977783Seric priencode(p) 3987783Seric char *p; 3997783Seric { 4008253Seric register int i; 4017783Seric 4028253Seric for (i = 0; i < NumPriorities; i++) 4037783Seric { 40433725Sbostic if (!strcasecmp(p, Priorities[i].pri_name)) 4058253Seric return (Priorities[i].pri_val); 4067783Seric } 4078253Seric 4088253Seric /* unknown priority */ 4098253Seric return (0); 4107783Seric } 4117783Seric /* 4127890Seric ** CRACKADDR -- parse an address and turn it into a macro 4137783Seric ** 4147783Seric ** This doesn't actually parse the address -- it just extracts 4157783Seric ** it and replaces it with "$g". The parse is totally ad hoc 4167783Seric ** and isn't even guaranteed to leave something syntactically 4177783Seric ** identical to what it started with. However, it does leave 4187783Seric ** something semantically identical. 4197783Seric ** 42051379Seric ** This algorithm has been cleaned up to handle a wider range 42151379Seric ** of cases -- notably quoted and backslash escaped strings. 42251379Seric ** This modification makes it substantially better at preserving 42351379Seric ** the original syntax. 4247783Seric ** 4257783Seric ** Parameters: 4267890Seric ** addr -- the address to be cracked. 4277783Seric ** 4287783Seric ** Returns: 4297783Seric ** a pointer to the new version. 4307783Seric ** 4317783Seric ** Side Effects: 4327890Seric ** none. 4337783Seric ** 4347783Seric ** Warning: 4357783Seric ** The return value is saved in local storage and should 4367783Seric ** be copied if it is to be reused. 4377783Seric */ 4387783Seric 4397783Seric char * 4407890Seric crackaddr(addr) 4417890Seric register char *addr; 4427783Seric { 4437783Seric register char *p; 44451379Seric register char c; 44551379Seric int cmtlev; 44651379Seric int copylev; 44751379Seric bool qmode; 44851379Seric bool putgmac = FALSE; 44951379Seric register char *bp; 4507783Seric static char buf[MAXNAME]; 4517783Seric 4527783Seric if (tTd(33, 1)) 4537890Seric printf("crackaddr(%s)\n", addr); 4547783Seric 4558082Seric /* strip leading spaces */ 4568082Seric while (*addr != '\0' && isspace(*addr)) 4578082Seric addr++; 4588082Seric 4597783Seric /* 46051379Seric ** Start by assuming we have no angle brackets. This will be 46151379Seric ** adjusted later if we find them. 4627783Seric */ 4637783Seric 46451379Seric bp = buf; 46551379Seric p = addr; 46651379Seric copylev = cmtlev = 0; 46751379Seric qmode = FALSE; 46851379Seric 46951379Seric while ((c = *p++) != '\0') 4707783Seric { 47151379Seric if (copylev > 0 || c == ' ') 47251379Seric *bp++ = c; 4737783Seric 47451379Seric /* check for backslash escapes */ 47551379Seric if (c == '\\') 4767783Seric { 47751379Seric if ((c = *p++) == '\0') 4787783Seric { 47951379Seric /* too far */ 48051379Seric p--; 48151379Seric goto putg; 4827783Seric } 48351379Seric if (copylev > 0) 48451379Seric *bp++ = c; 48551379Seric goto putg; 4867783Seric } 4877783Seric 48851379Seric /* check for quoted strings */ 48951379Seric if (c == '"') 4907783Seric { 49151379Seric qmode = !qmode; 49251379Seric continue; 4937783Seric } 49451379Seric if (qmode) 49551379Seric goto putg; 4967783Seric 49751379Seric /* check for comments */ 49851379Seric if (c == '(') 4997783Seric { 50051379Seric cmtlev++; 50151379Seric if (copylev++ <= 0) 50251379Seric *bp++ = c; 50351379Seric } 50451379Seric if (cmtlev > 0) 50551379Seric { 50651379Seric if (c == ')') 5077783Seric { 50851379Seric cmtlev--; 50951379Seric copylev--; 5107783Seric } 5117783Seric continue; 5127783Seric } 5137783Seric 51451379Seric /* check for angle brackets */ 51551379Seric if (c == '<') 51651379Seric { 51751379Seric /* oops -- have to change our mind */ 51851379Seric bcopy(addr, buf, p - addr); 51951379Seric bp = &buf[p - addr]; 52051379Seric copylev = 0; 52151379Seric putgmac = FALSE; 52251379Seric continue; 52351379Seric } 5247783Seric 52551379Seric if (c == '>') 5267783Seric { 52751379Seric if (copylev++ <= 0) 52851379Seric *bp++ = c; 52951379Seric continue; 5307783Seric } 53151379Seric 53251379Seric /* must be a real address character */ 53351379Seric putg: 53451379Seric if (copylev <= 0 && !putgmac) 53551379Seric { 53651379Seric *bp++ = '\001'; 53751379Seric *bp++ = 'g'; 53851379Seric putgmac = TRUE; 53951379Seric } 5407783Seric } 5417783Seric 54251379Seric *bp++ = '\0'; 5437783Seric 5447783Seric if (tTd(33, 1)) 5457944Seric printf("crackaddr=>`%s'\n", buf); 5467783Seric 5477783Seric return (buf); 5487783Seric } 5499382Seric /* 5509382Seric ** PUTHEADER -- put the header part of a message from the in-core copy 5519382Seric ** 5529382Seric ** Parameters: 5539382Seric ** fp -- file to put it on. 5549382Seric ** m -- mailer to use. 5559382Seric ** e -- envelope to use. 5569382Seric ** 5579382Seric ** Returns: 5589382Seric ** none. 5599382Seric ** 5609382Seric ** Side Effects: 5619382Seric ** none. 5629382Seric */ 5639382Seric 56410176Seric putheader(fp, m, e) 5659382Seric register FILE *fp; 5669382Seric register MAILER *m; 5679382Seric register ENVELOPE *e; 5689382Seric { 56940960Sbostic char buf[MAX(MAXFIELD,BUFSIZ)]; 5709382Seric register HDR *h; 5719382Seric extern char *arpadate(); 5729382Seric extern char *capitalize(); 57340960Sbostic char obuf[MAX(MAXFIELD,MAXLINE)]; 5749382Seric 5759382Seric for (h = e->e_header; h != NULL; h = h->h_link) 5769382Seric { 5779382Seric register char *p; 57810689Seric extern bool bitintersect(); 5799382Seric 5809382Seric if (bitset(H_CHECK|H_ACHECK, h->h_flags) && 58110689Seric !bitintersect(h->h_mflags, m->m_flags)) 5829382Seric continue; 5839382Seric 58411414Seric /* handle Resent-... headers specially */ 58511414Seric if (bitset(H_RESENT, h->h_flags) && !bitset(EF_RESENT, e->e_flags)) 58611414Seric continue; 58711414Seric 5889382Seric p = h->h_value; 5899382Seric if (bitset(H_DEFAULT, h->h_flags)) 5909382Seric { 5919382Seric /* macro expand value if generated internally */ 5929382Seric expand(p, buf, &buf[sizeof buf], e); 5939382Seric p = buf; 5949382Seric if (p == NULL || *p == '\0') 5959382Seric continue; 5969382Seric } 5979382Seric 5989382Seric if (bitset(H_FROM|H_RCPT, h->h_flags)) 5999382Seric { 6009382Seric /* address field */ 6019382Seric bool oldstyle = bitset(EF_OLDSTYLE, e->e_flags); 6029382Seric 6039382Seric if (bitset(H_FROM, h->h_flags)) 6049382Seric oldstyle = FALSE; 60510176Seric commaize(h, p, fp, oldstyle, m); 6069382Seric } 6079382Seric else 6089382Seric { 6099382Seric /* vanilla header line */ 61012159Seric register char *nlp; 61112159Seric 61212159Seric (void) sprintf(obuf, "%s: ", capitalize(h->h_field)); 61312159Seric while ((nlp = index(p, '\n')) != NULL) 61412159Seric { 61512159Seric *nlp = '\0'; 61612159Seric (void) strcat(obuf, p); 61712159Seric *nlp = '\n'; 61812159Seric putline(obuf, fp, m); 61912159Seric p = ++nlp; 62012161Seric obuf[0] = '\0'; 62112159Seric } 62212159Seric (void) strcat(obuf, p); 62310176Seric putline(obuf, fp, m); 6249382Seric } 6259382Seric } 6269382Seric } 6279382Seric /* 6289382Seric ** COMMAIZE -- output a header field, making a comma-translated list. 6299382Seric ** 6309382Seric ** Parameters: 6319382Seric ** h -- the header field to output. 6329382Seric ** p -- the value to put in it. 6339382Seric ** fp -- file to put it to. 6349382Seric ** oldstyle -- TRUE if this is an old style header. 6359382Seric ** m -- a pointer to the mailer descriptor. If NULL, 6369382Seric ** don't transform the name at all. 6379382Seric ** 6389382Seric ** Returns: 6399382Seric ** none. 6409382Seric ** 6419382Seric ** Side Effects: 6429382Seric ** outputs "p" to file "fp". 6439382Seric */ 6449382Seric 64510176Seric commaize(h, p, fp, oldstyle, m) 6469382Seric register HDR *h; 6479382Seric register char *p; 6489382Seric FILE *fp; 6499382Seric bool oldstyle; 6509382Seric register MAILER *m; 6519382Seric { 6529382Seric register char *obp; 6539382Seric int opos; 6549382Seric bool firstone = TRUE; 65511157Seric char obuf[MAXLINE + 3]; 6569382Seric 6579382Seric /* 6589382Seric ** Output the address list translated by the 6599382Seric ** mailer and with commas. 6609382Seric */ 6619382Seric 6629382Seric if (tTd(14, 2)) 6639382Seric printf("commaize(%s: %s)\n", h->h_field, p); 6649382Seric 6659382Seric obp = obuf; 6669382Seric (void) sprintf(obp, "%s: ", capitalize(h->h_field)); 6679382Seric opos = strlen(h->h_field) + 2; 6689382Seric obp += opos; 6699382Seric 6709382Seric /* 6719382Seric ** Run through the list of values. 6729382Seric */ 6739382Seric 6749382Seric while (*p != '\0') 6759382Seric { 6769382Seric register char *name; 67754983Seric register int c; 6789382Seric char savechar; 6799382Seric extern char *remotename(); 6809382Seric extern char *DelimChar; /* defined in prescan */ 6819382Seric 6829382Seric /* 6839382Seric ** Find the end of the name. New style names 6849382Seric ** end with a comma, old style names end with 6859382Seric ** a space character. However, spaces do not 6869382Seric ** necessarily delimit an old-style name -- at 6879382Seric ** signs mean keep going. 6889382Seric */ 6899382Seric 6909382Seric /* find end of name */ 6919382Seric while (isspace(*p) || *p == ',') 6929382Seric p++; 6939382Seric name = p; 6949382Seric for (;;) 6959382Seric { 6969382Seric char *oldp; 69716909Seric char pvpbuf[PSBUFSIZE]; 6989382Seric extern bool isatword(); 6999382Seric extern char **prescan(); 7009382Seric 70116909Seric (void) prescan(p, oldstyle ? ' ' : ',', pvpbuf); 7029382Seric p = DelimChar; 7039382Seric 7049382Seric /* look to see if we have an at sign */ 7059382Seric oldp = p; 7069382Seric while (*p != '\0' && isspace(*p)) 7079382Seric p++; 7089382Seric 7099382Seric if (*p != '@' && !isatword(p)) 7109382Seric { 7119382Seric p = oldp; 7129382Seric break; 7139382Seric } 7149382Seric p += *p == '@' ? 1 : 2; 7159382Seric while (*p != '\0' && isspace(*p)) 7169382Seric p++; 7179382Seric } 7189382Seric /* at the end of one complete name */ 7199382Seric 7209382Seric /* strip off trailing white space */ 7219382Seric while (p >= name && (isspace(*p) || *p == ',' || *p == '\0')) 7229382Seric p--; 7239382Seric if (++p == name) 7249382Seric continue; 7259382Seric savechar = *p; 7269382Seric *p = '\0'; 7279382Seric 7289382Seric /* translate the name to be relative */ 72910309Seric name = remotename(name, m, bitset(H_FROM, h->h_flags), FALSE); 7309382Seric if (*name == '\0') 7319382Seric { 7329382Seric *p = savechar; 7339382Seric continue; 7349382Seric } 7359382Seric 7369382Seric /* output the name with nice formatting */ 73754983Seric opos += strlen(name); 7389382Seric if (!firstone) 7399382Seric opos += 2; 7409382Seric if (opos > 78 && !firstone) 7419382Seric { 74210178Seric (void) strcpy(obp, ",\n"); 74310176Seric putline(obuf, fp, m); 7449382Seric obp = obuf; 7459382Seric (void) sprintf(obp, " "); 74610161Seric opos = strlen(obp); 74710161Seric obp += opos; 74854983Seric opos += strlen(name); 7499382Seric } 7509382Seric else if (!firstone) 7519382Seric { 7529382Seric (void) sprintf(obp, ", "); 7539382Seric obp += 2; 7549382Seric } 7559382Seric 7569382Seric /* strip off quote bits as we output */ 75754983Seric while ((c = *name++) != '\0' && obp < &obuf[MAXLINE]) 7589382Seric { 75954983Seric if (bitnset(M_7BITS, m->m_flags)) 76054983Seric c &= 0177; 76154983Seric *obp++ = c; 7629382Seric } 7639382Seric firstone = FALSE; 7649382Seric *p = savechar; 7659382Seric } 7669382Seric (void) strcpy(obp, "\n"); 76710176Seric putline(obuf, fp, m); 7689382Seric } 7699382Seric /* 7709382Seric ** ISATWORD -- tell if the word we are pointing to is "at". 7719382Seric ** 7729382Seric ** Parameters: 7739382Seric ** p -- word to check. 7749382Seric ** 7759382Seric ** Returns: 7769382Seric ** TRUE -- if p is the word at. 7779382Seric ** FALSE -- otherwise. 7789382Seric ** 7799382Seric ** Side Effects: 7809382Seric ** none. 7819382Seric */ 7829382Seric 7839382Seric bool 7849382Seric isatword(p) 7859382Seric register char *p; 7869382Seric { 7879382Seric extern char lower(); 7889382Seric 7899382Seric if (lower(p[0]) == 'a' && lower(p[1]) == 't' && 7909382Seric p[2] != '\0' && isspace(p[2])) 7919382Seric return (TRUE); 7929382Seric return (FALSE); 7939382Seric } 794