122976Smiriam /* 234921Sbostic * Copyright (c) 1983 Eric P. Allman 333730Sbostic * Copyright (c) 1988 Regents of the University of California. 433730Sbostic * All rights reserved. 533730Sbostic * 642828Sbostic * %sccs.include.redist.c% 733730Sbostic */ 822976Smiriam 922976Smiriam #ifndef lint 10*56795Seric static char sccsid[] = "@(#)parseaddr.c 5.25 (Berkeley) 11/14/92"; 1133730Sbostic #endif /* not lint */ 1222976Smiriam 1356678Seric # include "sendmail.h" 14297Seric 15297Seric /* 169888Seric ** PARSEADDR -- Parse an address 17297Seric ** 18297Seric ** Parses an address and breaks it up into three parts: a 19297Seric ** net to transmit the message on, the host to transmit it 20297Seric ** to, and a user on that host. These are loaded into an 212973Seric ** ADDRESS header with the values squirreled away if necessary. 22297Seric ** The "user" part may not be a real user; the process may 23297Seric ** just reoccur on that machine. For example, on a machine 24297Seric ** with an arpanet connection, the address 25297Seric ** csvax.bill@berkeley 26297Seric ** will break up to a "user" of 'csvax.bill' and a host 27297Seric ** of 'berkeley' -- to be transmitted over the arpanet. 28297Seric ** 29297Seric ** Parameters: 30297Seric ** addr -- the address to parse. 31297Seric ** a -- a pointer to the address descriptor buffer. 32297Seric ** If NULL, a header will be created. 33297Seric ** copyf -- determines what shall be copied: 34297Seric ** -1 -- don't copy anything. The printname 35297Seric ** (q_paddr) is just addr, and the 36297Seric ** user & host are allocated internally 37297Seric ** to parse. 38297Seric ** 0 -- copy out the parsed user & host, but 39297Seric ** don't copy the printname. 40297Seric ** +1 -- copy everything. 4111445Seric ** delim -- the character to terminate the address, passed 4211445Seric ** to prescan. 4356678Seric ** e -- the envelope that will contain this address. 44297Seric ** 45297Seric ** Returns: 46297Seric ** A pointer to the address descriptor header (`a' if 47297Seric ** `a' is non-NULL). 48297Seric ** NULL on error. 49297Seric ** 50297Seric ** Side Effects: 51297Seric ** none 52297Seric */ 53297Seric 549374Seric /* following delimiters are inherent to the internal algorithms */ 5516155Seric # define DELIMCHARS "\001()<>,;\\\"\r\n" /* word delimiters */ 562091Seric 572973Seric ADDRESS * 5856678Seric parseaddr(addr, a, copyf, delim, e) 59297Seric char *addr; 602973Seric register ADDRESS *a; 61297Seric int copyf; 6211445Seric char delim; 6356678Seric register ENVELOPE *e; 64297Seric { 653149Seric register char **pvp; 6616914Seric char pvpbuf[PSBUFSIZE]; 6756678Seric extern char **prescan(); 6856678Seric extern ADDRESS *buildaddr(); 69297Seric 70297Seric /* 71297Seric ** Initialize and prescan address. 72297Seric */ 73297Seric 7456678Seric e->e_to = addr; 757675Seric if (tTd(20, 1)) 769888Seric printf("\n--parseaddr(%s)\n", addr); 773188Seric 7816914Seric pvp = prescan(addr, delim, pvpbuf); 793149Seric if (pvp == NULL) 8056729Seric { 8156729Seric if (tTd(20, 1)) 8256729Seric printf("parseaddr-->NULL\n"); 83297Seric return (NULL); 8456729Seric } 85297Seric 86297Seric /* 873149Seric ** Apply rewriting rules. 887889Seric ** Ruleset 0 does basic parsing. It must resolve. 89297Seric */ 90297Seric 918181Seric rewrite(pvp, 3); 924070Seric rewrite(pvp, 0); 93297Seric 943149Seric /* 953149Seric ** See if we resolved to a real mailer. 963149Seric */ 97297Seric 983149Seric if (pvp[0][0] != CANONNET) 993149Seric { 1003149Seric setstat(EX_USAGE); 1013149Seric usrerr("cannot resolve name"); 1023149Seric return (NULL); 103297Seric } 104297Seric 105297Seric /* 1063149Seric ** Build canonical address from pvp. 107297Seric */ 108297Seric 1093149Seric a = buildaddr(pvp, a); 1104279Seric if (a == NULL) 1114279Seric return (NULL); 112297Seric 113297Seric /* 1143149Seric ** Make local copies of the host & user and then 1153149Seric ** transport them out. 116297Seric */ 117297Seric 11856678Seric allocaddr(a, copyf, addr); 11956678Seric 12056678Seric /* 12156678Seric ** Compute return value. 12256678Seric */ 12356678Seric 12456678Seric if (tTd(20, 1)) 1258078Seric { 12656678Seric printf("parseaddr-->"); 12756678Seric printaddr(a, FALSE); 12856678Seric } 12956678Seric 13056678Seric return (a); 13156678Seric } 13256678Seric /* 13356678Seric ** ALLOCADDR -- do local allocations of address on demand. 13456678Seric ** 13556678Seric ** Also lowercases the host name if requested. 13656678Seric ** 13756678Seric ** Parameters: 13856678Seric ** a -- the address to reallocate. 13956678Seric ** copyf -- the copy flag (see parseaddr for description). 14056678Seric ** paddr -- the printname of the address. 14156678Seric ** 14256678Seric ** Returns: 14356678Seric ** none. 14456678Seric ** 14556678Seric ** Side Effects: 14656678Seric ** Copies portions of a into local buffers as requested. 14756678Seric */ 14856678Seric 14956678Seric allocaddr(a, copyf, paddr) 15056678Seric register ADDRESS *a; 15156678Seric int copyf; 15256678Seric char *paddr; 15356678Seric { 15456678Seric register MAILER *m = a->q_mailer; 15556678Seric 15656678Seric if (copyf > 0 && paddr != NULL) 15756678Seric { 15856678Seric extern char *DelimChar; 1598078Seric char savec = *DelimChar; 1608078Seric 1618078Seric *DelimChar = '\0'; 16256678Seric a->q_paddr = newstr(paddr); 1638078Seric *DelimChar = savec; 1648078Seric } 165297Seric else 16656678Seric a->q_paddr = paddr; 16724944Seric 16824944Seric if (a->q_user == NULL) 16924944Seric a->q_user = ""; 17024944Seric if (a->q_host == NULL) 17124944Seric a->q_host = ""; 17224944Seric 1733149Seric if (copyf >= 0) 174297Seric { 17524944Seric a->q_host = newstr(a->q_host); 1763149Seric if (a->q_user != a->q_paddr) 1773149Seric a->q_user = newstr(a->q_user); 178297Seric } 179297Seric 18056678Seric if (a->q_paddr == NULL) 18156678Seric a->q_paddr = a->q_user; 18256678Seric 183297Seric /* 18416202Seric ** Convert host name to lower case if requested. 18516202Seric ** User name will be done later. 18616202Seric */ 18716202Seric 18816202Seric if (!bitnset(M_HST_UPPER, m->m_flags)) 18916202Seric makelower(a->q_host); 190297Seric } 191297Seric /* 19216162Seric ** LOWERADDR -- map UPPER->lower case on addresses as requested. 19316162Seric ** 19416162Seric ** Parameters: 19516162Seric ** a -- address to be mapped. 19616162Seric ** 19716162Seric ** Returns: 19816162Seric ** none. 19916162Seric ** 20016162Seric ** Side Effects: 20116162Seric ** none. 20216162Seric */ 20316162Seric 20416162Seric loweraddr(a) 20516162Seric register ADDRESS *a; 20616162Seric { 20716162Seric register MAILER *m = a->q_mailer; 20816162Seric 20916162Seric if (!bitnset(M_USR_UPPER, m->m_flags)) 21016162Seric makelower(a->q_user); 21116162Seric } 21216162Seric /* 213297Seric ** PRESCAN -- Prescan name and make it canonical 214297Seric ** 2159374Seric ** Scans a name and turns it into a set of tokens. This process 2169374Seric ** deletes blanks and comments (in parentheses). 217297Seric ** 218297Seric ** This routine knows about quoted strings and angle brackets. 219297Seric ** 220297Seric ** There are certain subtleties to this routine. The one that 221297Seric ** comes to mind now is that backslashes on the ends of names 222297Seric ** are silently stripped off; this is intentional. The problem 223297Seric ** is that some versions of sndmsg (like at LBL) set the kill 224297Seric ** character to something other than @ when reading addresses; 225297Seric ** so people type "csvax.eric\@berkeley" -- which screws up the 226297Seric ** berknet mailer. 227297Seric ** 228297Seric ** Parameters: 229297Seric ** addr -- the name to chomp. 230297Seric ** delim -- the delimiter for the address, normally 231297Seric ** '\0' or ','; \0 is accepted in any case. 23215284Seric ** If '\t' then we are reading the .cf file. 23316914Seric ** pvpbuf -- place to put the saved text -- note that 23416914Seric ** the pointers are static. 235297Seric ** 236297Seric ** Returns: 2373149Seric ** A pointer to a vector of tokens. 238297Seric ** NULL on error. 239297Seric ** 240297Seric ** Side Effects: 24125279Seric ** sets DelimChar to point to the character matching 'delim'. 242297Seric */ 243297Seric 2448078Seric /* states and character types */ 2458078Seric # define OPR 0 /* operator */ 2468078Seric # define ATM 1 /* atom */ 2478078Seric # define QST 2 /* in quoted string */ 2488078Seric # define SPC 3 /* chewing up spaces */ 2498078Seric # define ONE 4 /* pick up one character */ 2503149Seric 2518078Seric # define NSTATES 5 /* number of states */ 2528078Seric # define TYPE 017 /* mask to select state type */ 2538078Seric 2548078Seric /* meta bits for table */ 2558078Seric # define M 020 /* meta character; don't pass through */ 2568078Seric # define B 040 /* cause a break */ 2578078Seric # define MB M|B /* meta-break */ 2588078Seric 2598078Seric static short StateTab[NSTATES][NSTATES] = 2608078Seric { 2618087Seric /* oldst chtype> OPR ATM QST SPC ONE */ 2629051Seric /*OPR*/ OPR|B, ATM|B, QST|B, SPC|MB, ONE|B, 2639051Seric /*ATM*/ OPR|B, ATM, QST|B, SPC|MB, ONE|B, 2649051Seric /*QST*/ QST, QST, OPR, QST, QST, 2658078Seric /*SPC*/ OPR, ATM, QST, SPC|M, ONE, 2668078Seric /*ONE*/ OPR, OPR, OPR, OPR, OPR, 2678078Seric }; 2688078Seric 2698078Seric # define NOCHAR -1 /* signal nothing in lookahead token */ 2708078Seric 27156678Seric char *DelimChar; /* set to point to the delimiter */ 27256678Seric 2733149Seric char ** 27416914Seric prescan(addr, delim, pvpbuf) 275297Seric char *addr; 276297Seric char delim; 27716914Seric char pvpbuf[]; 278297Seric { 279297Seric register char *p; 2808078Seric register char *q; 2819346Seric register int c; 2823149Seric char **avp; 283297Seric bool bslashmode; 284297Seric int cmntcnt; 2858423Seric int anglecnt; 2863149Seric char *tok; 2878078Seric int state; 2888078Seric int newstate; 2898078Seric static char *av[MAXATOM+1]; 29056678Seric extern int errno; 291297Seric 29215253Seric /* make sure error messages don't have garbage on them */ 29315253Seric errno = 0; 29415253Seric 29516914Seric q = pvpbuf; 2963149Seric bslashmode = FALSE; 2977800Seric cmntcnt = 0; 2988423Seric anglecnt = 0; 2993149Seric avp = av; 30056678Seric state = ATM; 3018078Seric c = NOCHAR; 3028078Seric p = addr; 30356764Seric if (tTd(22, 11)) 304297Seric { 3058078Seric printf("prescan: "); 3068078Seric xputs(p); 30723109Seric (void) putchar('\n'); 3088078Seric } 3098078Seric 3108078Seric do 3118078Seric { 3123149Seric /* read a token */ 3133149Seric tok = q; 3148078Seric for (;;) 315297Seric { 3168078Seric /* store away any old lookahead character */ 3178078Seric if (c != NOCHAR) 3188078Seric { 31915284Seric /* see if there is room */ 32016914Seric if (q >= &pvpbuf[PSBUFSIZE - 5]) 3218078Seric { 3228078Seric usrerr("Address too long"); 3238078Seric DelimChar = p; 3248078Seric return (NULL); 3258078Seric } 32615284Seric 32715284Seric /* squirrel it away */ 3288078Seric *q++ = c; 3298078Seric } 3308078Seric 3318078Seric /* read a new input character */ 3328078Seric c = *p++; 33356764Seric if (c == '\0' || (c == delim && anglecnt <= 0)) 33456764Seric { 33556764Seric /* diagnose and patch up bad syntax */ 33656764Seric if (state == QST) 33756764Seric { 33856764Seric usrerr("Unbalanced '\"'"); 33956764Seric c = '"'; 34056764Seric } 34156764Seric else if (cmntcnt > 0) 34256764Seric { 34356764Seric usrerr("Unbalanced '('"); 34456764Seric c = ')'; 34556764Seric } 34656764Seric else if (anglecnt > 0) 34756764Seric { 34856764Seric c = '>'; 34956764Seric usrerr("Unbalanced '<'"); 35056764Seric } 35156764Seric else 35256764Seric break; 35315284Seric 35456764Seric p--; 35556764Seric } 35656764Seric 3578078Seric if (tTd(22, 101)) 3588078Seric printf("c=%c, s=%d; ", c, state); 3598078Seric 3603149Seric /* chew up special characters */ 3613149Seric *q = '\0'; 3623149Seric if (bslashmode) 3633149Seric { 36424944Seric /* kludge \! for naive users */ 36524944Seric if (c != '!') 36656678Seric *q++ = '\\'; 3673149Seric bslashmode = FALSE; 36856678Seric continue; 3693149Seric } 37056678Seric 37156678Seric if (c == '\\') 3723149Seric { 3733149Seric bslashmode = TRUE; 3748078Seric c = NOCHAR; 37556678Seric continue; 3763149Seric } 37756678Seric else if (state == QST) 3788514Seric { 3798514Seric /* do nothing, just avoid next clauses */ 3808514Seric } 3818078Seric else if (c == '(') 3824100Seric { 3838078Seric cmntcnt++; 3848078Seric c = NOCHAR; 3854100Seric } 3868078Seric else if (c == ')') 3873149Seric { 3888078Seric if (cmntcnt <= 0) 3893149Seric { 3908078Seric usrerr("Unbalanced ')'"); 3918078Seric DelimChar = p; 3928078Seric return (NULL); 3933149Seric } 3948078Seric else 3958078Seric cmntcnt--; 3968078Seric } 3978078Seric else if (cmntcnt > 0) 3988078Seric c = NOCHAR; 3998423Seric else if (c == '<') 4008423Seric anglecnt++; 4018423Seric else if (c == '>') 4028423Seric { 4038423Seric if (anglecnt <= 0) 4048423Seric { 4058423Seric usrerr("Unbalanced '>'"); 4068423Seric DelimChar = p; 4078423Seric return (NULL); 4088423Seric } 4098423Seric anglecnt--; 4108423Seric } 41111423Seric else if (delim == ' ' && isspace(c)) 41211423Seric c = ' '; 4133149Seric 4148078Seric if (c == NOCHAR) 4158078Seric continue; 4163149Seric 4178078Seric /* see if this is end of input */ 41811405Seric if (c == delim && anglecnt <= 0 && state != QST) 4193149Seric break; 4203149Seric 4218078Seric newstate = StateTab[state][toktype(c)]; 4228078Seric if (tTd(22, 101)) 4238078Seric printf("ns=%02o\n", newstate); 4248078Seric state = newstate & TYPE; 4258078Seric if (bitset(M, newstate)) 4268078Seric c = NOCHAR; 4278078Seric if (bitset(B, newstate)) 4284228Seric break; 429297Seric } 4303149Seric 4313149Seric /* new token */ 4328078Seric if (tok != q) 4331378Seric { 4348078Seric *q++ = '\0'; 4358078Seric if (tTd(22, 36)) 436297Seric { 4378078Seric printf("tok="); 4388078Seric xputs(tok); 43923109Seric (void) putchar('\n'); 440297Seric } 4418078Seric if (avp >= &av[MAXATOM]) 442297Seric { 4438078Seric syserr("prescan: too many tokens"); 4448078Seric DelimChar = p; 4458078Seric return (NULL); 446297Seric } 4478078Seric *avp++ = tok; 448297Seric } 4498423Seric } while (c != '\0' && (c != delim || anglecnt > 0)); 4503149Seric *avp = NULL; 4518078Seric DelimChar = --p; 45256764Seric if (tTd(22, 12)) 45356764Seric { 45456764Seric printf("prescan==>"); 45556764Seric printav(av); 45656764Seric } 45756764Seric if (av[0] != NULL) 4583149Seric return (av); 4593149Seric return (NULL); 4603149Seric } 4613149Seric /* 4623149Seric ** TOKTYPE -- return token type 4633149Seric ** 4643149Seric ** Parameters: 4653149Seric ** c -- the character in question. 4663149Seric ** 4673149Seric ** Returns: 4683149Seric ** Its type. 4693149Seric ** 4703149Seric ** Side Effects: 4713149Seric ** none. 4723149Seric */ 473297Seric 4743149Seric toktype(c) 4753149Seric register char c; 4763149Seric { 4773380Seric static char buf[50]; 4783382Seric static bool firstime = TRUE; 4793380Seric 4803382Seric if (firstime) 4813380Seric { 4823382Seric firstime = FALSE; 48316155Seric expand("\001o", buf, &buf[sizeof buf - 1], CurEnv); 4847005Seric (void) strcat(buf, DELIMCHARS); 4853380Seric } 48656327Seric if (c == MATCHCLASS || c == MATCHREPL || c == MATCHNCLASS) 4878078Seric return (ONE); 4888078Seric if (c == '"') 4898078Seric return (QST); 4904100Seric if (!isascii(c)) 4918078Seric return (ATM); 4928078Seric if (isspace(c) || c == ')') 4938078Seric return (SPC); 494*56795Seric if (iscntrl(c) || strchr(buf, c) != NULL) 4958078Seric return (OPR); 4968078Seric return (ATM); 4973149Seric } 4983149Seric /* 4993149Seric ** REWRITE -- apply rewrite rules to token vector. 5003149Seric ** 5014476Seric ** This routine is an ordered production system. Each rewrite 5024476Seric ** rule has a LHS (called the pattern) and a RHS (called the 5034476Seric ** rewrite); 'rwr' points the the current rewrite rule. 5044476Seric ** 5054476Seric ** For each rewrite rule, 'avp' points the address vector we 5064476Seric ** are trying to match against, and 'pvp' points to the pattern. 5078058Seric ** If pvp points to a special match value (MATCHZANY, MATCHANY, 5089585Seric ** MATCHONE, MATCHCLASS, MATCHNCLASS) then the address in avp 5099585Seric ** matched is saved away in the match vector (pointed to by 'mvp'). 5104476Seric ** 5114476Seric ** When a match between avp & pvp does not match, we try to 5129585Seric ** back out. If we back up over MATCHONE, MATCHCLASS, or MATCHNCLASS 5134476Seric ** we must also back out the match in mvp. If we reach a 5148058Seric ** MATCHANY or MATCHZANY we just extend the match and start 5158058Seric ** over again. 5164476Seric ** 5174476Seric ** When we finally match, we rewrite the address vector 5184476Seric ** and try over again. 5194476Seric ** 5203149Seric ** Parameters: 5213149Seric ** pvp -- pointer to token vector. 5223149Seric ** 5233149Seric ** Returns: 5243149Seric ** none. 5253149Seric ** 5263149Seric ** Side Effects: 5273149Seric ** pvp is modified. 5283149Seric */ 5292091Seric 5303149Seric struct match 5313149Seric { 5324468Seric char **first; /* first token matched */ 5334468Seric char **last; /* last token matched */ 5343149Seric }; 5353149Seric 5364468Seric # define MAXMATCH 9 /* max params per rewrite */ 5373149Seric 5383149Seric 5394070Seric rewrite(pvp, ruleset) 5403149Seric char **pvp; 5414070Seric int ruleset; 5423149Seric { 5433149Seric register char *ap; /* address pointer */ 5443149Seric register char *rp; /* rewrite pointer */ 5453149Seric register char **avp; /* address vector pointer */ 5463149Seric register char **rvp; /* rewrite vector pointer */ 5478058Seric register struct match *mlp; /* cur ptr into mlist */ 5488058Seric register struct rewrite *rwr; /* pointer to current rewrite rule */ 54956678Seric struct match mlist[MAXMATCH]; /* stores match on LHS */ 5503149Seric char *npvp[MAXATOM+1]; /* temporary space for rebuild */ 5513149Seric 5529279Seric if (OpMode == MD_TEST || tTd(21, 2)) 5533149Seric { 5548959Seric printf("rewrite: ruleset %2d input:", ruleset); 55556678Seric printav(pvp); 5563149Seric } 55756678Seric if (ruleset < 0 || ruleset >= MAXRWSETS) 55856326Seric { 55956678Seric syserr("rewrite: illegal ruleset number %d", ruleset); 56056326Seric return; 56156326Seric } 56256678Seric if (pvp == NULL) 56356678Seric return; 56456326Seric 5653149Seric /* 56656678Seric ** Run through the list of rewrite rules, applying 56756678Seric ** any that match. 5683149Seric */ 5693149Seric 5704070Seric for (rwr = RewriteRules[ruleset]; rwr != NULL; ) 5713149Seric { 57256678Seric int loopcount = 0; 57356678Seric 5747675Seric if (tTd(21, 12)) 575297Seric { 5768069Seric printf("-----trying rule:"); 57756678Seric printav(rwr->r_lhs); 5783149Seric } 5793149Seric 5803149Seric /* try to match on this rule */ 5814468Seric mlp = mlist; 5828058Seric rvp = rwr->r_lhs; 5838058Seric avp = pvp; 5848058Seric while ((ap = *avp) != NULL || *rvp != NULL) 5853149Seric { 58656678Seric if (++loopcount > 100) 58752637Seric { 58856678Seric syserr("Infinite loop in ruleset %d", ruleset); 58956678Seric printf("workspace: "); 59056678Seric printav(pvp); 59152637Seric break; 59252637Seric } 5933149Seric rp = *rvp; 5948058Seric if (tTd(21, 35)) 5958058Seric { 59656678Seric printf("operator="); 5978058Seric xputs(ap); 59856678Seric printf(", token="); 5998058Seric xputs(rp); 6008069Seric printf("\n"); 6018058Seric } 60256678Seric if (rp == NULL) 60356326Seric { 6043149Seric /* end-of-pattern before end-of-address */ 6058058Seric goto backup; 60656678Seric } 60756678Seric if (ap == NULL && *rp != MATCHZANY) 60856326Seric { 60956678Seric /* end-of-input */ 61056678Seric break; 611297Seric } 61256326Seric 61356678Seric switch (*rp) 6148058Seric { 61556678Seric register STAB *s; 61656326Seric 61756678Seric case MATCHCLASS: 61856678Seric case MATCHNCLASS: 61956678Seric /* match any token in (not in) a class */ 62056678Seric s = stab(ap, ST_CLASS, ST_FIND); 62156678Seric if (s == NULL || !bitnset(rp[1], s->s_class)) 62256326Seric { 62356678Seric if (*rp == MATCHCLASS) 6249585Seric goto backup; 62556326Seric } 62656678Seric else if (*rp == MATCHNCLASS) 62756678Seric goto backup; 6284060Seric 62956678Seric /* explicit fall-through */ 63056678Seric 63156678Seric case MATCHONE: 63256678Seric case MATCHANY: 63356678Seric /* match exactly one token */ 63456678Seric mlp->first = avp; 63556678Seric mlp->last = avp++; 6368058Seric mlp++; 63756678Seric break; 6388058Seric 63956678Seric case MATCHZANY: 64056678Seric /* match zero or more tokens */ 64156678Seric mlp->first = avp; 64256678Seric mlp->last = avp - 1; 64356678Seric mlp++; 64456678Seric break; 64556326Seric 64656678Seric default: 64756678Seric /* must have exact match */ 64856678Seric if (strcasecmp(rp, ap)) 6498058Seric goto backup; 6504468Seric avp++; 65156678Seric break; 6523149Seric } 6533149Seric 65456678Seric /* successful match on this token */ 6553149Seric rvp++; 6563149Seric continue; 6573149Seric 65856678Seric backup: 65956678Seric /* match failed -- back up */ 66056678Seric while (--rvp >= rwr->r_lhs) 6613149Seric { 66256678Seric rp = *rvp; 66356678Seric if (*rp == MATCHANY || *rp == MATCHZANY) 6644468Seric { 66556678Seric /* extend binding and continue */ 66656678Seric avp = ++mlp[-1].last; 66756678Seric avp++; 66856678Seric rvp++; 66956678Seric break; 6704468Seric } 67156678Seric avp--; 67256678Seric if (*rp == MATCHONE || *rp == MATCHCLASS || 67356678Seric *rp == MATCHNCLASS) 67456678Seric { 67556678Seric /* back out binding */ 67656678Seric mlp--; 67756678Seric } 6783149Seric } 6793149Seric 68056678Seric if (rvp < rwr->r_lhs) 68156678Seric { 68256678Seric /* total failure to match */ 68356326Seric break; 6843149Seric } 685297Seric } 6863149Seric 6873149Seric /* 68856678Seric ** See if we successfully matched 6893149Seric */ 6903149Seric 69156678Seric if (rvp < rwr->r_lhs || *rvp != NULL) 6923149Seric { 6939374Seric if (tTd(21, 10)) 6949374Seric printf("----- rule fails\n"); 6959374Seric rwr = rwr->r_next; 6969374Seric continue; 6979374Seric } 6983149Seric 6999374Seric rvp = rwr->r_rhs; 7009374Seric if (tTd(21, 12)) 7019374Seric { 7029374Seric printf("-----rule matches:"); 70356678Seric printav(rvp); 7049374Seric } 7059374Seric 7069374Seric rp = *rvp; 7079374Seric if (*rp == CANONUSER) 7089374Seric { 7099374Seric rvp++; 7109374Seric rwr = rwr->r_next; 7119374Seric } 7129374Seric else if (*rp == CANONHOST) 7139374Seric { 7149374Seric rvp++; 7159374Seric rwr = NULL; 7169374Seric } 7179374Seric else if (*rp == CANONNET) 7189374Seric rwr = NULL; 7199374Seric 7209374Seric /* substitute */ 7219374Seric for (avp = npvp; *rvp != NULL; rvp++) 7229374Seric { 7239374Seric register struct match *m; 7249374Seric register char **pp; 7259374Seric 7268058Seric rp = *rvp; 72756678Seric if (*rp == MATCHREPL) 7288058Seric { 72916914Seric /* substitute from LHS */ 73016914Seric m = &mlist[rp[1] - '1']; 73156678Seric if (m < mlist || m >= mlp) 7329374Seric { 73356678Seric syserr("rewrite: ruleset %d: replacement $%c out of bounds", 73456326Seric ruleset, rp[1]); 7359374Seric return; 7369374Seric } 73716914Seric if (tTd(21, 15)) 73816914Seric { 73916914Seric printf("$%c:", rp[1]); 74016914Seric pp = m->first; 74156678Seric while (pp <= m->last) 74216914Seric { 74316914Seric printf(" %x=\"", *pp); 74416914Seric (void) fflush(stdout); 74516914Seric printf("%s\"", *pp++); 74616914Seric } 74716914Seric printf("\n"); 74816914Seric } 7499374Seric pp = m->first; 75056678Seric while (pp <= m->last) 7513149Seric { 75216914Seric if (avp >= &npvp[MAXATOM]) 75356678Seric { 75456678Seric syserr("rewrite: expansion too long"); 75556678Seric return; 75656678Seric } 75716914Seric *avp++ = *pp++; 7583149Seric } 7593149Seric } 76016914Seric else 7618226Seric { 76216914Seric /* vanilla replacement */ 7639374Seric if (avp >= &npvp[MAXATOM]) 76416889Seric { 76556678Seric toolong: 76616889Seric syserr("rewrite: expansion too long"); 76716889Seric return; 76816889Seric } 76956678Seric *avp++ = rp; 7708226Seric } 7719374Seric } 7729374Seric *avp++ = NULL; 77316914Seric 77416914Seric /* 77556678Seric ** Check for any hostname/keyword lookups. 77616914Seric */ 77716914Seric 77816914Seric for (rvp = npvp; *rvp != NULL; rvp++) 77916914Seric { 78056678Seric char **hbrvp; 78116914Seric char **xpvp; 78216914Seric int trsize; 78317473Seric char *olddelimchar; 78456678Seric char *replac; 78556678Seric int endtoken; 78656678Seric STAB *map; 78756678Seric char *mapname; 78856678Seric char **key_rvp; 78956678Seric char **arg_rvp; 79056678Seric char **default_rvp; 79156678Seric char buf[MAXNAME + 1]; 79216914Seric char *pvpb1[MAXATOM + 1]; 79317174Seric char pvpbuf[PSBUFSIZE]; 79456678Seric extern char *DelimChar; 79516914Seric 79656678Seric if (**rvp != HOSTBEGIN && **rvp != LOOKUPBEGIN) 79716914Seric continue; 79816914Seric 79916914Seric /* 80056678Seric ** Got a hostname/keyword lookup. 80116914Seric ** 80216914Seric ** This could be optimized fairly easily. 80316914Seric */ 80416914Seric 80516914Seric hbrvp = rvp; 80656678Seric arg_rvp = default_rvp = NULL; 80756678Seric if (**rvp == HOSTBEGIN) 80856327Seric { 80956678Seric endtoken = HOSTEND; 81056678Seric mapname = "host"; 81156327Seric } 81256326Seric else 81356327Seric { 81456678Seric endtoken = LOOKUPEND; 81556678Seric mapname = *++rvp; 81656327Seric } 81756678Seric map = stab(mapname, ST_MAP, ST_FIND); 81856678Seric if (map == NULL) 81956678Seric syserr("rewrite: map %s not found", mapname); 82056678Seric 82156678Seric /* extract the match part */ 82256678Seric key_rvp = ++rvp; 82356678Seric while (*rvp != NULL && **rvp != endtoken) 82453654Seric { 82556678Seric switch (**rvp) 82656678Seric { 82756678Seric case CANONHOST: 82856678Seric *rvp++ = NULL; 82956678Seric arg_rvp = rvp; 83056678Seric break; 83156678Seric 83256678Seric case CANONUSER: 83356678Seric *rvp++ = NULL; 83456678Seric default_rvp = rvp; 83556678Seric break; 83656678Seric 83756678Seric default: 83856678Seric rvp++; 83956678Seric break; 84056678Seric } 84153654Seric } 84216914Seric if (*rvp != NULL) 84316914Seric *rvp++ = NULL; 84416914Seric 84516914Seric /* save the remainder of the input string */ 84616914Seric trsize = (int) (avp - rvp + 1) * sizeof *rvp; 84716914Seric bcopy((char *) rvp, (char *) pvpb1, trsize); 84816914Seric 84956678Seric /* look it up */ 85056678Seric cataddr(key_rvp, buf, sizeof buf); 85156678Seric if (map != NULL && bitset(MF_VALID, map->s_map.map_flags)) 85256678Seric replac = (*map->s_map.map_class->map_lookup)(buf, 85356678Seric sizeof buf - 1, arg_rvp); 85453654Seric else 85556678Seric replac = NULL; 85656678Seric 85756678Seric /* if no replacement, use default */ 85856678Seric if (replac == NULL) 85951317Seric { 86056678Seric if (default_rvp != NULL) 86156678Seric xpvp = default_rvp; 86253654Seric else 86356678Seric xpvp = key_rvp; 86453654Seric } 86556678Seric else 86653654Seric { 86756678Seric /* scan the new replacement */ 86856678Seric olddelimchar = DelimChar; 86956678Seric xpvp = prescan(replac, '\0', pvpbuf); 87056678Seric DelimChar = olddelimchar; 87153654Seric if (xpvp == NULL) 87251317Seric { 87356678Seric syserr("rewrite: cannot prescan map value: %s", replac); 87456678Seric return; 87556678Seric } 87651317Seric } 87751317Seric 87816914Seric /* append it to the token list */ 87956678Seric for (avp = hbrvp; *xpvp != NULL; xpvp++) 88056678Seric { 88117174Seric *avp++ = newstr(*xpvp); 88216920Seric if (avp >= &npvp[MAXATOM]) 88316914Seric goto toolong; 88417174Seric } 88516914Seric 88616914Seric /* restore the old trailing information */ 88756678Seric for (xpvp = pvpb1; (*avp++ = *xpvp++) != NULL; ) 88816920Seric if (avp >= &npvp[MAXATOM]) 88916914Seric goto toolong; 89017174Seric 89156678Seric break; 89216914Seric } 89316914Seric 89416914Seric /* 89516914Seric ** Check for subroutine calls. 89616914Seric */ 89716914Seric 89856678Seric if (*npvp != NULL && **npvp == CALLSUBR) 89956678Seric { 90056678Seric bcopy((char *) &npvp[2], (char *) pvp, 90156678Seric (int) (avp - npvp - 2) * sizeof *avp); 90256678Seric if (tTd(21, 3)) 90356678Seric printf("-----callsubr %s\n", npvp[1]); 90456678Seric rewrite(pvp, atoi(npvp[1])); 90556678Seric } 90656678Seric else 90756678Seric { 90817348Seric bcopy((char *) npvp, (char *) pvp, 90916900Seric (int) (avp - npvp) * sizeof *avp); 91056678Seric } 9119374Seric if (tTd(21, 4)) 9129374Seric { 9139374Seric printf("rewritten as:"); 91456678Seric printav(pvp); 9159374Seric } 916297Seric } 9178069Seric 9189279Seric if (OpMode == MD_TEST || tTd(21, 2)) 9198069Seric { 9208959Seric printf("rewrite: ruleset %2d returns:", ruleset); 92156678Seric printav(pvp); 9228069Seric } 9233149Seric } 9243149Seric /* 9253149Seric ** BUILDADDR -- build address from token vector. 9263149Seric ** 9273149Seric ** Parameters: 9283149Seric ** tv -- token vector. 9293149Seric ** a -- pointer to address descriptor to fill. 9303149Seric ** If NULL, one will be allocated. 9313149Seric ** 9323149Seric ** Returns: 9334279Seric ** NULL if there was an error. 9344279Seric ** 'a' otherwise. 9353149Seric ** 9363149Seric ** Side Effects: 9373149Seric ** fills in 'a' 9383149Seric */ 9393149Seric 94056678Seric ADDRESS * 9413149Seric buildaddr(tv, a) 9423149Seric register char **tv; 9433149Seric register ADDRESS *a; 9443149Seric { 9453149Seric static char buf[MAXNAME]; 9463149Seric struct mailer **mp; 9473149Seric register struct mailer *m; 9483149Seric 9493149Seric if (a == NULL) 9503149Seric a = (ADDRESS *) xalloc(sizeof *a); 95116889Seric bzero((char *) a, sizeof *a); 9523149Seric 9533149Seric /* figure out what net/mailer to use */ 95456678Seric if (**tv != CANONNET) 9554279Seric { 9563149Seric syserr("buildaddr: no net"); 9574279Seric return (NULL); 9584279Seric } 9593149Seric tv++; 96033725Sbostic if (!strcasecmp(*tv, "error")) 9614279Seric { 96210183Seric if (**++tv == CANONHOST) 96310183Seric { 96410183Seric setstat(atoi(*++tv)); 96510183Seric tv++; 96610183Seric } 96710183Seric if (**tv != CANONUSER) 9684279Seric syserr("buildaddr: error: no user"); 96956678Seric buf[0] = '\0'; 9704279Seric while (*++tv != NULL) 9714279Seric { 9724279Seric if (buf[0] != '\0') 9737005Seric (void) strcat(buf, " "); 9747005Seric (void) strcat(buf, *tv); 9754279Seric } 9764279Seric usrerr(buf); 9774279Seric return (NULL); 9784279Seric } 9794598Seric for (mp = Mailer; (m = *mp++) != NULL; ) 9803149Seric { 98133725Sbostic if (!strcasecmp(m->m_name, *tv)) 9823149Seric break; 9833149Seric } 9843149Seric if (m == NULL) 9854279Seric { 98624944Seric syserr("buildaddr: unknown mailer %s", *tv); 9874279Seric return (NULL); 9884279Seric } 9894598Seric a->q_mailer = m; 9903149Seric 9913149Seric /* figure out what host (if any) */ 99256678Seric tv++; 99356678Seric if (!bitnset(M_LOCAL, m->m_flags)) 9943149Seric { 99556678Seric if (**tv++ != CANONHOST) 9964279Seric { 9973149Seric syserr("buildaddr: no host"); 9984279Seric return (NULL); 9994279Seric } 10005704Seric buf[0] = '\0'; 100156678Seric while (*tv != NULL && **tv != CANONUSER) 100256678Seric (void) strcat(buf, *tv++); 10035704Seric a->q_host = newstr(buf); 10043149Seric } 100556678Seric else 100656678Seric a->q_host = NULL; 10073149Seric 10083149Seric /* figure out the user */ 100936615Sbostic if (*tv == NULL || **tv != CANONUSER) 10104279Seric { 10113149Seric syserr("buildaddr: no user"); 10124279Seric return (NULL); 10134279Seric } 101419040Seric 101556678Seric if (m == LocalMailer && tv[1] != NULL && strcmp(tv[1], "@") == 0) 101656678Seric { 101756678Seric tv++; 101856678Seric a->q_flags |= QNOTREMOTE; 101956678Seric } 102051317Seric 102119040Seric /* rewrite according recipient mailer rewriting rules */ 102219040Seric rewrite(++tv, 2); 102356327Seric if (m->m_r_rwset > 0) 102456327Seric rewrite(tv, m->m_r_rwset); 102519040Seric rewrite(tv, 4); 102619040Seric 102719040Seric /* save the result for the command line/RCPT argument */ 102811278Seric cataddr(tv, buf, sizeof buf); 10293149Seric a->q_user = buf; 10303149Seric 10313149Seric return (a); 10323149Seric } 10333188Seric /* 10344228Seric ** CATADDR -- concatenate pieces of addresses (putting in <LWSP> subs) 10354228Seric ** 10364228Seric ** Parameters: 10374228Seric ** pvp -- parameter vector to rebuild. 10384228Seric ** buf -- buffer to build the string into. 10394228Seric ** sz -- size of buf. 10404228Seric ** 10414228Seric ** Returns: 10424228Seric ** none. 10434228Seric ** 10444228Seric ** Side Effects: 10454228Seric ** Destroys buf. 10464228Seric */ 10474228Seric 10484228Seric cataddr(pvp, buf, sz) 10494228Seric char **pvp; 10504228Seric char *buf; 10514228Seric register int sz; 10524228Seric { 10534228Seric bool oatomtok = FALSE; 105456678Seric bool natomtok = FALSE; 10554228Seric register int i; 10564228Seric register char *p; 10574228Seric 10588423Seric if (pvp == NULL) 10598423Seric { 106023109Seric (void) strcpy(buf, ""); 10618423Seric return; 10628423Seric } 10634228Seric p = buf; 106411156Seric sz -= 2; 10654228Seric while (*pvp != NULL && (i = strlen(*pvp)) < sz) 10664228Seric { 10678078Seric natomtok = (toktype(**pvp) == ATM); 10684228Seric if (oatomtok && natomtok) 10699042Seric *p++ = SpaceSub; 10704228Seric (void) strcpy(p, *pvp); 10714228Seric oatomtok = natomtok; 10724228Seric p += i; 107311156Seric sz -= i + 1; 10744228Seric pvp++; 10754228Seric } 10764228Seric *p = '\0'; 10774228Seric } 10784228Seric /* 10793188Seric ** SAMEADDR -- Determine if two addresses are the same 10803188Seric ** 10813188Seric ** This is not just a straight comparison -- if the mailer doesn't 10823188Seric ** care about the host we just ignore it, etc. 10833188Seric ** 10843188Seric ** Parameters: 10853188Seric ** a, b -- pointers to the internal forms to compare. 10863188Seric ** 10873188Seric ** Returns: 10883188Seric ** TRUE -- they represent the same mailbox. 10893188Seric ** FALSE -- they don't. 10903188Seric ** 10913188Seric ** Side Effects: 10923188Seric ** none. 10933188Seric */ 10943188Seric 10953188Seric bool 10969374Seric sameaddr(a, b) 10973188Seric register ADDRESS *a; 10983188Seric register ADDRESS *b; 10993188Seric { 11003188Seric /* if they don't have the same mailer, forget it */ 11013188Seric if (a->q_mailer != b->q_mailer) 11023188Seric return (FALSE); 11033188Seric 11043188Seric /* if the user isn't the same, we can drop out */ 110556678Seric if (strcmp(a->q_user, b->q_user) != 0) 11063188Seric return (FALSE); 11073188Seric 11083188Seric /* if the mailer ignores hosts, we have succeeded! */ 110910690Seric if (bitnset(M_LOCAL, a->q_mailer->m_flags)) 11103188Seric return (TRUE); 11113188Seric 11123188Seric /* otherwise compare hosts (but be careful for NULL ptrs) */ 11133188Seric if (a->q_host == NULL || b->q_host == NULL) 11143188Seric return (FALSE); 111556678Seric if (strcmp(a->q_host, b->q_host) != 0) 11163188Seric return (FALSE); 11173188Seric 11183188Seric return (TRUE); 11193188Seric } 11203234Seric /* 11213234Seric ** PRINTADDR -- print address (for debugging) 11223234Seric ** 11233234Seric ** Parameters: 11243234Seric ** a -- the address to print 11253234Seric ** follow -- follow the q_next chain. 11263234Seric ** 11273234Seric ** Returns: 11283234Seric ** none. 11293234Seric ** 11303234Seric ** Side Effects: 11313234Seric ** none. 11323234Seric */ 11333234Seric 11343234Seric printaddr(a, follow) 11353234Seric register ADDRESS *a; 11363234Seric bool follow; 11373234Seric { 11385001Seric bool first = TRUE; 11395001Seric 11403234Seric while (a != NULL) 11413234Seric { 11425001Seric first = FALSE; 11434443Seric printf("%x=", a); 11444085Seric (void) fflush(stdout); 114540973Sbostic printf("%s: mailer %d (%s), host `%s', user `%s', ruser `%s'\n", 114640973Sbostic a->q_paddr, a->q_mailer->m_mno, a->q_mailer->m_name, 114740973Sbostic a->q_host, a->q_user, a->q_ruser? a->q_ruser: "<null>"); 11488181Seric printf("\tnext=%x, flags=%o, alias %x\n", a->q_next, a->q_flags, 11498181Seric a->q_alias); 11508181Seric printf("\thome=\"%s\", fullname=\"%s\"\n", a->q_home, 11518181Seric a->q_fullname); 11524996Seric 11533234Seric if (!follow) 11543234Seric return; 11554996Seric a = a->q_next; 11563234Seric } 11575001Seric if (first) 11584443Seric printf("[NULL]\n"); 11593234Seric } 11604317Seric 11617682Seric /* 11627682Seric ** REMOTENAME -- return the name relative to the current mailer 11637682Seric ** 11647682Seric ** Parameters: 11657682Seric ** name -- the name to translate. 11668069Seric ** m -- the mailer that we want to do rewriting relative 11678069Seric ** to. 11688069Seric ** senderaddress -- if set, uses the sender rewriting rules 11698069Seric ** rather than the recipient rewriting rules. 117010310Seric ** canonical -- if set, strip out any comment information, 117110310Seric ** etc. 11727682Seric ** 11737682Seric ** Returns: 11747682Seric ** the text string representing this address relative to 11757682Seric ** the receiving mailer. 11767682Seric ** 11777682Seric ** Side Effects: 11787682Seric ** none. 11797682Seric ** 11807682Seric ** Warnings: 11817682Seric ** The text string returned is tucked away locally; 11827682Seric ** copy it if you intend to save it. 11837682Seric */ 11847682Seric 11857682Seric char * 118656678Seric remotename(name, m, senderaddress, canonical, e) 11877682Seric char *name; 118856678Seric struct mailer *m; 11898069Seric bool senderaddress; 119010310Seric bool canonical; 119156678Seric register ENVELOPE *e; 11927682Seric { 11938069Seric register char **pvp; 11948069Seric char *fancy; 119556678Seric extern char *macvalue(); 119656678Seric char *oldg = macvalue('g', e); 11977682Seric static char buf[MAXNAME]; 11987682Seric char lbuf[MAXNAME]; 119916914Seric char pvpbuf[PSBUFSIZE]; 120056678Seric extern char **prescan(); 120156678Seric extern char *crackaddr(); 12027682Seric 12037755Seric if (tTd(12, 1)) 12047755Seric printf("remotename(%s)\n", name); 12057755Seric 120610177Seric /* don't do anything if we are tagging it as special */ 120756327Seric if ((senderaddress ? m->m_s_rwset : m->m_r_rwset) < 0) 120810177Seric return (name); 120910177Seric 12107682Seric /* 12118181Seric ** Do a heuristic crack of this name to extract any comment info. 12128181Seric ** This will leave the name as a comment and a $g macro. 12137889Seric */ 12147889Seric 121510310Seric if (canonical) 121616155Seric fancy = "\001g"; 121710310Seric else 121810310Seric fancy = crackaddr(name); 12197889Seric 12208181Seric /* 12218181Seric ** Turn the name into canonical form. 12228181Seric ** Normally this will be RFC 822 style, i.e., "user@domain". 12238181Seric ** If this only resolves to "user", and the "C" flag is 12248181Seric ** specified in the sending mailer, then the sender's 12258181Seric ** domain will be appended. 12268181Seric */ 12278181Seric 122816914Seric pvp = prescan(name, '\0', pvpbuf); 12297889Seric if (pvp == NULL) 12307889Seric return (name); 12318181Seric rewrite(pvp, 3); 123256678Seric if (e->e_fromdomain != NULL) 12338181Seric { 12348181Seric /* append from domain to this address */ 12358181Seric register char **pxp = pvp; 12368181Seric 12379594Seric /* see if there is an "@domain" in the current name */ 12388181Seric while (*pxp != NULL && strcmp(*pxp, "@") != 0) 12398181Seric pxp++; 12408181Seric if (*pxp == NULL) 12418181Seric { 12429594Seric /* no.... append the "@domain" from the sender */ 124356678Seric register char **qxq = e->e_fromdomain; 12448181Seric 12459594Seric while ((*pxp++ = *qxq++) != NULL) 12469594Seric continue; 124711726Seric rewrite(pvp, 3); 12488181Seric } 12498181Seric } 12508181Seric 12518181Seric /* 12528959Seric ** Do more specific rewriting. 125356678Seric ** Rewrite using ruleset 1 or 2 depending on whether this is 125456678Seric ** a sender address or not. 12558181Seric ** Then run it through any receiving-mailer-specific rulesets. 12568181Seric */ 12578181Seric 12588069Seric if (senderaddress) 12597755Seric { 126056327Seric rewrite(pvp, 1); 126156327Seric if (m->m_s_rwset > 0) 126256327Seric rewrite(pvp, m->m_s_rwset); 12638069Seric } 12648069Seric else 12658069Seric { 126656327Seric rewrite(pvp, 2); 126756327Seric if (m->m_r_rwset > 0) 126856327Seric rewrite(pvp, m->m_r_rwset); 12697682Seric } 12707682Seric 12718181Seric /* 12728959Seric ** Do any final sanitation the address may require. 12738959Seric ** This will normally be used to turn internal forms 12748959Seric ** (e.g., user@host.LOCAL) into external form. This 12758959Seric ** may be used as a default to the above rules. 12768959Seric */ 12778959Seric 12788959Seric rewrite(pvp, 4); 12798959Seric 12808959Seric /* 12818181Seric ** Now restore the comment information we had at the beginning. 12828181Seric */ 12838181Seric 12847682Seric cataddr(pvp, lbuf, sizeof lbuf); 128556678Seric define('g', lbuf, e); 128656678Seric expand(fancy, buf, &buf[sizeof buf - 1], e); 128756678Seric define('g', oldg, e); 12887682Seric 12897682Seric if (tTd(12, 1)) 12907755Seric printf("remotename => `%s'\n", buf); 12917682Seric return (buf); 12927682Seric } 129351317Seric /* 129456678Seric ** MAPLOCALUSER -- run local username through ruleset 5 for final redirection 129551317Seric ** 129651317Seric ** Parameters: 129756678Seric ** a -- the address to map (but just the user name part). 129856678Seric ** sendq -- the sendq in which to install any replacement 129956678Seric ** addresses. 130051317Seric ** 130151317Seric ** Returns: 130251317Seric ** none. 130351317Seric */ 130451317Seric 130556678Seric maplocaluser(a, sendq, e) 130656678Seric register ADDRESS *a; 130756678Seric ADDRESS **sendq; 130856678Seric ENVELOPE *e; 130951317Seric { 131056678Seric register char **pvp; 131156678Seric register ADDRESS *a1 = NULL; 131256678Seric char pvpbuf[PSBUFSIZE]; 131351317Seric 131456678Seric if (tTd(29, 1)) 131556678Seric { 131656678Seric printf("maplocaluser: "); 131756678Seric printaddr(a, FALSE); 131856678Seric } 131956678Seric pvp = prescan(a->q_user, '\0', pvpbuf); 132056678Seric if (pvp == NULL) 132156678Seric return; 132251317Seric 132356678Seric rewrite(pvp, 5); 132456678Seric if (pvp[0] == NULL || pvp[0][0] != CANONNET) 132556678Seric return; 132651317Seric 132756678Seric /* if non-null, mailer destination specified -- has it changed? */ 132856678Seric a1 = buildaddr(pvp, NULL); 132956678Seric if (a1 == NULL || sameaddr(a, a1)) 133056678Seric return; 133151317Seric 133256678Seric /* mark old address as dead; insert new address */ 133356678Seric a->q_flags |= QDONTSEND; 133456678Seric a1->q_alias = a; 133556678Seric allocaddr(a1, 1, NULL); 133656678Seric (void) recipient(a1, sendq, e); 133751317Seric } 1338