Return-to-sender version of mail.c
espo at bpa.UUCP
espo at bpa.UUCP
Sat Oct 22 02:09:10 AEST 1983
Did you ever sit and wonder "I hope I sent that mail to the
right person? ; Sure hope that sys1!sys2... still has a uucp
link so that my mail gets to sys3!person?" ??
Well so have I. That's why I've made some modifications to the
mail.c source program. These mods are made to, (1) set up a
return address string when mailing to any remote, (2) return-to
sender any mail it cannot deliver as long as there's a return
address, (3) forward to the root login any mail that cannot be
delivered AND has no return address.
(NOTE: I figure that whoever gets root's mail should be
responsible enough to return it - although some might think that
mail is a personal thing, but if it's that personal send it by
U.S. Mail!!).
Included with the mail modifications is a quick and dirty way
to get around those sites with modified uuxqt sources, so that
it will return the return code instead of always zero (0), and not
try to mail a copy of the letter back ONE SITE.
These mods were made for UNIX 4.0 USG, and may not apply for
your particular version, but the idea here could be applied
if one's willing to 'hack around'.
Bob Esposito....bpa!espo
******************************
|
diff oldmail.c newmail.c |
|
******************************
4a5,11
> ** Modified to set-up a return address when remoting to
> ** other systems. If mail fails anywhere in the forwarding
> ** process, the letter is returned to sender informing them
> ** that the mail was undeliverable.
> **
> ** Bob Esposito..bpa!espo
> **
51a59
> char retaddr[LSIZE];
70a79
> int rmt = 0;
118c127,129
< else
---
> else {
> if(argv[0][0] == 'r')
> rmt++;
119a131
> }
491a504,506
> if (rmt)
> if (retto(line))
> strncpy(retaddr,&line[16],strlen(&line[16])-1);
542a558
> char *addr;
544a561
> int retcode;
546a564,566
> if (!rmt)
> strcpy(addr, name);
>
558a579,580
> if (!rmt)
> parseaddr(addr);
568a591,592
> if (!rmt)
> fprintf(rmf, "Return Address: %s\n", retaddr);
570c594,608
< return(pclose(rmf)==0 ? 1 : 0);
---
> retcode = pclose(rmf);
> if (retcode == 0)
> return(1);
> else if (!rmt && retcode != 0)
> return(0);
> else if (retcode != 0 && rmt && (strlen(retaddr) > 0))
> return(retosndr(retaddr));
> else if (retcode != 0) {
> if((rmf=popen("mail root", "w")) == NULL)
> return(0);
> fprintf(rmf, "Mail Failed. No return address\n");
> copylet(n, rmf, ZAP);
> return(pclose(rmf)==0 ? 1 : 0);
> }
> return(0);
578a617
> FILE *rmf;
596a636,644
> if (rmt && strlen(retaddr) > 0)
> return(retosndr(retaddr));
> else if (rmt) {
> if((rmf=popen("mail root", "w")) == NULL)
> return(0);
> fprintf(rmf, "Mail Failed. No return address\n");
> copylet(n, rmf, ZAP);
> return(pclose(rmf)==0 ? 1 : 0);
> }
732a781,868
> }
>
> parseaddr(addr)
> char *addr;
> {
> char *p;
> int len = 0;
>
> p = addr;
>
> while(*p != '\0') {
> len++;
> p++;
> }
> p--;
>
> while(*p != '!') {
> len--;
> p--;
> }
>
> *p-- = '\0';
> len--;
>
> while(len-- >= 1) {
> if(*p != '!') {
> p--;
> continue;
> }
> if(len == 1)
> strcat(retaddr, p);
> else
> strcat(retaddr, p+1);
> strcat(retaddr, "!");
> *p-- = '\0';
> }
> strcat(retaddr, p+1);
> strcat(retaddr, "!");
> strcat(retaddr, thissys);
> strcat(retaddr, "!");
> strcat(retaddr, my_name);
> }
>
> retto(lp)
> register char *lp;
> {
>
> register char *p;
>
> for( p = "Return Address: "; *p; )
> if (*lp++ != *p++)
> return(0);
> return(1);
> }
>
> retosndr(addr)
> char *addr;
> {
> register char *p;
> char retcmd[64];
> FILE *rmf, *popen();
>
> do {
> if((p=strchr(addr, '!')) == NULL)
> return(0);
> *p++ = '\0';
> if(strcmp(addr, thissys) == 0) {
> addr = p;
> if((p=strchr(addr, '!')) == NULL)
> return(0);
> *p++ = '\0';
> break;
> }
> addr = p;
> } while(*p);
>
> if(strchr(p, '!'))
> sprintf(retcmd, "uux - %s!rmail \\(%s\\)", addr, p);
> else
> sprintf(retcmd, "uux - %s!rmail %s", addr, p);
>
> if((rmf=popen(retcmd, "w")) == NULL)
> return(0);
>
> fprintf(rmf, "* Return to sender - can't deliver *\n");
> copylet(0, rmf, ZAP);
> return(pclose(rmf)==0 ? 1 : 0);
> return(1);
***********************************
|
diff olduuxqt.c newuuxqt.c |
|
***********************************
15a16
> #define RETMAIL 1 /* indicates system has return-to-sender mail */
279a281,284
> #ifdef RETMAIL
> if (ret != 0 && strcmp(xcmd, "rmail") == SAME)
> cleanup(ret);
> #endif
523a529,531
> #ifdef RETMAIL
> return;
> #endif
More information about the Comp.sources.unix
mailing list