122711Sdist /* 234921Sbostic * Copyright (c) 1983 Eric P. Allman 333731Sbostic * Copyright (c) 1988 Regents of the University of California. 433731Sbostic * All rights reserved. 533731Sbostic * 642829Sbostic * %sccs.include.redist.c% 733731Sbostic */ 822711Sdist 922711Sdist #ifndef lint 10*59057Seric static char sccsid[] = "@(#)savemail.c 6.30 (Berkeley) 04/13/93"; 1133731Sbostic #endif /* not lint */ 1222711Sdist 13297Seric # include <pwd.h> 143313Seric # include "sendmail.h" 15297Seric 16297Seric /* 17297Seric ** SAVEMAIL -- Save mail on error 18297Seric ** 199375Seric ** If mailing back errors, mail it back to the originator 20297Seric ** together with an error message; otherwise, just put it in 21297Seric ** dead.letter in the user's home directory (if he exists on 22297Seric ** this machine). 23297Seric ** 24297Seric ** Parameters: 259337Seric ** e -- the envelope containing the message in error. 26297Seric ** 27297Seric ** Returns: 28297Seric ** none 29297Seric ** 30297Seric ** Side Effects: 31297Seric ** Saves the letter, by writing or mailing it back to the 32297Seric ** sender, or by putting it in dead.letter in her home 33297Seric ** directory. 34297Seric */ 35297Seric 3624942Seric /* defines for state machine */ 3724942Seric # define ESM_REPORT 0 /* report to sender's terminal */ 3824942Seric # define ESM_MAIL 1 /* mail back to sender */ 3924942Seric # define ESM_QUIET 2 /* messages have already been returned */ 4024942Seric # define ESM_DEADLETTER 3 /* save in ~/dead.letter */ 4124942Seric # define ESM_POSTMASTER 4 /* return to postmaster */ 4224942Seric # define ESM_USRTMP 5 /* save in /usr/tmp/dead.letter */ 4324942Seric # define ESM_PANIC 6 /* leave the locked queue/transcript files */ 4424942Seric # define ESM_DONE 7 /* the message is successfully delivered */ 4524942Seric 4624942Seric 479337Seric savemail(e) 489337Seric register ENVELOPE *e; 49297Seric { 50297Seric register struct passwd *pw; 5124942Seric register FILE *fp; 5224942Seric int state; 5324942Seric auto ADDRESS *q; 54297Seric char buf[MAXLINE+1]; 55297Seric extern struct passwd *getpwnam(); 56297Seric register char *p; 57297Seric extern char *ttypath(); 585846Seric typedef int (*fnptr)(); 59297Seric 607676Seric if (tTd(6, 1)) 6158680Seric { 6258734Seric printf("\nsavemail, errormode = %c\n e_from=", e->e_errormode); 6358680Seric printaddr(&e->e_from, FALSE); 6458680Seric } 657361Seric 669375Seric if (bitset(EF_RESPONSE, e->e_flags)) 67297Seric return; 689337Seric e->e_flags &= ~EF_FATALERRS; 69297Seric 70297Seric /* 71297Seric ** In the unhappy event we don't know who to return the mail 72297Seric ** to, make someone up. 73297Seric */ 74297Seric 759337Seric if (e->e_from.q_paddr == NULL) 76297Seric { 7758733Seric e->e_sender = "Postmaster"; 7858704Seric if (parseaddr(e->e_sender, &e->e_from, 0, '\0', NULL, e) == NULL) 79297Seric { 8058733Seric syserr("553 Cannot parse Postmaster!"); 81297Seric ExitStat = EX_SOFTWARE; 82297Seric finis(); 83297Seric } 84297Seric } 859337Seric e->e_to = NULL; 86297Seric 87297Seric /* 8824942Seric ** Basic state machine. 8924942Seric ** 9024942Seric ** This machine runs through the following states: 9124942Seric ** 9224942Seric ** ESM_QUIET Errors have already been printed iff the 9324942Seric ** sender is local. 9424942Seric ** ESM_REPORT Report directly to the sender's terminal. 9524942Seric ** ESM_MAIL Mail response to the sender. 9624942Seric ** ESM_DEADLETTER Save response in ~/dead.letter. 9724942Seric ** ESM_POSTMASTER Mail response to the postmaster. 9824942Seric ** ESM_PANIC Save response anywhere possible. 99297Seric */ 100297Seric 10124942Seric /* determine starting state */ 10258734Seric switch (e->e_errormode) 103297Seric { 10424942Seric case EM_WRITE: 10524942Seric state = ESM_REPORT; 10624942Seric break; 10724942Seric 10824942Seric case EM_BERKNET: 10924942Seric /* mail back, but return o.k. exit status */ 110401Seric ExitStat = EX_OK; 11124942Seric 11224942Seric /* fall through.... */ 11324942Seric 11424942Seric case EM_MAIL: 11524942Seric state = ESM_MAIL; 11624942Seric break; 11724942Seric 11824942Seric case EM_PRINT: 11924979Seric case '\0': 12024942Seric state = ESM_QUIET; 12124942Seric break; 12224942Seric 12324942Seric case EM_QUIET: 12424942Seric /* no need to return anything at all */ 12524942Seric return; 12624979Seric 12724979Seric default: 12858734Seric syserr("554 savemail: bogus errormode x%x\n", e->e_errormode); 12924979Seric state = ESM_MAIL; 13024979Seric break; 131297Seric } 132297Seric 13324942Seric while (state != ESM_DONE) 134297Seric { 13524979Seric if (tTd(6, 5)) 13624979Seric printf(" state %d\n", state); 13724979Seric 13824942Seric switch (state) 139297Seric { 14024979Seric case ESM_QUIET: 14124979Seric if (e->e_from.q_mailer == LocalMailer) 14224979Seric state = ESM_DEADLETTER; 14324979Seric else 14424979Seric state = ESM_MAIL; 14524979Seric break; 14624979Seric 14724942Seric case ESM_REPORT: 14824942Seric 14924942Seric /* 15024942Seric ** If the user is still logged in on the same terminal, 15124942Seric ** then write the error messages back to hir (sic). 15224942Seric */ 15324942Seric 15424942Seric p = ttypath(); 15524942Seric if (p == NULL || freopen(p, "w", stdout) == NULL) 15624942Seric { 15724942Seric state = ESM_MAIL; 15824942Seric break; 15924942Seric } 16024942Seric 16158050Seric expand("\201n", buf, &buf[sizeof buf - 1], e); 1629375Seric printf("\r\nMessage from %s...\r\n", buf); 1639375Seric printf("Errors occurred while sending mail.\r\n"); 1649542Seric if (e->e_xfp != NULL) 1659375Seric { 1669542Seric (void) fflush(e->e_xfp); 16724942Seric fp = fopen(queuename(e, 'x'), "r"); 1689375Seric } 1699375Seric else 17024942Seric fp = NULL; 17124942Seric if (fp == NULL) 1729375Seric { 1739337Seric syserr("Cannot open %s", queuename(e, 'x')); 1749375Seric printf("Transcript of session is unavailable.\r\n"); 1759375Seric } 1769375Seric else 1779375Seric { 1789375Seric printf("Transcript follows:\r\n"); 17924942Seric while (fgets(buf, sizeof buf, fp) != NULL && 1809375Seric !ferror(stdout)) 1819375Seric fputs(buf, stdout); 18258680Seric (void) xfclose(fp, "savemail transcript", e->e_id); 1839375Seric } 18424942Seric printf("Original message will be saved in dead.letter.\r\n"); 18524942Seric state = ESM_DEADLETTER; 18624942Seric break; 187297Seric 18824942Seric case ESM_MAIL: 18924942Seric /* 19024942Seric ** If mailing back, do it. 19124942Seric ** Throw away all further output. Don't alias, 19224942Seric ** since this could cause loops, e.g., if joe 19324942Seric ** mails to joe@x, and for some reason the network 19424942Seric ** for @x is down, then the response gets sent to 19524942Seric ** joe@x, which gives a response, etc. Also force 19624942Seric ** the mail to be delivered even if a version of 19724942Seric ** it has already been sent to the sender. 19824942Seric */ 199297Seric 20058680Seric if (strcmp(e->e_from.q_paddr, "<>") != 0) 20158680Seric (void) sendtolist(e->e_from.q_paddr, 20258680Seric (ADDRESS *) NULL, 20358680Seric &e->e_errorqueue, e); 20458680Seric 20558680Seric /* deliver a cc: to the postmaster if desired */ 20658680Seric if (PostMasterCopy != NULL) 20724942Seric { 20858680Seric auto ADDRESS *rlist = NULL; 20958178Seric 21058680Seric (void) sendtolist(PostMasterCopy, 21158304Seric (ADDRESS *) NULL, 21258680Seric &rlist, e); 21358680Seric (void) returntosender(e->e_message, 21458680Seric rlist, FALSE, e); 21558680Seric } 21658680Seric q = e->e_errorqueue; 21758680Seric if (q == NULL) 21858680Seric { 21958680Seric /* this is an error-error */ 22058680Seric state = ESM_POSTMASTER; 22158680Seric break; 22258680Seric } 22358966Seric if (returntosender(e->e_message, 22458680Seric q, (e->e_class >= 0), e) == 0) 22558680Seric { 22658680Seric state = ESM_DONE; 22758680Seric break; 22858680Seric } 22924981Seric 23058680Seric /* didn't work -- return to postmaster */ 23158680Seric state = ESM_POSTMASTER; 23258680Seric break; 23358306Seric 23458680Seric case ESM_POSTMASTER: 23558680Seric /* 23658680Seric ** Similar to previous case, but to system postmaster. 23758680Seric */ 23858680Seric 239*59057Seric q = parseaddr("postmaster", q, 0, '\0', NULL, e); 240*59057Seric if (q == NULL) 24124942Seric { 24258680Seric syserr("553 cannot parse postmaster!"); 24358680Seric ExitStat = EX_SOFTWARE; 24458680Seric state = ESM_USRTMP; 24558680Seric break; 24624942Seric } 24758966Seric if (returntosender(e->e_message, 24857438Seric q, (e->e_class >= 0), e) == 0) 24924942Seric { 25024942Seric state = ESM_DONE; 25124942Seric break; 25224942Seric } 253297Seric 25458680Seric /* didn't work -- last resort */ 25558680Seric state = ESM_USRTMP; 25624942Seric break; 257297Seric 25824942Seric case ESM_DEADLETTER: 25924942Seric /* 26024942Seric ** Save the message in dead.letter. 26124942Seric ** If we weren't mailing back, and the user is 26224942Seric ** local, we should save the message in 26324942Seric ** ~/dead.letter so that the poor person doesn't 26424942Seric ** have to type it over again -- and we all know 26524942Seric ** what poor typists UNIX users are. 26624942Seric */ 2675315Seric 26824942Seric p = NULL; 26924942Seric if (e->e_from.q_mailer == LocalMailer) 27024942Seric { 27124942Seric if (e->e_from.q_home != NULL) 27224942Seric p = e->e_from.q_home; 27324942Seric else if ((pw = getpwnam(e->e_from.q_user)) != NULL) 27424942Seric p = pw->pw_dir; 27524942Seric } 27624942Seric if (p == NULL) 27724942Seric { 27858865Seric /* no local directory */ 27924942Seric state = ESM_MAIL; 28024942Seric break; 28124942Seric } 28224942Seric if (e->e_dfp != NULL) 28324942Seric { 28424942Seric auto ADDRESS *q; 28524942Seric bool oldverb = Verbose; 28624942Seric 28724942Seric /* we have a home directory; open dead.letter */ 28824942Seric define('z', p, e); 28958050Seric expand("\201z/dead.letter", buf, &buf[sizeof buf - 1], e); 29024942Seric Verbose = TRUE; 29158151Seric message("Saving message in %s", buf); 29224942Seric Verbose = oldverb; 29324942Seric e->e_to = buf; 29424942Seric q = NULL; 29558082Seric (void) sendtolist(buf, &e->e_from, &q, e); 29624942Seric if (deliver(e, q) == 0) 29724942Seric state = ESM_DONE; 29824942Seric else 29924942Seric state = ESM_MAIL; 30024942Seric } 30125569Seric else 30225569Seric { 30325569Seric /* no data file -- try mailing back */ 30425569Seric state = ESM_MAIL; 30525569Seric } 30624942Seric break; 30724942Seric 30824942Seric case ESM_USRTMP: 30924942Seric /* 31024942Seric ** Log the mail in /usr/tmp/dead.letter. 31124942Seric */ 31224942Seric 31357438Seric if (e->e_class < 0) 31457438Seric { 31557438Seric state = ESM_DONE; 31657438Seric break; 31757438Seric } 31857438Seric 31924942Seric fp = dfopen("/usr/tmp/dead.letter", "a"); 32024942Seric if (fp == NULL) 32124942Seric { 32224942Seric state = ESM_PANIC; 32324942Seric break; 32424942Seric } 32524942Seric 32658010Seric putfromline(fp, FileMailer, e); 32758010Seric (*e->e_puthdr)(fp, FileMailer, e); 32858010Seric putline("\n", fp, FileMailer); 32958010Seric (*e->e_putbody)(fp, FileMailer, e); 33058010Seric putline("\n", fp, FileMailer); 33124942Seric (void) fflush(fp); 33224942Seric state = ferror(fp) ? ESM_PANIC : ESM_DONE; 33358680Seric (void) xfclose(fp, "savemail", "/usr/tmp/dead.letter"); 33424942Seric break; 33524942Seric 33624942Seric default: 33758151Seric syserr("554 savemail: unknown state %d", state); 33824942Seric 33924942Seric /* fall through ... */ 34024942Seric 34124942Seric case ESM_PANIC: 34224942Seric /* leave the locked queue & transcript files around */ 34358151Seric syserr("554 savemail: cannot save rejected email anywhere"); 34424942Seric exit(EX_SOFTWARE); 34524942Seric } 346297Seric } 347297Seric } 348297Seric /* 3494633Seric ** RETURNTOSENDER -- return a message to the sender with an error. 3504633Seric ** 3514633Seric ** Parameters: 3524633Seric ** msg -- the explanatory message. 35316479Seric ** returnq -- the queue of people to send the message to. 3545984Seric ** sendbody -- if TRUE, also send back the body of the 3555984Seric ** message; otherwise just send the header. 35655012Seric ** e -- the current envelope. 3574633Seric ** 3584633Seric ** Returns: 3594633Seric ** zero -- if everything went ok. 3604633Seric ** else -- some error. 3614633Seric ** 3624633Seric ** Side Effects: 3634633Seric ** Returns the current message to the sender via 3644633Seric ** mail. 3654633Seric */ 3664633Seric 3675984Seric static bool SendBody; 3684633Seric 3697045Seric #define MAXRETURNS 6 /* max depth of returning messages */ 37058559Seric #define ERRORFUDGE 100 /* nominal size of error message text */ 3717045Seric 37255012Seric returntosender(msg, returnq, sendbody, e) 3734633Seric char *msg; 37416479Seric ADDRESS *returnq; 3755984Seric bool sendbody; 37655012Seric register ENVELOPE *e; 3774633Seric { 3784633Seric char buf[MAXNAME]; 3796978Seric extern putheader(), errbody(); 3806978Seric register ENVELOPE *ee; 38158680Seric ENVELOPE *oldcur = CurEnv; 3826978Seric extern ENVELOPE *newenvelope(); 3836978Seric ENVELOPE errenvelope; 3847045Seric static int returndepth; 3859375Seric register ADDRESS *q; 3864633Seric 38758966Seric if (msg == NULL) 38858966Seric msg = "Unable to deliver mail"; 38958966Seric 3907676Seric if (tTd(6, 1)) 3917287Seric { 39258680Seric printf("Return To Sender: msg=\"%s\", depth=%d, e=%x, returnq=", 39355012Seric msg, returndepth, e); 39416479Seric printaddr(returnq, TRUE); 3957287Seric } 3967287Seric 3977045Seric if (++returndepth >= MAXRETURNS) 3987045Seric { 3997045Seric if (returndepth != MAXRETURNS) 40058151Seric syserr("554 returntosender: infinite recursion on %s", returnq->q_paddr); 4017045Seric /* don't "unrecurse" and fake a clean exit */ 4027045Seric /* returndepth--; */ 4037045Seric return (0); 4047045Seric } 4057045Seric 4065984Seric SendBody = sendbody; 40758680Seric define('g', e->e_from.q_paddr, e); 40858179Seric ee = newenvelope(&errenvelope, e); 40958050Seric define('a', "\201b", ee); 410*59057Seric define('r', "internal", ee); 411*59057Seric define('s', "localhost", ee); 412*59057Seric define('_', "localhost", ee); 4136978Seric ee->e_puthdr = putheader; 4146978Seric ee->e_putbody = errbody; 4159375Seric ee->e_flags |= EF_RESPONSE; 41655012Seric if (!bitset(EF_OLDSTYLE, e->e_flags)) 41745155Seric ee->e_flags &= ~EF_OLDSTYLE; 41816479Seric ee->e_sendqueue = returnq; 41958559Seric ee->e_msgsize = e->e_msgsize + ERRORFUDGE; 4209542Seric openxscript(ee); 42116479Seric for (q = returnq; q != NULL; q = q->q_next) 4229375Seric { 42358559Seric if (bitset(QDONTSEND, q->q_flags)) 42458559Seric continue; 42558559Seric 42658559Seric ee->e_nrcpts++; 42758559Seric 42858144Seric if (!DontPruneRoutes && pruneroute(q->q_paddr)) 42958333Seric parseaddr(q->q_paddr, q, 0, '\0', NULL, e); 43058144Seric 4319375Seric if (q->q_alias == NULL) 4329375Seric addheader("to", q->q_paddr, ee); 4339375Seric } 43424942Seric 43557642Seric # ifdef LOG 43658020Seric if (LogLevel > 5) 43757642Seric syslog(LOG_INFO, "%s: %s: return to sender: %s", 43857642Seric e->e_id, ee->e_id, msg); 43957642Seric # endif 44057642Seric 44110845Seric (void) sprintf(buf, "Returned mail: %s", msg); 44210106Seric addheader("subject", buf, ee); 4434633Seric 4444633Seric /* fake up an address header for the from person */ 44558050Seric expand("\201n", buf, &buf[sizeof buf - 1], e); 44658680Seric if (parseaddr(buf, &ee->e_from, 1, '\0', NULL, e) == NULL) 4474633Seric { 44858151Seric syserr("553 Can't parse myself!"); 4494633Seric ExitStat = EX_SOFTWARE; 4507045Seric returndepth--; 4514633Seric return (-1); 4524633Seric } 45358704Seric ee->e_sender = ee->e_from.q_paddr; 4545984Seric 4556978Seric /* push state into submessage */ 4566978Seric CurEnv = ee; 45758050Seric define('f', "\201n", ee); 4589375Seric define('x', "Mail Delivery Subsystem", ee); 45958929Seric eatheader(ee, TRUE); 4605984Seric 4616978Seric /* actually deliver the error message */ 46214876Seric sendall(ee, SM_DEFAULT); 4636978Seric 4646978Seric /* restore state */ 4657811Seric dropenvelope(ee); 46658680Seric CurEnv = oldcur; 4677045Seric returndepth--; 4686978Seric 4697045Seric /* should check for delivery errors here */ 4704633Seric return (0); 4714633Seric } 4724633Seric /* 4736978Seric ** ERRBODY -- output the body of an error message. 4746978Seric ** 4756978Seric ** Typically this is a copy of the transcript plus a copy of the 4766978Seric ** original offending message. 4776978Seric ** 478297Seric ** Parameters: 479297Seric ** fp -- the output file. 48010170Seric ** m -- the mailer to output to. 4819542Seric ** e -- the envelope we are working in. 482297Seric ** 483297Seric ** Returns: 484297Seric ** none 485297Seric ** 486297Seric ** Side Effects: 4876978Seric ** Outputs the body of an error message. 488297Seric */ 489297Seric 49010170Seric errbody(fp, m, e) 491297Seric register FILE *fp; 4924318Seric register struct mailer *m; 4939542Seric register ENVELOPE *e; 494297Seric { 4956978Seric register FILE *xfile; 4963189Seric char buf[MAXLINE]; 4979337Seric char *p; 498297Seric 49958680Seric if (e->e_parent == NULL) 50058680Seric { 50158680Seric syserr("errbody: null parent"); 50258680Seric putline("\n", fp, m); 50358680Seric putline(" ----- Original message lost -----\n", fp, m); 50458680Seric return; 50558680Seric } 50658680Seric 5079057Seric /* 50855372Seric ** Output error message header (if specified and available). 50955372Seric */ 51055372Seric 51155372Seric if (ErrMsgFile != NULL) 51255372Seric { 51355372Seric if (*ErrMsgFile == '/') 51455372Seric { 51555372Seric xfile = fopen(ErrMsgFile, "r"); 51655372Seric if (xfile != NULL) 51755372Seric { 51855372Seric while (fgets(buf, sizeof buf, xfile) != NULL) 51955425Seric { 52055425Seric expand(buf, buf, &buf[sizeof buf - 1], e); 52155372Seric putline(buf, fp, m); 52255425Seric } 52355372Seric (void) fclose(xfile); 52455372Seric fprintf(fp, "\n"); 52555372Seric } 52655372Seric } 52755372Seric else 52855372Seric { 52955425Seric expand(ErrMsgFile, buf, &buf[sizeof buf - 1], e); 53055425Seric putline(buf, fp, m); 53155372Seric fprintf(fp, "\n"); 53255372Seric } 53355372Seric } 53455372Seric 53555372Seric /* 5369057Seric ** Output transcript of errors 5379057Seric */ 5389057Seric 5394086Seric (void) fflush(stdout); 5409542Seric p = queuename(e->e_parent, 'x'); 5419337Seric if ((xfile = fopen(p, "r")) == NULL) 5429057Seric { 5439337Seric syserr("Cannot open %s", p); 54458680Seric putline(" ----- Transcript of session is unavailable -----\n", fp, m); 5459057Seric } 5469057Seric else 5479057Seric { 54858680Seric putline(" ----- Transcript of session follows -----\n", fp, m); 5499542Seric if (e->e_xfp != NULL) 5509542Seric (void) fflush(e->e_xfp); 5519057Seric while (fgets(buf, sizeof buf, xfile) != NULL) 55210170Seric putline(buf, fp, m); 55358680Seric (void) xfclose(xfile, "errbody xscript", p); 5549057Seric } 555297Seric errno = 0; 5564318Seric 5574318Seric /* 5584318Seric ** Output text of original message 5594318Seric */ 5604318Seric 5614289Seric if (NoReturn) 56258665Seric SendBody = FALSE; 56358680Seric if (e->e_parent->e_df != NULL) 5644199Seric { 5655984Seric if (SendBody) 5665984Seric { 56710170Seric putline("\n", fp, m); 56810170Seric putline(" ----- Unsent message follows -----\n", fp, m); 5695984Seric (void) fflush(fp); 57010170Seric putheader(fp, m, e->e_parent); 57110170Seric putline("\n", fp, m); 57210170Seric putbody(fp, m, e->e_parent); 5735984Seric } 5745984Seric else 5755984Seric { 57610170Seric putline("\n", fp, m); 57710170Seric putline(" ----- Message header follows -----\n", fp, m); 5785984Seric (void) fflush(fp); 57910170Seric putheader(fp, m, e->e_parent); 5805984Seric } 5814199Seric } 5824199Seric else 58310170Seric { 58410170Seric putline("\n", fp, m); 58510170Seric putline(" ----- No message was collected -----\n", fp, m); 58610170Seric putline("\n", fp, m); 58710170Seric } 5884318Seric 5894318Seric /* 5904318Seric ** Cleanup and exit 5914318Seric */ 5924318Seric 593297Seric if (errno != 0) 5946978Seric syserr("errbody: I/O error"); 595297Seric } 59658144Seric /* 59758144Seric ** PRUNEROUTE -- prune an RFC-822 source route 59858144Seric ** 59958144Seric ** Trims down a source route to the last internet-registered hop. 60058144Seric ** This is encouraged by RFC 1123 section 5.3.3. 60158144Seric ** 60258144Seric ** Parameters: 60358144Seric ** addr -- the address 60458144Seric ** 60558144Seric ** Returns: 60658144Seric ** TRUE -- address was modified 60758144Seric ** FALSE -- address could not be pruned 60858144Seric ** 60958144Seric ** Side Effects: 61058144Seric ** modifies addr in-place 61158144Seric */ 61258144Seric 61358144Seric pruneroute(addr) 61458144Seric char *addr; 61558144Seric { 61658144Seric #ifdef NAMED_BIND 61758144Seric char *start, *at, *comma; 61858144Seric char c; 61958144Seric int rcode; 62058144Seric char hostbuf[BUFSIZ]; 62158144Seric char *mxhosts[MAXMXHOSTS + 1]; 62258144Seric 62358144Seric /* check to see if this is really a route-addr */ 62458144Seric if (*addr != '<' || addr[1] != '@' || addr[strlen(addr) - 1] != '>') 62558144Seric return FALSE; 62658144Seric start = strchr(addr, ':'); 62758144Seric at = strrchr(addr, '@'); 62858144Seric if (start == NULL || at == NULL || at < start) 62958144Seric return FALSE; 63058144Seric 63158144Seric /* slice off the angle brackets */ 63258144Seric strcpy(hostbuf, at + 1); 63358144Seric hostbuf[strlen(hostbuf) - 1] = '\0'; 63458144Seric 63558144Seric while (start) 63658144Seric { 63758144Seric if (getmxrr(hostbuf, mxhosts, "", &rcode) > 0) 63858144Seric { 63958144Seric strcpy(addr + 1, start + 1); 64058144Seric return TRUE; 64158144Seric } 64258144Seric c = *start; 64358144Seric *start = '\0'; 64458144Seric comma = strrchr(addr, ','); 64558144Seric if (comma && comma[1] == '@') 64658144Seric strcpy(hostbuf, comma + 2); 64758144Seric else 64858144Seric comma = 0; 64958144Seric *start = c; 65058144Seric start = comma; 65158144Seric } 65258144Seric #endif 65358144Seric return FALSE; 65458144Seric } 655