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