122711Sdist /* 268839Seric * Copyright (c) 1983, 1995 Eric P. Allman 362531Sbostic * Copyright (c) 1988, 1993 462531Sbostic * The Regents of the University of California. All rights reserved. 533731Sbostic * 642829Sbostic * %sccs.include.redist.c% 733731Sbostic */ 822711Sdist 922711Sdist #ifndef lint 10*68868Seric static char sccsid[] = "@(#)savemail.c 8.68 (Berkeley) 04/23/95"; 1133731Sbostic #endif /* not lint */ 1222711Sdist 1363937Seric # include "sendmail.h" 14297Seric 15297Seric /* 16297Seric ** SAVEMAIL -- Save mail on error 17297Seric ** 189375Seric ** If mailing back errors, mail it back to the originator 19297Seric ** together with an error message; otherwise, just put it in 20297Seric ** dead.letter in the user's home directory (if he exists on 21297Seric ** this machine). 22297Seric ** 23297Seric ** Parameters: 249337Seric ** e -- the envelope containing the message in error. 2567981Seric ** sendbody -- if TRUE, also send back the body of the 2667981Seric ** message; otherwise just send the header. 27297Seric ** 28297Seric ** Returns: 29297Seric ** none 30297Seric ** 31297Seric ** Side Effects: 32297Seric ** Saves the letter, by writing or mailing it back to the 33297Seric ** sender, or by putting it in dead.letter in her home 34297Seric ** directory. 35297Seric */ 36297Seric 3724942Seric /* defines for state machine */ 3824942Seric # define ESM_REPORT 0 /* report to sender's terminal */ 3924942Seric # define ESM_MAIL 1 /* mail back to sender */ 4024942Seric # define ESM_QUIET 2 /* messages have already been returned */ 4124942Seric # define ESM_DEADLETTER 3 /* save in ~/dead.letter */ 4224942Seric # define ESM_POSTMASTER 4 /* return to postmaster */ 4324942Seric # define ESM_USRTMP 5 /* save in /usr/tmp/dead.letter */ 4424942Seric # define ESM_PANIC 6 /* leave the locked queue/transcript files */ 4524942Seric # define ESM_DONE 7 /* the message is successfully delivered */ 4624942Seric 4765174Seric # ifndef _PATH_VARTMP 4865174Seric # define _PATH_VARTMP "/usr/tmp/" 4965174Seric # endif 5024942Seric 5165174Seric 5267981Seric savemail(e, sendbody) 539337Seric register ENVELOPE *e; 5467981Seric bool sendbody; 55297Seric { 56297Seric register struct passwd *pw; 5724942Seric register FILE *fp; 5824942Seric int state; 5959290Seric auto ADDRESS *q = NULL; 6065870Seric register char *p; 6165870Seric MCI mcibuf; 6268802Seric int sfflags; 63297Seric char buf[MAXLINE+1]; 64297Seric extern char *ttypath(); 655846Seric typedef int (*fnptr)(); 6664945Seric extern bool writable(); 67297Seric 687676Seric if (tTd(6, 1)) 6958680Seric { 7066317Seric printf("\nsavemail, errormode = %c, id = %s, ExitStat = %d\n e_from=", 7166317Seric e->e_errormode, e->e_id == NULL ? "NONE" : e->e_id, 7266317Seric ExitStat); 7358680Seric printaddr(&e->e_from, FALSE); 7458680Seric } 757361Seric 7659101Seric if (e->e_id == NULL) 7759101Seric { 7859101Seric /* can't return a message with no id */ 7959101Seric return; 8059101Seric } 8159101Seric 82297Seric /* 83297Seric ** In the unhappy event we don't know who to return the mail 84297Seric ** to, make someone up. 85297Seric */ 86297Seric 879337Seric if (e->e_from.q_paddr == NULL) 88297Seric { 8958733Seric e->e_sender = "Postmaster"; 9064284Seric if (parseaddr(e->e_sender, &e->e_from, 9164284Seric RF_COPYPARSE|RF_SENDERADDR, '\0', NULL, e) == NULL) 92297Seric { 9358733Seric syserr("553 Cannot parse Postmaster!"); 94297Seric ExitStat = EX_SOFTWARE; 95297Seric finis(); 96297Seric } 97297Seric } 989337Seric e->e_to = NULL; 99297Seric 100297Seric /* 10124942Seric ** Basic state machine. 10224942Seric ** 10324942Seric ** This machine runs through the following states: 10424942Seric ** 10524942Seric ** ESM_QUIET Errors have already been printed iff the 10624942Seric ** sender is local. 10724942Seric ** ESM_REPORT Report directly to the sender's terminal. 10824942Seric ** ESM_MAIL Mail response to the sender. 10924942Seric ** ESM_DEADLETTER Save response in ~/dead.letter. 11024942Seric ** ESM_POSTMASTER Mail response to the postmaster. 11124942Seric ** ESM_PANIC Save response anywhere possible. 112297Seric */ 113297Seric 11424942Seric /* determine starting state */ 11558734Seric switch (e->e_errormode) 116297Seric { 11724942Seric case EM_WRITE: 11824942Seric state = ESM_REPORT; 11924942Seric break; 12024942Seric 12124942Seric case EM_BERKNET: 12224942Seric /* mail back, but return o.k. exit status */ 123401Seric ExitStat = EX_OK; 12424942Seric 12524942Seric /* fall through.... */ 12624942Seric 12724942Seric case EM_MAIL: 12824942Seric state = ESM_MAIL; 12924942Seric break; 13024942Seric 13124942Seric case EM_PRINT: 13224979Seric case '\0': 13324942Seric state = ESM_QUIET; 13424942Seric break; 13524942Seric 13624942Seric case EM_QUIET: 13724942Seric /* no need to return anything at all */ 13824942Seric return; 13924979Seric 14024979Seric default: 14158734Seric syserr("554 savemail: bogus errormode x%x\n", e->e_errormode); 14224979Seric state = ESM_MAIL; 14324979Seric break; 144297Seric } 145297Seric 14659094Seric /* if this is already an error response, send to postmaster */ 14759094Seric if (bitset(EF_RESPONSE, e->e_flags)) 14859094Seric { 14959094Seric if (e->e_parent != NULL && 15059094Seric bitset(EF_RESPONSE, e->e_parent->e_flags)) 15159094Seric { 15259094Seric /* got an error sending a response -- can it */ 15359094Seric return; 15459094Seric } 15559094Seric state = ESM_POSTMASTER; 15659094Seric } 15759094Seric 15824942Seric while (state != ESM_DONE) 159297Seric { 16024979Seric if (tTd(6, 5)) 16124979Seric printf(" state %d\n", state); 16224979Seric 16324942Seric switch (state) 164297Seric { 16524979Seric case ESM_QUIET: 16667473Seric if (bitnset(M_LOCALMAILER, e->e_from.q_mailer->m_flags)) 16724979Seric state = ESM_DEADLETTER; 16824979Seric else 16924979Seric state = ESM_MAIL; 17024979Seric break; 17124979Seric 17224942Seric case ESM_REPORT: 17324942Seric 17424942Seric /* 17524942Seric ** If the user is still logged in on the same terminal, 17624942Seric ** then write the error messages back to hir (sic). 17724942Seric */ 17824942Seric 17924942Seric p = ttypath(); 18024942Seric if (p == NULL || freopen(p, "w", stdout) == NULL) 18124942Seric { 18224942Seric state = ESM_MAIL; 18324942Seric break; 18424942Seric } 18524942Seric 18668529Seric expand("\201n", buf, sizeof buf, e); 1879375Seric printf("\r\nMessage from %s...\r\n", buf); 1889375Seric printf("Errors occurred while sending mail.\r\n"); 1899542Seric if (e->e_xfp != NULL) 1909375Seric { 1919542Seric (void) fflush(e->e_xfp); 19224942Seric fp = fopen(queuename(e, 'x'), "r"); 1939375Seric } 1949375Seric else 19524942Seric fp = NULL; 19624942Seric if (fp == NULL) 1979375Seric { 1989337Seric syserr("Cannot open %s", queuename(e, 'x')); 1999375Seric printf("Transcript of session is unavailable.\r\n"); 2009375Seric } 2019375Seric else 2029375Seric { 2039375Seric printf("Transcript follows:\r\n"); 20424942Seric while (fgets(buf, sizeof buf, fp) != NULL && 2059375Seric !ferror(stdout)) 2069375Seric fputs(buf, stdout); 20758680Seric (void) xfclose(fp, "savemail transcript", e->e_id); 2089375Seric } 20924942Seric printf("Original message will be saved in dead.letter.\r\n"); 21024942Seric state = ESM_DEADLETTER; 21124942Seric break; 212297Seric 21324942Seric case ESM_MAIL: 21424942Seric /* 21524942Seric ** If mailing back, do it. 21624942Seric ** Throw away all further output. Don't alias, 21724942Seric ** since this could cause loops, e.g., if joe 21824942Seric ** mails to joe@x, and for some reason the network 21924942Seric ** for @x is down, then the response gets sent to 22024942Seric ** joe@x, which gives a response, etc. Also force 22124942Seric ** the mail to be delivered even if a version of 22224942Seric ** it has already been sent to the sender. 22363841Seric ** 22463841Seric ** If this is a configuration or local software 22563841Seric ** error, send to the local postmaster as well, 22663841Seric ** since the originator can't do anything 22763841Seric ** about it anyway. Note that this is a full 22863841Seric ** copy of the message (intentionally) so that 22963841Seric ** the Postmaster can forward things along. 23024942Seric */ 231297Seric 23263841Seric if (ExitStat == EX_CONFIG || ExitStat == EX_SOFTWARE) 23363841Seric { 23463841Seric (void) sendtolist("postmaster", 23567982Seric NULLADDR, &e->e_errorqueue, 0, e); 23663841Seric } 23767939Seric if (!emptyaddr(&e->e_from)) 23863841Seric { 23958680Seric (void) sendtolist(e->e_from.q_paddr, 24067982Seric NULLADDR, &e->e_errorqueue, 0, e); 24163841Seric } 24258680Seric 24363841Seric /* 24463841Seric ** Deliver a non-delivery report to the 24563841Seric ** Postmaster-designate (not necessarily 24663841Seric ** Postmaster). This does not include the 24763841Seric ** body of the message, for privacy reasons. 24863841Seric ** You really shouldn't need this. 24963841Seric */ 25063841Seric 25163849Seric e->e_flags |= EF_PM_NOTIFY; 25258178Seric 25364792Seric /* check to see if there are any good addresses */ 25464792Seric for (q = e->e_errorqueue; q != NULL; q = q->q_next) 25564792Seric if (!bitset(QBADADDR|QDONTSEND, q->q_flags)) 25664792Seric break; 25758680Seric if (q == NULL) 25858680Seric { 25958680Seric /* this is an error-error */ 26058680Seric state = ESM_POSTMASTER; 26158680Seric break; 26258680Seric } 26366303Seric if (returntosender(e->e_message, e->e_errorqueue, 26467981Seric sendbody, e) == 0) 26558680Seric { 26658680Seric state = ESM_DONE; 26758680Seric break; 26858680Seric } 26924981Seric 27058680Seric /* didn't work -- return to postmaster */ 27158680Seric state = ESM_POSTMASTER; 27258680Seric break; 27358306Seric 27458680Seric case ESM_POSTMASTER: 27558680Seric /* 27658680Seric ** Similar to previous case, but to system postmaster. 27758680Seric */ 27858680Seric 27959432Seric q = NULL; 28067982Seric if (sendtolist("postmaster", NULL, &q, 0, e) <= 0) 28124942Seric { 28258680Seric syserr("553 cannot parse postmaster!"); 28358680Seric ExitStat = EX_SOFTWARE; 28458680Seric state = ESM_USRTMP; 28558680Seric break; 28624942Seric } 28767981Seric if (returntosender(e->e_message, q, sendbody, e) == 0) 28824942Seric { 28924942Seric state = ESM_DONE; 29024942Seric break; 29124942Seric } 292297Seric 29358680Seric /* didn't work -- last resort */ 29458680Seric state = ESM_USRTMP; 29524942Seric break; 296297Seric 29724942Seric case ESM_DEADLETTER: 29824942Seric /* 29924942Seric ** Save the message in dead.letter. 30024942Seric ** If we weren't mailing back, and the user is 30124942Seric ** local, we should save the message in 30224942Seric ** ~/dead.letter so that the poor person doesn't 30324942Seric ** have to type it over again -- and we all know 30424942Seric ** what poor typists UNIX users are. 30524942Seric */ 3065315Seric 30724942Seric p = NULL; 30867473Seric if (bitnset(M_HASPWENT, e->e_from.q_mailer->m_flags)) 30924942Seric { 31024942Seric if (e->e_from.q_home != NULL) 31124942Seric p = e->e_from.q_home; 31268693Seric else if ((pw = sm_getpwnam(e->e_from.q_user)) != NULL) 31324942Seric p = pw->pw_dir; 31424942Seric } 31568802Seric if (p == NULL || e->e_dfp == NULL) 31624942Seric { 31768802Seric /* no local directory or no data file */ 31824942Seric state = ESM_MAIL; 31924942Seric break; 32024942Seric } 32124942Seric 32268802Seric /* we have a home directory; open dead.letter */ 32368802Seric define('z', p, e); 32468802Seric expand("\201z/dead.letter", buf, sizeof buf, e); 32568802Seric sfflags = SFF_NOSLINK|SFF_CREAT|SFF_REGONLY|SFF_RUNASREALUID; 32668802Seric e->e_to = buf; 32768802Seric goto writefile; 32824942Seric 32924942Seric case ESM_USRTMP: 33024942Seric /* 33124942Seric ** Log the mail in /usr/tmp/dead.letter. 33224942Seric */ 33324942Seric 33457438Seric if (e->e_class < 0) 33557438Seric { 33657438Seric state = ESM_DONE; 33757438Seric break; 33857438Seric } 33957438Seric 34068490Seric if (SafeFileEnv != NULL && SafeFileEnv[0] != '\0') 34168490Seric { 34268490Seric state = ESM_PANIC; 34368490Seric break; 34468490Seric } 34568490Seric 34665174Seric strcpy(buf, _PATH_VARTMP); 34765174Seric strcat(buf, "dead.letter"); 34868802Seric sfflags = SFF_NOSLINK|SFF_CREAT|SFF_REGONLY; 34968802Seric 35068802Seric writefile: 35168802Seric if (!writable(buf, q, sfflags) || 35268802Seric (fp = safefopen(buf, O_WRONLY|O_CREAT|O_APPEND, 35368802Seric FileMode, sfflags)) == NULL) 35464945Seric { 35568802Seric if (state == ESM_USRTMP) 35668802Seric state = ESM_PANIC; 35768802Seric else 35868802Seric state = ESM_MAIL; 35964945Seric break; 36064945Seric } 36124942Seric 36265870Seric bzero(&mcibuf, sizeof mcibuf); 36365870Seric mcibuf.mci_out = fp; 36465870Seric mcibuf.mci_mailer = FileMailer; 36565870Seric if (bitnset(M_7BITS, FileMailer->m_flags)) 36665870Seric mcibuf.mci_flags |= MCIF_7BIT; 36765870Seric 36865870Seric putfromline(&mcibuf, e); 36968228Seric (*e->e_puthdr)(&mcibuf, e->e_header, e); 37068228Seric (*e->e_putbody)(&mcibuf, e, NULL); 37165870Seric putline("\n", &mcibuf); 37224942Seric (void) fflush(fp); 37368802Seric if (!ferror(fp)) 37468802Seric { 37568802Seric bool oldverb = Verbose; 37668802Seric 37768802Seric Verbose = TRUE; 37868802Seric message("Saved message in %s", buf); 37968802Seric Verbose = oldverb; 38068802Seric state = ESM_DONE; 38168802Seric } 38268802Seric else if (state == ESM_USRTMP) 38368802Seric state = ESM_PANIC; 38468802Seric else 38568802Seric state = ESM_MAIL; 38667809Seric (void) xfclose(fp, "savemail", buf); 38724942Seric break; 38824942Seric 38924942Seric default: 39058151Seric syserr("554 savemail: unknown state %d", state); 39124942Seric 39224942Seric /* fall through ... */ 39324942Seric 39424942Seric case ESM_PANIC: 39524942Seric /* leave the locked queue & transcript files around */ 39668490Seric loseqfile(e, "savemail panic"); 39764949Seric syserr("!554 savemail: cannot save rejected email anywhere"); 39824942Seric } 399297Seric } 400297Seric } 401297Seric /* 4024633Seric ** RETURNTOSENDER -- return a message to the sender with an error. 4034633Seric ** 4044633Seric ** Parameters: 4054633Seric ** msg -- the explanatory message. 40616479Seric ** returnq -- the queue of people to send the message to. 4075984Seric ** sendbody -- if TRUE, also send back the body of the 4085984Seric ** message; otherwise just send the header. 40955012Seric ** e -- the current envelope. 4104633Seric ** 4114633Seric ** Returns: 4124633Seric ** zero -- if everything went ok. 4134633Seric ** else -- some error. 4144633Seric ** 4154633Seric ** Side Effects: 4164633Seric ** Returns the current message to the sender via 4174633Seric ** mail. 4184633Seric */ 4194633Seric 4207045Seric #define MAXRETURNS 6 /* max depth of returning messages */ 42158559Seric #define ERRORFUDGE 100 /* nominal size of error message text */ 4227045Seric 42355012Seric returntosender(msg, returnq, sendbody, e) 4244633Seric char *msg; 42516479Seric ADDRESS *returnq; 4265984Seric bool sendbody; 42755012Seric register ENVELOPE *e; 4284633Seric { 42968528Seric char buf[MAXNAME + 1]; 4306978Seric extern putheader(), errbody(); 4316978Seric register ENVELOPE *ee; 43258680Seric ENVELOPE *oldcur = CurEnv; 4336978Seric ENVELOPE errenvelope; 4347045Seric static int returndepth; 4359375Seric register ADDRESS *q; 43668228Seric char *p; 4374633Seric 43860010Seric if (returnq == NULL) 43960010Seric return (-1); 44060010Seric 44158966Seric if (msg == NULL) 44258966Seric msg = "Unable to deliver mail"; 44358966Seric 4447676Seric if (tTd(6, 1)) 4457287Seric { 44667987Seric printf("\n*** Return To Sender: msg=\"%s\", depth=%d, e=%x, returnq=", 44755012Seric msg, returndepth, e); 44816479Seric printaddr(returnq, TRUE); 44967987Seric if (tTd(6, 20)) 45067987Seric { 45167987Seric printf("Sendq="); 45267987Seric printaddr(e->e_sendqueue, TRUE); 45367987Seric } 4547287Seric } 4557287Seric 4567045Seric if (++returndepth >= MAXRETURNS) 4577045Seric { 4587045Seric if (returndepth != MAXRETURNS) 45958151Seric syserr("554 returntosender: infinite recursion on %s", returnq->q_paddr); 4607045Seric /* don't "unrecurse" and fake a clean exit */ 4617045Seric /* returndepth--; */ 4627045Seric return (0); 4637045Seric } 4647045Seric 46558680Seric define('g', e->e_from.q_paddr, e); 46664940Seric define('u', NULL, e); 46767880Seric 46867880Seric /* initialize error envelope */ 46958179Seric ee = newenvelope(&errenvelope, e); 47058050Seric define('a', "\201b", ee); 47159057Seric define('r', "internal", ee); 47259057Seric define('s', "localhost", ee); 47359057Seric define('_', "localhost", ee); 4746978Seric ee->e_puthdr = putheader; 4756978Seric ee->e_putbody = errbody; 47664120Seric ee->e_flags |= EF_RESPONSE|EF_METOO; 47755012Seric if (!bitset(EF_OLDSTYLE, e->e_flags)) 47845155Seric ee->e_flags &= ~EF_OLDSTYLE; 47916479Seric ee->e_sendqueue = returnq; 48064655Seric ee->e_msgsize = ERRORFUDGE; 48168559Seric if (sendbody) 48264655Seric ee->e_msgsize += e->e_msgsize; 48368802Seric else 48468802Seric ee->e_flags |= EF_NO_BODY_RETN; 48564737Seric initsys(ee); 48616479Seric for (q = returnq; q != NULL; q = q->q_next) 4879375Seric { 48859989Seric if (bitset(QBADADDR, q->q_flags)) 48958559Seric continue; 49058559Seric 49168141Seric if (!DontPruneRoutes && pruneroute(q->q_paddr)) 49268141Seric { 49368141Seric register ADDRESS *p; 49468141Seric 49568141Seric parseaddr(q->q_paddr, q, RF_COPYPARSE, '\0', NULL, e); 49668141Seric for (p = returnq; p != NULL; p = p->q_next) 49768141Seric { 49868141Seric if (p != q && sameaddr(p, q)) 49968141Seric q->q_flags |= QDONTSEND; 50068141Seric } 50168141Seric } 50268141Seric 50359989Seric if (!bitset(QDONTSEND, q->q_flags)) 50459989Seric ee->e_nrcpts++; 50558559Seric 5069375Seric if (q->q_alias == NULL) 50767546Seric addheader("To", q->q_paddr, &ee->e_header); 5089375Seric } 50924942Seric 51057642Seric # ifdef LOG 51158020Seric if (LogLevel > 5) 51265054Seric syslog(LOG_INFO, "%s: %s: return to sender: %s", 51357642Seric e->e_id, ee->e_id, msg); 51457642Seric # endif 51557642Seric 51668003Seric if (SendMIMEErrors) 51767261Seric { 51868003Seric addheader("MIME-Version", "1.0", &ee->e_header); 51968003Seric (void) sprintf(buf, "%s.%ld/%s", 52068003Seric ee->e_id, curtime(), MyHostName); 52168003Seric ee->e_msgboundary = newstr(buf); 52268003Seric (void) sprintf(buf, 52368848Seric #if DSN 52468859Seric "multipart/report; report-type=X-delivery-status-2 (draft of April 20, 1995);\n\tboundary=\"%s\"", 52568028Seric #else 52668028Seric "multipart/mixed; boundary=\"%s\"", 52768028Seric #endif 52868003Seric ee->e_msgboundary); 52968003Seric addheader("Content-Type", buf, &ee->e_header); 53068003Seric } 53168228Seric if (strncmp(msg, "Warning:", 8) == 0) 53268003Seric { 53367261Seric addheader("Subject", msg, ee); 53468228Seric p = "warning-timeout"; 53567261Seric } 53667429Seric else if (strcmp(msg, "Return receipt") == 0) 53767429Seric { 53867429Seric addheader("Subject", msg, ee); 53968228Seric p = "return-receipt"; 54067429Seric } 54167261Seric else 54267261Seric { 54367261Seric sprintf(buf, "Returned mail: %.*s", sizeof buf - 20, msg); 54467546Seric addheader("Subject", buf, &ee->e_header); 54568228Seric p = "failure"; 54667261Seric } 54768228Seric (void) sprintf(buf, "auto-generated (%s)", p); 54868228Seric addheader("Auto-Submitted", buf, &ee->e_header); 5494633Seric 5504633Seric /* fake up an address header for the from person */ 55168529Seric expand("\201n", buf, sizeof buf, e); 55264284Seric if (parseaddr(buf, &ee->e_from, RF_COPYALL|RF_SENDERADDR, '\0', NULL, e) == NULL) 5534633Seric { 55458151Seric syserr("553 Can't parse myself!"); 5554633Seric ExitStat = EX_SOFTWARE; 5567045Seric returndepth--; 5574633Seric return (-1); 5584633Seric } 55958704Seric ee->e_sender = ee->e_from.q_paddr; 5605984Seric 5616978Seric /* push state into submessage */ 5626978Seric CurEnv = ee; 56358050Seric define('f', "\201n", ee); 5649375Seric define('x', "Mail Delivery Subsystem", ee); 56558929Seric eatheader(ee, TRUE); 5665984Seric 56763753Seric /* mark statistics */ 56864284Seric markstats(ee, NULLADDR); 56963753Seric 5706978Seric /* actually deliver the error message */ 57114876Seric sendall(ee, SM_DEFAULT); 5726978Seric 5736978Seric /* restore state */ 5747811Seric dropenvelope(ee); 57558680Seric CurEnv = oldcur; 5767045Seric returndepth--; 5776978Seric 5787045Seric /* should check for delivery errors here */ 5794633Seric return (0); 5804633Seric } 5814633Seric /* 5826978Seric ** ERRBODY -- output the body of an error message. 5836978Seric ** 5846978Seric ** Typically this is a copy of the transcript plus a copy of the 5856978Seric ** original offending message. 5866978Seric ** 587297Seric ** Parameters: 58865870Seric ** mci -- the mailer connection information. 5899542Seric ** e -- the envelope we are working in. 59067546Seric ** separator -- any possible MIME separator. 59167936Seric ** flags -- to modify the behaviour. 592297Seric ** 593297Seric ** Returns: 594297Seric ** none 595297Seric ** 596297Seric ** Side Effects: 5976978Seric ** Outputs the body of an error message. 598297Seric */ 599297Seric 60068228Seric errbody(mci, e, separator) 60165870Seric register MCI *mci; 6029542Seric register ENVELOPE *e; 60367546Seric char *separator; 604297Seric { 6056978Seric register FILE *xfile; 60659082Seric char *p; 60759082Seric register ADDRESS *q; 60859082Seric bool printheader; 60968559Seric bool sendbody; 6103189Seric char buf[MAXLINE]; 61168228Seric extern char *xtextify(); 612297Seric 61367546Seric if (bitset(MCIF_INHEADER, mci->mci_flags)) 61467546Seric { 61567546Seric putline("", mci); 61667546Seric mci->mci_flags &= ~MCIF_INHEADER; 61767546Seric } 61858680Seric if (e->e_parent == NULL) 61958680Seric { 62058680Seric syserr("errbody: null parent"); 62165870Seric putline(" ----- Original message lost -----\n", mci); 62258680Seric return; 62358680Seric } 62458680Seric 6259057Seric /* 62659730Seric ** Output MIME header. 62759730Seric */ 62859730Seric 62959730Seric if (e->e_msgboundary != NULL) 63059730Seric { 63165870Seric putline("This is a MIME-encapsulated message", mci); 63265870Seric putline("", mci); 63359730Seric (void) sprintf(buf, "--%s", e->e_msgboundary); 63465870Seric putline(buf, mci); 63565870Seric putline("", mci); 63659730Seric } 63759730Seric 63859730Seric /* 63963852Seric ** Output introductory information. 64063852Seric */ 64163852Seric 64264718Seric for (q = e->e_parent->e_sendqueue; q != NULL; q = q->q_next) 64364718Seric if (bitset(QBADADDR, q->q_flags)) 64464718Seric break; 64565054Seric if (q == NULL && 64665054Seric !bitset(EF_FATALERRS|EF_SENDRECEIPT, e->e_parent->e_flags)) 64764718Seric { 64864718Seric putline(" **********************************************", 64965870Seric mci); 65064718Seric putline(" ** THIS IS A WARNING MESSAGE ONLY **", 65165870Seric mci); 65264718Seric putline(" ** YOU DO NOT NEED TO RESEND YOUR MESSAGE **", 65365870Seric mci); 65464718Seric putline(" **********************************************", 65565870Seric mci); 65665870Seric putline("", mci); 65764718Seric } 65864718Seric sprintf(buf, "The original message was received at %s", 65964718Seric arpadate(ctime(&e->e_parent->e_ctime))); 66065870Seric putline(buf, mci); 66168529Seric expand("from \201_", buf, sizeof buf, e->e_parent); 66265870Seric putline(buf, mci); 66365870Seric putline("", mci); 66463852Seric 66563852Seric /* 66655372Seric ** Output error message header (if specified and available). 66755372Seric */ 66855372Seric 66967682Seric if (ErrMsgFile != NULL && !bitset(EF_SENDRECEIPT, e->e_parent->e_flags)) 67055372Seric { 67155372Seric if (*ErrMsgFile == '/') 67255372Seric { 67355372Seric xfile = fopen(ErrMsgFile, "r"); 67455372Seric if (xfile != NULL) 67555372Seric { 67655372Seric while (fgets(buf, sizeof buf, xfile) != NULL) 67755425Seric { 67868529Seric expand(buf, buf, sizeof buf, e); 67965870Seric putline(buf, mci); 68055425Seric } 68155372Seric (void) fclose(xfile); 68265870Seric putline("\n", mci); 68355372Seric } 68455372Seric } 68555372Seric else 68655372Seric { 68768529Seric expand(ErrMsgFile, buf, sizeof buf, e); 68865870Seric putline(buf, mci); 68965870Seric putline("", mci); 69055372Seric } 69155372Seric } 69255372Seric 69355372Seric /* 69459082Seric ** Output message introduction 69559082Seric */ 69659082Seric 69759082Seric printheader = TRUE; 69859082Seric for (q = e->e_parent->e_sendqueue; q != NULL; q = q->q_next) 69959082Seric { 700*68868Seric if (bitset(QBADADDR, q->q_flags)) 70159082Seric { 702*68868Seric if (!bitset(QPINGONFAILURE, q->q_flags)) 70368603Seric continue; 704*68868Seric p = "unrecoverable error"; 705*68868Seric } 706*68868Seric else if (!bitset(QPRIMARY, q->q_flags)) 707*68868Seric continue; 708*68868Seric else if (bitset(QRELAYED, q->q_flags)) 709*68868Seric p = "relayed to non-DSN-aware mailer"; 710*68868Seric else if (bitset(QDELIVERED, q->q_flags)) 711*68868Seric { 712*68868Seric if (bitset(QEXPANDED, q->q_flags)) 713*68868Seric p = "successfully delivered to mailing list"; 71463787Seric else 715*68868Seric p = "successfully delivered to mailbox"; 716*68868Seric } 717*68868Seric else if (bitset(QEXPANDED, q->q_flags)) 718*68868Seric p = "expanded by alias"; 719*68868Seric else if (bitset(QDELAYED, q->q_flags)) 720*68868Seric p = "transient failure"; 721*68868Seric else 722*68868Seric continue; 723*68868Seric 724*68868Seric if (printheader) 725*68868Seric { 726*68868Seric putline(" ----- The following addresses have delivery notifications -----", 727*68868Seric mci); 728*68868Seric printheader = FALSE; 729*68868Seric } 730*68868Seric 731*68868Seric sprintf(buf, "%s (%s)", q->q_paddr, p); 732*68868Seric putline(buf, mci); 733*68868Seric if (q->q_alias != NULL) 734*68868Seric { 735*68868Seric strcpy(buf, " (expanded from: "); 736*68868Seric strcat(buf, q->q_alias->q_paddr); 737*68868Seric strcat(buf, ")"); 73865870Seric putline(buf, mci); 73959082Seric } 74059082Seric } 74159082Seric if (!printheader) 74265870Seric putline("\n", mci); 74359082Seric 74459082Seric /* 7459057Seric ** Output transcript of errors 7469057Seric */ 7479057Seric 7484086Seric (void) fflush(stdout); 7499542Seric p = queuename(e->e_parent, 'x'); 7509337Seric if ((xfile = fopen(p, "r")) == NULL) 7519057Seric { 7529337Seric syserr("Cannot open %s", p); 75365870Seric putline(" ----- Transcript of session is unavailable -----\n", mci); 7549057Seric } 7559057Seric else 7569057Seric { 757*68868Seric printheader = TRUE; 7589542Seric if (e->e_xfp != NULL) 7599542Seric (void) fflush(e->e_xfp); 7609057Seric while (fgets(buf, sizeof buf, xfile) != NULL) 761*68868Seric { 762*68868Seric if (printheader) 763*68868Seric putline(" ----- Transcript of session follows -----\n", mci); 764*68868Seric printheader = FALSE; 76565870Seric putline(buf, mci); 766*68868Seric } 76758680Seric (void) xfclose(xfile, "errbody xscript", p); 7689057Seric } 769297Seric errno = 0; 7704318Seric 77168848Seric #if DSN 7724318Seric /* 77367880Seric ** Output machine-readable version. 77467880Seric */ 77567880Seric 77667880Seric if (e->e_msgboundary != NULL) 77767880Seric { 77867880Seric putline("", mci); 77967880Seric (void) sprintf(buf, "--%s", e->e_msgboundary); 78067880Seric putline(buf, mci); 781*68868Seric putline("Content-Type: message/X-delivery-status-04a (Draft of 04 April 1995)", mci); 78267880Seric putline("", mci); 78367880Seric 78467880Seric /* 78567880Seric ** Output per-message information. 78667880Seric */ 78767880Seric 78867880Seric /* original envelope id from MAIL FROM: line */ 78967880Seric if (e->e_parent->e_envid != NULL) 79067880Seric { 79167880Seric (void) sprintf(buf, "Original-Envelope-Id: %s", 79268228Seric xtextify(e->e_parent->e_envid)); 79367880Seric putline(buf, mci); 79467880Seric } 79567880Seric 79668228Seric /* Reporting-MTA: is us (required) */ 797*68868Seric (void) sprintf(buf, "Reporting-MTA: dns; %s", 79868583Seric xtextify(MyHostName)); 79967880Seric putline(buf, mci); 80067880Seric 801*68868Seric /* DSN-Gateway: not relevant since we are not translating */ 802*68868Seric 80368228Seric /* Received-From-MTA: shows where we got this message from */ 80467990Seric if (RealHostName != NULL) 80567990Seric { 80668228Seric /* XXX use $s for type? */ 80768228Seric p = e->e_parent->e_from.q_mailer->m_mtatype; 80868228Seric if (p == NULL) 80968228Seric p = "dns"; 81068228Seric (void) sprintf(buf, "Received-From-MTA: %s; %s", 81168583Seric p, xtextify(RealHostName)); 81267990Seric putline(buf, mci); 81367990Seric } 81467963Seric 81567963Seric /* Arrival-Date: -- when it arrived here */ 81667963Seric (void) sprintf(buf, "Arrival-Date: %s", 81767963Seric arpadate(ctime(&e->e_parent->e_ctime))); 81867963Seric putline(buf, mci); 81967963Seric 82067880Seric /* 82167880Seric ** Output per-address information. 82267880Seric */ 82367880Seric 82467880Seric for (q = e->e_parent->e_sendqueue; q != NULL; q = q->q_next) 82567880Seric { 82667880Seric register ADDRESS *r; 82768603Seric char *action; 82867880Seric 82968603Seric if (bitset(QBADADDR, q->q_flags)) 830*68868Seric action = "failed"; 83168603Seric else if (!bitset(QPRIMARY, q->q_flags)) 83267880Seric continue; 833*68868Seric else if (bitset(QDELIVERED, q->q_flags)) 834*68868Seric { 835*68868Seric if (bitset(QEXPANDED, q->q_flags)) 836*68868Seric action = "delivered (to mailing list)"; 837*68868Seric else 838*68868Seric action = "delivered (to mailbox)"; 839*68868Seric } 84068603Seric else if (bitset(QRELAYED, q->q_flags)) 841*68868Seric action = "relayed (to non-DSN-aware mailer)"; 842*68868Seric else if (bitset(QEXPANDED, q->q_flags)) 843*68868Seric action = "expanded (to multi-recipient alias)"; 844*68868Seric else if (bitset(QDELAYED, q->q_flags)) 84568603Seric action = "delayed"; 84668603Seric else 84768603Seric continue; 84868603Seric 84967880Seric putline("", mci); 85067880Seric 85168228Seric /* Original-Recipient: -- passed from on high */ 85268228Seric if (q->q_orcpt != NULL) 85368228Seric { 85468228Seric (void) sprintf(buf, "Original-Recipient: %s", 85568228Seric xtextify(q->q_orcpt)); 85668228Seric putline(buf, mci); 85768228Seric } 85868228Seric 85968228Seric /* Final-Recipient: -- the name from the RCPT command */ 86068228Seric p = e->e_parent->e_from.q_mailer->m_addrtype; 86168228Seric if (p == NULL) 86268228Seric p = "rfc822"; 86368228Seric for (r = q; r->q_alias != NULL; r = r->q_alias) 86468228Seric continue; 86568228Seric if (strchr(r->q_user, '@') == NULL) 86668583Seric { 86768583Seric (void) sprintf(buf, "Final-Recipient: %s; %s@", 86868583Seric p, xtextify(r->q_user)); 86968583Seric strcat(buf, xtextify(MyHostName)); 87068583Seric } 87167998Seric else 87268583Seric { 87368228Seric (void) sprintf(buf, "Final-Recipient: %s; %s", 87468228Seric p, xtextify(r->q_user)); 87568583Seric } 87667880Seric putline(buf, mci); 87767880Seric 87868603Seric /* X-Actual-Recipient: -- the real problem address */ 87968603Seric if (r != q) 88068603Seric { 88168603Seric if (strchr(q->q_user, '@') == NULL) 88268603Seric { 88368603Seric (void) sprintf(buf, "X-Actual-Recipient: %s; %s@", 88468603Seric p, xtextify(q->q_user)); 88568603Seric strcat(buf, xtextify(MyHostName)); 88668603Seric } 88768603Seric else 88868603Seric { 88968603Seric (void) sprintf(buf, "X-Actual-Recipient: %s; %s", 89068603Seric p, xtextify(q->q_user)); 89168603Seric } 89268603Seric putline(buf, mci); 89368603Seric } 89468603Seric 89567880Seric /* Action: -- what happened? */ 89668603Seric sprintf(buf, "Action: %s", action); 89768603Seric putline(buf, mci); 89867880Seric 89967880Seric /* Status: -- what _really_ happened? */ 90067880Seric strcpy(buf, "Status: "); 90167880Seric if (q->q_status != NULL) 90267880Seric strcat(buf, q->q_status); 90367880Seric else if (bitset(QBADADDR, q->q_flags)) 90468228Seric strcat(buf, "5.0.0"); 90567880Seric else if (bitset(QQUEUEUP, q->q_flags)) 90668228Seric strcat(buf, "4.0.0"); 90767880Seric else 90868228Seric strcat(buf, "2.0.0"); 90967880Seric putline(buf, mci); 91067880Seric 91168228Seric /* Remote-MTA: -- who was I talking to? */ 91268228Seric p = q->q_mailer->m_mtatype; 91368228Seric if (p == NULL) 91468228Seric p = "dns"; 91568228Seric (void) sprintf(buf, "Remote-MTA: %s; ", p); 91668228Seric if (q->q_statmta != NULL) 91768228Seric p = q->q_statmta; 91868603Seric else if (q->q_host != NULL && q->q_host[0] != '\0') 91968228Seric p = q->q_host; 92068228Seric else 92168228Seric p = NULL; 92268228Seric if (p != NULL) 92368228Seric { 92468228Seric strcat(buf, p); 92568228Seric p = &buf[strlen(buf) - 1]; 92668228Seric if (*p == '.') 92768228Seric *p = '\0'; 92868228Seric putline(buf, mci); 92968228Seric } 93068228Seric 93168228Seric /* Diagnostic-Code: -- actual result from other end */ 93268228Seric if (q->q_rstatus != NULL) 93368228Seric { 93468228Seric p = q->q_mailer->m_diagtype; 93568228Seric if (p == NULL) 93668228Seric p = "smtp"; 93768228Seric (void) sprintf(buf, "Diagnostic-Code: %s; %s", 938*68868Seric p, xtextify(q->q_rstatus)); 93968228Seric putline(buf, mci); 94068228Seric } 94168228Seric 94268228Seric /* Last-Attempt-Date: -- fine granularity */ 94367880Seric if (q->q_statdate == (time_t) 0L) 94467880Seric q->q_statdate = curtime(); 94568228Seric (void) sprintf(buf, "Last-Attempt-Date: %s", 94667880Seric arpadate(ctime(&q->q_statdate))); 94767880Seric putline(buf, mci); 94867880Seric 949*68868Seric /* Will-Retry-Until: -- for delayed messages only */ 95067963Seric if (bitset(QQUEUEUP, q->q_flags) && 95167963Seric !bitset(QBADADDR, q->q_flags)) 95267963Seric { 95367963Seric time_t xdate; 95467963Seric 95567963Seric xdate = e->e_ctime + TimeOuts.to_q_return[e->e_timeoutclass]; 956*68868Seric sprintf(buf, "Will-Retry-Until: %s", 95767963Seric arpadate(ctime(&xdate))); 95867963Seric putline(buf, mci); 95967963Seric } 96067880Seric } 96167880Seric } 96268028Seric #endif 96367880Seric 96467880Seric /* 9654318Seric ** Output text of original message 9664318Seric */ 9674318Seric 96865870Seric putline("", mci); 96968564Seric if (bitset(EF_HAS_DF, e->e_parent->e_flags)) 9704199Seric { 97168802Seric sendbody = !bitset(EF_NO_BODY_RETN, e->e_parent->e_flags) && 97268802Seric !bitset(EF_NO_BODY_RETN, e->e_flags); 97368559Seric 97467880Seric if (e->e_msgboundary == NULL) 97567880Seric { 97668559Seric if (sendbody) 97767880Seric putline(" ----- Original message follows -----\n", mci); 97867880Seric else 97967880Seric putline(" ----- Message header follows -----\n", mci); 98067880Seric (void) fflush(mci->mci_out); 98167880Seric } 9825984Seric else 9835984Seric { 98459730Seric (void) sprintf(buf, "--%s", e->e_msgboundary); 98565870Seric putline(buf, mci); 98668859Seric (void) sprintf(buf, "Content-Type: %s", 98768859Seric sendbody ? "message/rfc822" 98868859Seric : "text/rfc822-headers"); 98968228Seric putline(buf, mci); 9905984Seric } 99167981Seric putline("", mci); 99268228Seric putheader(mci, e->e_parent->e_header, e->e_parent); 99368559Seric if (sendbody) 99468228Seric putbody(mci, e->e_parent, e->e_msgboundary); 99568228Seric else if (e->e_msgboundary == NULL) 99667546Seric { 99767546Seric putline("", mci); 99865870Seric putline(" ----- Message body suppressed -----", mci); 99967546Seric } 10004199Seric } 100168228Seric else if (e->e_msgboundary == NULL) 100210170Seric { 100365870Seric putline(" ----- No message was collected -----\n", mci); 100410170Seric } 10054318Seric 100660010Seric if (e->e_msgboundary != NULL) 100760010Seric { 100865870Seric putline("", mci); 100960010Seric (void) sprintf(buf, "--%s--", e->e_msgboundary); 101065870Seric putline(buf, mci); 101160010Seric } 101265870Seric putline("", mci); 101359730Seric 10144318Seric /* 10154318Seric ** Cleanup and exit 10164318Seric */ 10174318Seric 1018297Seric if (errno != 0) 10196978Seric syserr("errbody: I/O error"); 1020297Seric } 102158144Seric /* 102268228Seric ** SMTPTODSN -- convert SMTP to DSN status code 102368228Seric ** 102468228Seric ** Parameters: 102568228Seric ** smtpstat -- the smtp status code (e.g., 550). 102668228Seric ** 102768228Seric ** Returns: 102868228Seric ** The DSN version of the status code. 102968228Seric */ 103068228Seric 103168228Seric char * 103268228Seric smtptodsn(smtpstat) 103368228Seric int smtpstat; 103468228Seric { 103568857Seric if (smtpstat < 0) 103668857Seric return "4.4.2"; 103768857Seric 103868228Seric switch (smtpstat) 103968228Seric { 104068228Seric case 450: /* Req mail action not taken: mailbox unavailable */ 104168228Seric return "4.2.0"; 104268228Seric 104368228Seric case 451: /* Req action aborted: local error in processing */ 104468228Seric return "4.3.0"; 104568228Seric 104668228Seric case 452: /* Req action not taken: insufficient sys storage */ 104768228Seric return "4.3.1"; 104868228Seric 104968228Seric case 500: /* Syntax error, command unrecognized */ 105068228Seric return "5.5.2"; 105168228Seric 105268228Seric case 501: /* Syntax error in parameters or arguments */ 105368228Seric return "5.5.4"; 105468228Seric 105568228Seric case 502: /* Command not implemented */ 105668228Seric return "5.5.1"; 105768228Seric 105868228Seric case 503: /* Bad sequence of commands */ 105968228Seric return "5.5.1"; 106068228Seric 106168228Seric case 504: /* Command parameter not implemented */ 106268228Seric return "5.5.4"; 106368228Seric 106468228Seric case 550: /* Req mail action not taken: mailbox unavailable */ 106568228Seric return "5.2.0"; 106668228Seric 106768228Seric case 551: /* User not local; please try <...> */ 106868228Seric return "5.1.6"; 106968228Seric 107068228Seric case 552: /* Req mail action aborted: exceeded storage alloc */ 107168228Seric return "5.2.2"; 107268228Seric 107368228Seric case 553: /* Req action not taken: mailbox name not allowed */ 107468228Seric return "5.1.3"; 107568228Seric 107668228Seric case 554: /* Transaction failed */ 107768228Seric return "5.0.0"; 107868228Seric } 107968228Seric 108068228Seric if ((smtpstat / 100) == 2) 108168228Seric return "2.0.0"; 108268228Seric if ((smtpstat / 100) == 4) 108368228Seric return "4.0.0"; 108468228Seric return "5.0.0"; 108568228Seric } 108668228Seric /* 108768228Seric ** XTEXTIFY -- take regular text and turn it into DSN-style xtext 108868228Seric ** 108968228Seric ** Parameters: 109068228Seric ** t -- the text to convert. 109168228Seric ** 109268228Seric ** Returns: 109368228Seric ** The xtext-ified version of the same string. 109468228Seric */ 109568228Seric 109668228Seric char * 109768228Seric xtextify(t) 109868228Seric register char *t; 109968228Seric { 110068228Seric register char *p; 110168228Seric int l; 110268228Seric int nbogus; 110368228Seric static char *bp = NULL; 110468228Seric static int bplen = 0; 110568228Seric 110668228Seric /* figure out how long this xtext will have to be */ 110768228Seric nbogus = l = 0; 110868228Seric for (p = t; *p != '\0'; p++) 110968228Seric { 111068228Seric register int c = (*p & 0xff); 111168228Seric 111268228Seric /* ASCII dependence here -- this is the way the spec words it */ 1113*68868Seric if (c < '!' || c > '~' || c == '+' || c == '\\' || c == '(') 111468228Seric nbogus++; 111568228Seric l++; 111668228Seric } 111768228Seric if (nbogus == 0) 111868228Seric return t; 111968228Seric l += nbogus * 2 + 1; 112068228Seric 112168228Seric /* now allocate space if necessary for the new string */ 112268228Seric if (l > bplen) 112368228Seric { 112468228Seric if (bp != NULL) 112568228Seric free(bp); 112668228Seric bp = xalloc(l); 112768228Seric bplen = l; 112868228Seric } 112968228Seric 113068228Seric /* ok, copy the text with byte expansion */ 113168228Seric for (p = bp; *t != '\0'; ) 113268228Seric { 113368228Seric register int c = (*t++ & 0xff); 113468228Seric 113568228Seric /* ASCII dependence here -- this is the way the spec words it */ 113668228Seric if (c < '!' || c > '~' || c == '+' || c == '\\' || c == '(') 113768228Seric { 113868228Seric *p++ = '+'; 113968228Seric *p++ = "0123456789abcdef"[c >> 4]; 114068228Seric *p++ = "0123456789abcdef"[c & 0xf]; 114168228Seric } 114268228Seric else 114368228Seric *p++ = c; 114468228Seric } 114568228Seric *p = '\0'; 114668228Seric return bp; 114768228Seric } 114868228Seric /* 114968583Seric ** XTEXTOK -- check if a string is legal xtext 115068583Seric ** 115168583Seric ** Xtext is used in Delivery Status Notifications. The spec was 115268583Seric ** taken from draft-ietf-notary-mime-delivery-04.txt. 115368583Seric ** 115468583Seric ** Parameters: 115568583Seric ** s -- the string to check. 115668583Seric ** 115768583Seric ** Returns: 115868583Seric ** TRUE -- if 's' is legal xtext. 115968583Seric ** FALSE -- if it has any illegal characters in it. 116068583Seric */ 116168583Seric 116268583Seric bool 116368583Seric xtextok(s) 116468583Seric char *s; 116568583Seric { 116668583Seric int c; 116768583Seric 116868583Seric while ((c = *s++) != '\0') 116968583Seric { 117068583Seric if (c == '+') 117168583Seric { 117268583Seric c = *s++; 117368583Seric if (!isascii(c) || !isxdigit(c)) 117468583Seric return FALSE; 117568583Seric c = *s++; 117668583Seric if (!isascii(c) || !isxdigit(c)) 117768583Seric return FALSE; 117868583Seric } 117968583Seric else if (c < '!' || c > '~' || c == '\\' || c == '(') 118068583Seric return FALSE; 118168583Seric } 118268583Seric return TRUE; 118368583Seric } 118468583Seric /* 118558144Seric ** PRUNEROUTE -- prune an RFC-822 source route 118658144Seric ** 118758144Seric ** Trims down a source route to the last internet-registered hop. 118858144Seric ** This is encouraged by RFC 1123 section 5.3.3. 118958144Seric ** 119058144Seric ** Parameters: 119158144Seric ** addr -- the address 119258144Seric ** 119358144Seric ** Returns: 119458144Seric ** TRUE -- address was modified 119558144Seric ** FALSE -- address could not be pruned 119658144Seric ** 119758144Seric ** Side Effects: 119858144Seric ** modifies addr in-place 119958144Seric */ 120058144Seric 120158144Seric pruneroute(addr) 120258144Seric char *addr; 120358144Seric { 120466334Seric #if NAMED_BIND 120558144Seric char *start, *at, *comma; 120658144Seric char c; 120758144Seric int rcode; 120858144Seric char hostbuf[BUFSIZ]; 120958144Seric char *mxhosts[MAXMXHOSTS + 1]; 121058144Seric 121158144Seric /* check to see if this is really a route-addr */ 121258144Seric if (*addr != '<' || addr[1] != '@' || addr[strlen(addr) - 1] != '>') 121358144Seric return FALSE; 121458144Seric start = strchr(addr, ':'); 121558144Seric at = strrchr(addr, '@'); 121658144Seric if (start == NULL || at == NULL || at < start) 121758144Seric return FALSE; 121858144Seric 121958144Seric /* slice off the angle brackets */ 122058144Seric strcpy(hostbuf, at + 1); 122158144Seric hostbuf[strlen(hostbuf) - 1] = '\0'; 122258144Seric 122358144Seric while (start) 122458144Seric { 122559273Seric if (getmxrr(hostbuf, mxhosts, FALSE, &rcode) > 0) 122658144Seric { 122758144Seric strcpy(addr + 1, start + 1); 122858144Seric return TRUE; 122958144Seric } 123058144Seric c = *start; 123158144Seric *start = '\0'; 123258144Seric comma = strrchr(addr, ','); 123358144Seric if (comma && comma[1] == '@') 123458144Seric strcpy(hostbuf, comma + 2); 123558144Seric else 123658144Seric comma = 0; 123758144Seric *start = c; 123858144Seric start = comma; 123958144Seric } 124058144Seric #endif 124158144Seric return FALSE; 124258144Seric } 1243