1*4308Seric /* 2*4308Seric * rmail: front end for mail to stack up those stupid >From ... remote from ... 3*4308Seric * lines and make a correct return address. This works with the -f option 4*4308Seric * to /etc/delivermail so it won't work on systems without delivermail. 5*4308Seric * However, it ought to be easy to modify a standard /bin/mail to do the 6*4308Seric * same thing. 7*4308Seric * 8*4308Seric * NOTE: Rmail is SPECIFICALLY INTENDED for ERNIE COVAX because of its 9*4308Seric * physical position as a gateway between the uucp net and the arpanet. 10*4308Seric * By default, other sites will probably want /bin/rmail to be a link 11*4308Seric * to /bin/mail, as it was intended by BTL. However, other than the 12*4308Seric * (somewhat annoying) loss of information about when the mail was 13*4308Seric * originally sent, rmail should work OK on other systems running uucp. 14*4308Seric * If you don't run uucp you don't even need any rmail. 15*4308Seric */ 16*4308Seric 17*4308Seric static char SccsId[] = "@(#)rmail.c 1.1 09/06/81"; 18*4308Seric 19*4308Seric #include <stdio.h> 20*4308Seric FILE *popen(); 21*4308Seric char *index(); 22*4308Seric 23*4308Seric #define MAILER "/etc/delivermail" 24*4308Seric 25*4308Seric main(argc, argv) 26*4308Seric char **argv; 27*4308Seric { 28*4308Seric FILE *out; /* output to delivermail */ 29*4308Seric char lbuf[512]; /* one line of the message */ 30*4308Seric char from[512]; /* accumulated path of sender */ 31*4308Seric char ufrom[64]; /* user on remote system */ 32*4308Seric char sys[64]; /* a system in path */ 33*4308Seric char junk[512]; /* scratchpad */ 34*4308Seric char cmd[512]; 35*4308Seric char *to, *cp; 36*4308Seric 37*4308Seric to = argv[1]; 38*4308Seric if (argc != 2) { 39*4308Seric fprintf(stderr, "Usage: rmail user\n"); 40*4308Seric exit(1); 41*4308Seric } 42*4308Seric 43*4308Seric for (;;) { 44*4308Seric fgets(lbuf, sizeof lbuf, stdin); 45*4308Seric if (strncmp(lbuf, "From ", 5) && strncmp(lbuf, ">From ", 6)) 46*4308Seric break; 47*4308Seric /* sscanf(lbuf, "%s %s %s %s %s %s %s remote from %s", junk, ufrom, junk, junk, junk, junk, junk, sys); */ 48*4308Seric sscanf(lbuf, "%s %s", junk, ufrom); 49*4308Seric cp = lbuf; 50*4308Seric for (;;) { 51*4308Seric cp = index(cp+1, 'r'); 52*4308Seric if (cp == NULL) 53*4308Seric cp = "remote from somewhere"; 54*4308Seric #ifdef DEBUG 55*4308Seric printf("cp='%s'\n", cp); 56*4308Seric #endif 57*4308Seric if (strncmp(cp, "remote from ", 12)==0) 58*4308Seric break; 59*4308Seric } 60*4308Seric sscanf(cp, "remote from %s", sys); 61*4308Seric strcat(from, sys); 62*4308Seric strcat(from, "!"); 63*4308Seric #ifdef DEBUG 64*4308Seric printf("ufrom='%s', sys='%s', from now '%s'\n", ufrom, sys, from); 65*4308Seric #endif 66*4308Seric } 67*4308Seric strcat(from, ufrom); 68*4308Seric 69*4308Seric sprintf(cmd, "%s -r%s %s", MAILER, from, to); 70*4308Seric #ifdef DEBUG 71*4308Seric printf("cmd='%s'\n", cmd); 72*4308Seric #endif 73*4308Seric out = popen(cmd, "w"); 74*4308Seric fputs(lbuf, out); 75*4308Seric while (fgets(lbuf, sizeof lbuf, stdin)) 76*4308Seric fputs(lbuf, out); 77*4308Seric pclose(out); 78*4308Seric } 79*4308Seric 80*4308Seric /* 81*4308Seric * Return the ptr in sp at which the character c appears; 82*4308Seric * NULL if not found 83*4308Seric */ 84*4308Seric 85*4308Seric char * 86*4308Seric index(sp, c) 87*4308Seric register char *sp, c; 88*4308Seric { 89*4308Seric do { 90*4308Seric if (*sp == c) 91*4308Seric return(sp); 92*4308Seric } while (*sp++); 93*4308Seric return(NULL); 94*4308Seric } 95