14091Seric # include <errno.h> 24091Seric # include "sendmail.h" 34091Seric 4*21059Seric SCCSID(@(#)headers.c 4.6 05/24/85); 54091Seric 64091Seric /* 74091Seric ** CHOMPHEADER -- process and save a header line. 84091Seric ** 94091Seric ** Called by collect and by readcf to deal with header lines. 104091Seric ** 114091Seric ** Parameters: 124091Seric ** line -- header as a text line. 134091Seric ** def -- if set, this is a default value. 144091Seric ** 154091Seric ** Returns: 164091Seric ** flags for this header. 174091Seric ** 184091Seric ** Side Effects: 194091Seric ** The header is saved on the header list. 204319Seric ** Contents of 'line' are destroyed. 214091Seric */ 224091Seric 234091Seric chompheader(line, def) 244091Seric char *line; 254091Seric bool def; 264091Seric { 274091Seric register char *p; 284091Seric register HDR *h; 294091Seric HDR **hp; 304091Seric char *fname; 314091Seric char *fvalue; 324091Seric struct hdrinfo *hi; 339059Seric bool cond = FALSE; 3410689Seric BITMAP mopts; 357890Seric extern char *crackaddr(); 364091Seric 377677Seric # ifdef DEBUG 387677Seric if (tTd(31, 6)) 397677Seric printf("chompheader: %s\n", line); 407677Seric # endif DEBUG 417677Seric 424627Seric /* strip off options */ 4310689Seric clrbitmap(mopts); 444627Seric p = line; 454627Seric if (*p == '?') 464627Seric { 474627Seric /* have some */ 484627Seric register char *q = index(p + 1, *p); 494627Seric 504627Seric if (q != NULL) 514627Seric { 524627Seric *q++ = '\0'; 5310689Seric while (*++p != '\0') 5410689Seric setbitn(*p, mopts); 554627Seric p = q; 564627Seric } 574627Seric else 584627Seric syserr("chompheader: syntax error, line \"%s\"", line); 599059Seric cond = TRUE; 604627Seric } 614627Seric 624091Seric /* find canonical name */ 634627Seric fname = p; 644627Seric p = index(p, ':'); 6510118Seric if (p == NULL) 6610118Seric { 6710118Seric syserr("chompheader: syntax error, line \"%s\"", line); 6810118Seric return (0); 6910118Seric } 704091Seric fvalue = &p[1]; 714091Seric while (isspace(*--p)) 724091Seric continue; 734091Seric *++p = '\0'; 744091Seric makelower(fname); 754091Seric 764091Seric /* strip field value on front */ 774091Seric if (*fvalue == ' ') 784091Seric fvalue++; 794091Seric 804091Seric /* see if it is a known type */ 814091Seric for (hi = HdrInfo; hi->hi_field != NULL; hi++) 824091Seric { 834091Seric if (strcmp(hi->hi_field, fname) == 0) 844091Seric break; 854091Seric } 864091Seric 8711414Seric /* see if this is a resent message */ 8811930Seric if (!def && bitset(H_RESENT, hi->hi_flags)) 8911414Seric CurEnv->e_flags |= EF_RESENT; 9011414Seric 914091Seric /* if this means "end of header" quit now */ 924091Seric if (bitset(H_EOH, hi->hi_flags)) 934091Seric return (hi->hi_flags); 944091Seric 9511414Seric /* drop explicit From: if same as what we would generate -- for MH */ 9614784Seric p = "resent-from"; 9714784Seric if (!bitset(EF_RESENT, CurEnv->e_flags)) 9814784Seric p += 7; 9914784Seric if (!def && !QueueRun && strcmp(fname, p) == 0) 10011414Seric { 10114788Seric ADDRESS fromaddr; 10214788Seric 10314784Seric if (strcmp(fvalue, CurEnv->e_from.q_paddr) == 0) 10411414Seric return (hi->hi_flags); 10511414Seric } 10611414Seric 10714784Seric /* delete default value for this header */ 10814784Seric for (hp = &CurEnv->e_header; (h = *hp) != NULL; hp = &h->h_link) 10914784Seric { 11014784Seric if (strcmp(fname, h->h_field) == 0 && 11114784Seric bitset(H_DEFAULT, h->h_flags) && 11214784Seric !bitset(H_FORCE, h->h_flags)) 11314784Seric h->h_value = NULL; 11414784Seric } 11514784Seric 11613012Seric /* create a new node */ 11713012Seric h = (HDR *) xalloc(sizeof *h); 11813012Seric h->h_field = newstr(fname); 11913012Seric h->h_value = NULL; 12013012Seric h->h_link = NULL; 12113012Seric bcopy(mopts, h->h_mflags, sizeof mopts); 12213012Seric *hp = h; 1238066Seric h->h_flags = hi->hi_flags; 1244091Seric if (def) 1254091Seric h->h_flags |= H_DEFAULT; 1269059Seric if (cond) 1279059Seric h->h_flags |= H_CHECK; 1284091Seric if (h->h_value != NULL) 1299351Seric free((char *) h->h_value); 1308066Seric h->h_value = newstr(fvalue); 1314091Seric 1325937Seric /* hack to see if this is a new format message */ 1338095Seric if (!def && bitset(H_RCPT|H_FROM, h->h_flags) && 1345937Seric (index(fvalue, ',') != NULL || index(fvalue, '(') != NULL || 1358089Seric index(fvalue, '<') != NULL || index(fvalue, ';') != NULL)) 1368089Seric { 1379342Seric CurEnv->e_flags &= ~EF_OLDSTYLE; 1388089Seric } 1395937Seric 1404091Seric return (h->h_flags); 1414091Seric } 1424091Seric /* 1436980Seric ** ADDHEADER -- add a header entry to the end of the queue. 1446980Seric ** 1456980Seric ** This bypasses the special checking of chompheader. 1466980Seric ** 1476980Seric ** Parameters: 1486980Seric ** field -- the name of the header field. 1496980Seric ** value -- the value of the field. It must be lower-cased. 1506980Seric ** e -- the envelope to add them to. 1516980Seric ** 1526980Seric ** Returns: 1536980Seric ** none. 1546980Seric ** 1556980Seric ** Side Effects: 1566980Seric ** adds the field on the list of headers for this envelope. 1576980Seric */ 1586980Seric 1596980Seric addheader(field, value, e) 1606980Seric char *field; 1616980Seric char *value; 1626980Seric ENVELOPE *e; 1636980Seric { 1646980Seric register HDR *h; 1656980Seric register struct hdrinfo *hi; 1666980Seric HDR **hp; 1676980Seric 1686980Seric /* find info struct */ 1696980Seric for (hi = HdrInfo; hi->hi_field != NULL; hi++) 1706980Seric { 1716980Seric if (strcmp(field, hi->hi_field) == 0) 1726980Seric break; 1736980Seric } 1746980Seric 1756980Seric /* find current place in list -- keep back pointer? */ 1766980Seric for (hp = &e->e_header; (h = *hp) != NULL; hp = &h->h_link) 1776980Seric { 1786980Seric if (strcmp(field, h->h_field) == 0) 1796980Seric break; 1806980Seric } 1816980Seric 1826980Seric /* allocate space for new header */ 1836980Seric h = (HDR *) xalloc(sizeof *h); 1846980Seric h->h_field = field; 1856980Seric h->h_value = newstr(value); 1867368Seric h->h_link = *hp; 1876980Seric h->h_flags = hi->hi_flags | H_DEFAULT; 18810689Seric clrbitmap(h->h_mflags); 1896980Seric *hp = h; 1906980Seric } 1916980Seric /* 1924091Seric ** HVALUE -- return value of a header. 1934091Seric ** 1944091Seric ** Only "real" fields (i.e., ones that have not been supplied 1954091Seric ** as a default) are used. 1964091Seric ** 1974091Seric ** Parameters: 1984091Seric ** field -- the field name. 1994091Seric ** 2004091Seric ** Returns: 2014091Seric ** pointer to the value part. 2024091Seric ** NULL if not found. 2034091Seric ** 2044091Seric ** Side Effects: 2059382Seric ** none. 2064091Seric */ 2074091Seric 2084091Seric char * 2094091Seric hvalue(field) 2104091Seric char *field; 2114091Seric { 2124091Seric register HDR *h; 2134091Seric 2146908Seric for (h = CurEnv->e_header; h != NULL; h = h->h_link) 2154091Seric { 2164091Seric if (!bitset(H_DEFAULT, h->h_flags) && strcmp(h->h_field, field) == 0) 2174091Seric return (h->h_value); 2184091Seric } 2194091Seric return (NULL); 2204091Seric } 2214091Seric /* 2224091Seric ** ISHEADER -- predicate telling if argument is a header. 2234091Seric ** 2244319Seric ** A line is a header if it has a single word followed by 2254319Seric ** optional white space followed by a colon. 2264319Seric ** 2274091Seric ** Parameters: 2284091Seric ** s -- string to check for possible headerness. 2294091Seric ** 2304091Seric ** Returns: 2314091Seric ** TRUE if s is a header. 2324091Seric ** FALSE otherwise. 2334091Seric ** 2344091Seric ** Side Effects: 2354091Seric ** none. 2364091Seric */ 2374091Seric 2384091Seric bool 2394091Seric isheader(s) 2404091Seric register char *s; 2414091Seric { 2429382Seric while (*s > ' ' && *s != ':' && *s != '\0') 2434091Seric s++; 2449382Seric 2459382Seric /* following technically violates RFC822 */ 2464091Seric while (isspace(*s)) 2474091Seric s++; 2489382Seric 2494091Seric return (*s == ':'); 2504091Seric } 2515919Seric /* 2527783Seric ** EATHEADER -- run through the stored header and extract info. 2537783Seric ** 2547783Seric ** Parameters: 2559382Seric ** e -- the envelope to process. 2567783Seric ** 2577783Seric ** Returns: 2587783Seric ** none. 2597783Seric ** 2607783Seric ** Side Effects: 2617783Seric ** Sets a bunch of global variables from information 2629382Seric ** in the collected header. 2639382Seric ** Aborts the message if the hop count is exceeded. 2647783Seric */ 2657783Seric 2669382Seric eatheader(e) 2679382Seric register ENVELOPE *e; 2687783Seric { 2697783Seric register HDR *h; 2707783Seric register char *p; 2719382Seric int hopcnt = 0; 2727783Seric 2739382Seric #ifdef DEBUG 2749382Seric if (tTd(32, 1)) 2759382Seric printf("----- collected header -----\n"); 2769382Seric #endif DEBUG 2779382Seric for (h = e->e_header; h != NULL; h = h->h_link) 2787783Seric { 2799382Seric #ifdef DEBUG 2807783Seric extern char *capitalize(); 2817783Seric 2829382Seric if (tTd(32, 1)) 2837783Seric printf("%s: %s\n", capitalize(h->h_field), h->h_value); 2849382Seric #endif DEBUG 28511414Seric /* count the number of times it has been processed */ 2869382Seric if (bitset(H_TRACE, h->h_flags)) 2879382Seric hopcnt++; 28811414Seric 28911414Seric /* send to this person if we so desire */ 29011414Seric if (GrabTo && bitset(H_RCPT, h->h_flags) && 29111414Seric !bitset(H_DEFAULT, h->h_flags) && 29211414Seric (!bitset(EF_RESENT, CurEnv->e_flags) || bitset(H_RESENT, h->h_flags))) 29311414Seric { 29411414Seric sendtolist(h->h_value, (ADDRESS *) NULL, &CurEnv->e_sendqueue); 29511414Seric } 29611414Seric 29711414Seric /* log the message-id */ 29811290Seric #ifdef LOG 29913103Seric if (!QueueRun && LogLevel > 8 && h->h_value != NULL && 30011299Seric strcmp(h->h_field, "message-id") == 0) 30111290Seric { 30211290Seric char buf[MAXNAME]; 30311290Seric 30411290Seric p = h->h_value; 30511290Seric if (bitset(H_DEFAULT, h->h_flags)) 30611290Seric { 30711290Seric expand(p, buf, &buf[sizeof buf], e); 30811290Seric p = buf; 30911290Seric } 31011290Seric syslog(LOG_INFO, "%s: message-id=%s", e->e_id, p); 31111290Seric } 31211290Seric #endif LOG 3139382Seric } 3149382Seric #ifdef DEBUG 3159382Seric if (tTd(32, 1)) 3167783Seric printf("----------------------------\n"); 3179382Seric #endif DEBUG 3187783Seric 3199382Seric /* store hop count */ 3209382Seric if (hopcnt > e->e_hopcount) 3219382Seric e->e_hopcount = hopcnt; 3229382Seric 3237783Seric /* message priority */ 3249382Seric p = hvalue("precedence"); 3259382Seric if (p != NULL) 3269382Seric e->e_class = priencode(p); 3277783Seric if (!QueueRun) 328*21059Seric e->e_msgpriority = e->e_msgsize + e->e_ctime - e->e_class * WKPRIFACT; 3297783Seric 3308066Seric /* return receipt to */ 3318066Seric p = hvalue("return-receipt-to"); 3327783Seric if (p != NULL) 3339382Seric e->e_receiptto = p; 3347783Seric 3358253Seric /* errors to */ 3368253Seric p = hvalue("errors-to"); 3378253Seric if (p != NULL) 3389620Seric sendtolist(p, (ADDRESS *) NULL, &e->e_errorqueue); 3398253Seric 3407783Seric /* from person */ 3419285Seric if (OpMode == MD_ARPAFTP) 3428066Seric { 3438066Seric register struct hdrinfo *hi = HdrInfo; 3447783Seric 3458066Seric for (p = NULL; p == NULL && hi->hi_field != NULL; hi++) 3468066Seric { 3478066Seric if (bitset(H_FROM, hi->hi_flags)) 3488066Seric p = hvalue(hi->hi_field); 3498066Seric } 3508066Seric if (p != NULL) 3519382Seric setsender(p); 3528066Seric } 3538066Seric 3547783Seric /* full name of from person */ 3557783Seric p = hvalue("full-name"); 3567783Seric if (p != NULL) 3579382Seric define('x', p, e); 3587783Seric 3597783Seric /* date message originated */ 3607783Seric p = hvalue("posted-date"); 3617783Seric if (p == NULL) 3627783Seric p = hvalue("date"); 3637783Seric if (p != NULL) 3647783Seric { 3659382Seric define('a', p, e); 3667783Seric /* we don't have a good way to do canonical conversion .... 3679382Seric define('d', newstr(arpatounix(p)), e); 3687783Seric .... so we will ignore the problem for the time being */ 3697783Seric } 37011290Seric 37111290Seric /* 37211290Seric ** Log collection information. 37311290Seric */ 37411290Seric 37511290Seric # ifdef LOG 37611299Seric if (!QueueRun && LogLevel > 1) 37711290Seric { 37811290Seric syslog(LOG_INFO, "%s: from=%s, size=%ld, class=%d\n", 37911290Seric CurEnv->e_id, CurEnv->e_from.q_paddr, CurEnv->e_msgsize, 38011290Seric CurEnv->e_class); 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 extern bool sameword(); 4027783Seric 4038253Seric for (i = 0; i < NumPriorities; i++) 4047783Seric { 4058253Seric if (sameword(p, Priorities[i].pri_name)) 4068253Seric return (Priorities[i].pri_val); 4077783Seric } 4088253Seric 4098253Seric /* unknown priority */ 4108253Seric return (0); 4117783Seric } 4127783Seric /* 4137890Seric ** CRACKADDR -- parse an address and turn it into a macro 4147783Seric ** 4157783Seric ** This doesn't actually parse the address -- it just extracts 4167783Seric ** it and replaces it with "$g". The parse is totally ad hoc 4177783Seric ** and isn't even guaranteed to leave something syntactically 4187783Seric ** identical to what it started with. However, it does leave 4197783Seric ** something semantically identical. 4207783Seric ** 4217783Seric ** The process is kind of strange. There are a number of 4227783Seric ** interesting cases: 4237783Seric ** 1. comment <address> comment ==> comment <$g> comment 4247783Seric ** 2. address ==> address 4257783Seric ** 3. address (comment) ==> $g (comment) 4267783Seric ** 4. (comment) address ==> (comment) $g 4277783Seric ** And then there are the hard cases.... 4287783Seric ** 5. add (comment) ress ==> $g (comment) 4297783Seric ** 6. comment <address (comment)> ==> comment <$g (comment)> 4307783Seric ** 7. .... etc .... 4317783Seric ** 4327783Seric ** Parameters: 4337890Seric ** addr -- the address to be cracked. 4347783Seric ** 4357783Seric ** Returns: 4367783Seric ** a pointer to the new version. 4377783Seric ** 4387783Seric ** Side Effects: 4397890Seric ** none. 4407783Seric ** 4417783Seric ** Warning: 4427783Seric ** The return value is saved in local storage and should 4437783Seric ** be copied if it is to be reused. 4447783Seric */ 4457783Seric 4467783Seric char * 4477890Seric crackaddr(addr) 4487890Seric register char *addr; 4497783Seric { 4507783Seric register char *p; 4517783Seric register int i; 4527783Seric static char buf[MAXNAME]; 4537783Seric char *rhs; 4547783Seric bool gotaddr; 4557783Seric register char *bp; 4567783Seric 4577783Seric # ifdef DEBUG 4587783Seric if (tTd(33, 1)) 4597890Seric printf("crackaddr(%s)\n", addr); 4607783Seric # endif DEBUG 4617783Seric 4627783Seric strcpy(buf, ""); 4637783Seric rhs = NULL; 4647783Seric 4658082Seric /* strip leading spaces */ 4668082Seric while (*addr != '\0' && isspace(*addr)) 4678082Seric addr++; 4688082Seric 4697783Seric /* 4707783Seric ** See if we have anything in angle brackets. If so, that is 4717783Seric ** the address part, and the rest is the comment. 4727783Seric */ 4737783Seric 4747890Seric p = index(addr, '<'); 4757783Seric if (p != NULL) 4767783Seric { 4777890Seric /* copy the beginning of the addr field to the buffer */ 4787783Seric *p = '\0'; 4797890Seric strcpy(buf, addr); 4807783Seric strcat(buf, "<"); 4818082Seric *p++ = '<'; 4827783Seric 4838082Seric /* skip spaces */ 4848082Seric while (isspace(*p)) 4858082Seric p++; 4868082Seric 4877783Seric /* find the matching right angle bracket */ 4888082Seric addr = p; 4897783Seric for (i = 0; *p != '\0'; p++) 4907783Seric { 4917783Seric switch (*p) 4927783Seric { 4937783Seric case '<': 4947783Seric i++; 4957783Seric break; 4967783Seric 4977783Seric case '>': 4987783Seric i--; 4997783Seric break; 5007783Seric } 5017783Seric if (i < 0) 5027783Seric break; 5037783Seric } 5047783Seric 5057783Seric /* p now points to the closing quote (or a null byte) */ 5067783Seric if (*p != '\0') 5077783Seric { 5087783Seric /* make rhs point to the extra stuff at the end */ 5097783Seric rhs = p; 5107783Seric *p++ = '\0'; 5117783Seric } 5127783Seric } 5137783Seric 5147783Seric /* 5157944Seric ** Now parse the real address part. "addr" points to the (null 5167783Seric ** terminated) version of what we are inerested in; rhs points 5177783Seric ** to the extra stuff at the end of the line, if any. 5187783Seric */ 5197783Seric 5207890Seric p = addr; 5217783Seric 5227783Seric /* now strip out comments */ 5237783Seric bp = &buf[strlen(buf)]; 5247783Seric gotaddr = FALSE; 5257783Seric for (; *p != '\0'; p++) 5267783Seric { 5277783Seric if (*p == '(') 5287783Seric { 5297783Seric /* copy to matching close paren */ 5307783Seric *bp++ = *p++; 5317783Seric for (i = 0; *p != '\0'; p++) 5327783Seric { 5337783Seric *bp++ = *p; 5347783Seric switch (*p) 5357783Seric { 5367783Seric case '(': 5377783Seric i++; 5387783Seric break; 5397783Seric 5407783Seric case ')': 5417783Seric i--; 5427783Seric break; 5437783Seric } 5447783Seric if (i < 0) 5457783Seric break; 5467783Seric } 5477783Seric continue; 5487783Seric } 5497783Seric 5507783Seric /* 5517783Seric ** If this is the first "real" character we have seen, 5527783Seric ** then we put the "$g" in the buffer now. 5537783Seric */ 5547783Seric 5557783Seric if (isspace(*p)) 5567783Seric *bp++ = *p; 5577783Seric else if (!gotaddr) 5587783Seric { 55916148Seric strcpy(bp, "\001g"); 5607783Seric bp += 2; 5617783Seric gotaddr = TRUE; 5627783Seric } 5637783Seric } 5647783Seric 5657944Seric /* hack, hack.... strip trailing blanks */ 5667944Seric do 5677944Seric { 5687944Seric *bp-- = '\0'; 5697944Seric } while (isspace(*bp)); 5707944Seric bp++; 5717783Seric 5727944Seric /* put any right hand side back on */ 5737783Seric if (rhs != NULL) 5747783Seric { 5757783Seric *rhs = '>'; 5767783Seric strcpy(bp, rhs); 5777783Seric } 5787783Seric 5797783Seric # ifdef DEBUG 5807783Seric if (tTd(33, 1)) 5817944Seric printf("crackaddr=>`%s'\n", buf); 5827783Seric # endif DEBUG 5837783Seric 5847783Seric return (buf); 5857783Seric } 5869382Seric /* 5879382Seric ** PUTHEADER -- put the header part of a message from the in-core copy 5889382Seric ** 5899382Seric ** Parameters: 5909382Seric ** fp -- file to put it on. 5919382Seric ** m -- mailer to use. 5929382Seric ** e -- envelope to use. 5939382Seric ** 5949382Seric ** Returns: 5959382Seric ** none. 5969382Seric ** 5979382Seric ** Side Effects: 5989382Seric ** none. 5999382Seric */ 6009382Seric 60110176Seric putheader(fp, m, e) 6029382Seric register FILE *fp; 6039382Seric register MAILER *m; 6049382Seric register ENVELOPE *e; 6059382Seric { 6069382Seric char buf[BUFSIZ]; 6079382Seric register HDR *h; 6089382Seric extern char *arpadate(); 6099382Seric extern char *capitalize(); 6109382Seric char obuf[MAXLINE]; 6119382Seric 6129382Seric for (h = e->e_header; h != NULL; h = h->h_link) 6139382Seric { 6149382Seric register char *p; 61510689Seric extern bool bitintersect(); 6169382Seric 6179382Seric if (bitset(H_CHECK|H_ACHECK, h->h_flags) && 61810689Seric !bitintersect(h->h_mflags, m->m_flags)) 6199382Seric continue; 6209382Seric 62111414Seric /* handle Resent-... headers specially */ 62211414Seric if (bitset(H_RESENT, h->h_flags) && !bitset(EF_RESENT, e->e_flags)) 62311414Seric continue; 62411414Seric 6259382Seric p = h->h_value; 6269382Seric if (bitset(H_DEFAULT, h->h_flags)) 6279382Seric { 6289382Seric /* macro expand value if generated internally */ 6299382Seric expand(p, buf, &buf[sizeof buf], e); 6309382Seric p = buf; 6319382Seric if (p == NULL || *p == '\0') 6329382Seric continue; 6339382Seric } 6349382Seric 6359382Seric if (bitset(H_FROM|H_RCPT, h->h_flags)) 6369382Seric { 6379382Seric /* address field */ 6389382Seric bool oldstyle = bitset(EF_OLDSTYLE, e->e_flags); 6399382Seric 6409382Seric if (bitset(H_FROM, h->h_flags)) 6419382Seric oldstyle = FALSE; 64210176Seric commaize(h, p, fp, oldstyle, m); 6439382Seric } 6449382Seric else 6459382Seric { 6469382Seric /* vanilla header line */ 64712159Seric register char *nlp; 64812159Seric 64912159Seric (void) sprintf(obuf, "%s: ", capitalize(h->h_field)); 65012159Seric while ((nlp = index(p, '\n')) != NULL) 65112159Seric { 65212159Seric *nlp = '\0'; 65312159Seric (void) strcat(obuf, p); 65412159Seric *nlp = '\n'; 65512159Seric putline(obuf, fp, m); 65612159Seric p = ++nlp; 65712161Seric obuf[0] = '\0'; 65812159Seric } 65912159Seric (void) strcat(obuf, p); 66010176Seric putline(obuf, fp, m); 6619382Seric } 6629382Seric } 6639382Seric } 6649382Seric /* 6659382Seric ** COMMAIZE -- output a header field, making a comma-translated list. 6669382Seric ** 6679382Seric ** Parameters: 6689382Seric ** h -- the header field to output. 6699382Seric ** p -- the value to put in it. 6709382Seric ** fp -- file to put it to. 6719382Seric ** oldstyle -- TRUE if this is an old style header. 6729382Seric ** m -- a pointer to the mailer descriptor. If NULL, 6739382Seric ** don't transform the name at all. 6749382Seric ** 6759382Seric ** Returns: 6769382Seric ** none. 6779382Seric ** 6789382Seric ** Side Effects: 6799382Seric ** outputs "p" to file "fp". 6809382Seric */ 6819382Seric 68210176Seric commaize(h, p, fp, oldstyle, m) 6839382Seric register HDR *h; 6849382Seric register char *p; 6859382Seric FILE *fp; 6869382Seric bool oldstyle; 6879382Seric register MAILER *m; 6889382Seric { 6899382Seric register char *obp; 6909382Seric int opos; 6919382Seric bool firstone = TRUE; 69211157Seric char obuf[MAXLINE + 3]; 6939382Seric 6949382Seric /* 6959382Seric ** Output the address list translated by the 6969382Seric ** mailer and with commas. 6979382Seric */ 6989382Seric 6999382Seric # ifdef DEBUG 7009382Seric if (tTd(14, 2)) 7019382Seric printf("commaize(%s: %s)\n", h->h_field, p); 7029382Seric # endif DEBUG 7039382Seric 7049382Seric obp = obuf; 7059382Seric (void) sprintf(obp, "%s: ", capitalize(h->h_field)); 7069382Seric opos = strlen(h->h_field) + 2; 7079382Seric obp += opos; 7089382Seric 7099382Seric /* 7109382Seric ** Run through the list of values. 7119382Seric */ 7129382Seric 7139382Seric while (*p != '\0') 7149382Seric { 7159382Seric register char *name; 7169382Seric char savechar; 7179382Seric extern char *remotename(); 7189382Seric extern char *DelimChar; /* defined in prescan */ 7199382Seric 7209382Seric /* 7219382Seric ** Find the end of the name. New style names 7229382Seric ** end with a comma, old style names end with 7239382Seric ** a space character. However, spaces do not 7249382Seric ** necessarily delimit an old-style name -- at 7259382Seric ** signs mean keep going. 7269382Seric */ 7279382Seric 7289382Seric /* find end of name */ 7299382Seric while (isspace(*p) || *p == ',') 7309382Seric p++; 7319382Seric name = p; 7329382Seric for (;;) 7339382Seric { 7349382Seric char *oldp; 73516909Seric char pvpbuf[PSBUFSIZE]; 7369382Seric extern bool isatword(); 7379382Seric extern char **prescan(); 7389382Seric 73916909Seric (void) prescan(p, oldstyle ? ' ' : ',', pvpbuf); 7409382Seric p = DelimChar; 7419382Seric 7429382Seric /* look to see if we have an at sign */ 7439382Seric oldp = p; 7449382Seric while (*p != '\0' && isspace(*p)) 7459382Seric p++; 7469382Seric 7479382Seric if (*p != '@' && !isatword(p)) 7489382Seric { 7499382Seric p = oldp; 7509382Seric break; 7519382Seric } 7529382Seric p += *p == '@' ? 1 : 2; 7539382Seric while (*p != '\0' && isspace(*p)) 7549382Seric p++; 7559382Seric } 7569382Seric /* at the end of one complete name */ 7579382Seric 7589382Seric /* strip off trailing white space */ 7599382Seric while (p >= name && (isspace(*p) || *p == ',' || *p == '\0')) 7609382Seric p--; 7619382Seric if (++p == name) 7629382Seric continue; 7639382Seric savechar = *p; 7649382Seric *p = '\0'; 7659382Seric 7669382Seric /* translate the name to be relative */ 76710309Seric name = remotename(name, m, bitset(H_FROM, h->h_flags), FALSE); 7689382Seric if (*name == '\0') 7699382Seric { 7709382Seric *p = savechar; 7719382Seric continue; 7729382Seric } 7739382Seric 7749382Seric /* output the name with nice formatting */ 7759382Seric opos += qstrlen(name); 7769382Seric if (!firstone) 7779382Seric opos += 2; 7789382Seric if (opos > 78 && !firstone) 7799382Seric { 78010178Seric (void) strcpy(obp, ",\n"); 78110176Seric putline(obuf, fp, m); 7829382Seric obp = obuf; 7839382Seric (void) sprintf(obp, " "); 78410161Seric opos = strlen(obp); 78510161Seric obp += opos; 78610161Seric opos += qstrlen(name); 7879382Seric } 7889382Seric else if (!firstone) 7899382Seric { 7909382Seric (void) sprintf(obp, ", "); 7919382Seric obp += 2; 7929382Seric } 7939382Seric 7949382Seric /* strip off quote bits as we output */ 79511157Seric while (*name != '\0' && obp < &obuf[MAXLINE]) 7969382Seric { 7979382Seric if (bitset(0200, *name)) 7989382Seric *obp++ = '\\'; 7999382Seric *obp++ = *name++ & ~0200; 8009382Seric } 8019382Seric firstone = FALSE; 8029382Seric *p = savechar; 8039382Seric } 8049382Seric (void) strcpy(obp, "\n"); 80510176Seric putline(obuf, fp, m); 8069382Seric } 8079382Seric /* 8089382Seric ** ISATWORD -- tell if the word we are pointing to is "at". 8099382Seric ** 8109382Seric ** Parameters: 8119382Seric ** p -- word to check. 8129382Seric ** 8139382Seric ** Returns: 8149382Seric ** TRUE -- if p is the word at. 8159382Seric ** FALSE -- otherwise. 8169382Seric ** 8179382Seric ** Side Effects: 8189382Seric ** none. 8199382Seric */ 8209382Seric 8219382Seric bool 8229382Seric isatword(p) 8239382Seric register char *p; 8249382Seric { 8259382Seric extern char lower(); 8269382Seric 8279382Seric if (lower(p[0]) == 'a' && lower(p[1]) == 't' && 8289382Seric p[2] != '\0' && isspace(p[2])) 8299382Seric return (TRUE); 8309382Seric return (FALSE); 8319382Seric } 832