Commit | Line | Data |
---|---|---|
9adc8f2c EA |
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 | |
0f5791a6 | 4 | * to /usr/lib/sendmail so it won't work on systems without sendmail. |
9adc8f2c EA |
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 | ||
0f5791a6 | 17 | static char SccsId[] = "@(#)rmail.c 3.1 %G%"; |
9adc8f2c | 18 | |
0f5791a6 EA |
19 | # include <stdio.h> |
20 | # include <sysexits.h> | |
21 | # include "useful.h" | |
9adc8f2c | 22 | |
0f5791a6 EA |
23 | extern FILE *popen(); |
24 | extern char *index(); | |
25 | ||
26 | bool Debug; | |
27 | ||
28 | # define MAILER "/usr/lib/sendmail" | |
9adc8f2c EA |
29 | |
30 | main(argc, argv) | |
0f5791a6 | 31 | char **argv; |
9adc8f2c | 32 | { |
0f5791a6 | 33 | FILE *out; /* output to sendmail */ |
9adc8f2c EA |
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 */ | |
0f5791a6 EA |
39 | char cmd[2000]; |
40 | register char *cp; | |
9adc8f2c | 41 | |
0f5791a6 EA |
42 | # ifdef DEBUG |
43 | if (argc > 1 && strcmp(argv[1], "-T") == 0) | |
44 | { | |
45 | Debug = TRUE; | |
46 | argc--; | |
47 | argv++; | |
9adc8f2c | 48 | } |
0f5791a6 | 49 | # endif DEBUG |
9adc8f2c | 50 | |
0f5791a6 EA |
51 | if (argc < 2) |
52 | { | |
53 | fprintf(stderr, "Usage: rmail user ...\n"); | |
54 | exit(EX_USAGE); | |
55 | } | |
56 | ||
57 | for (;;) | |
58 | { | |
9adc8f2c | 59 | fgets(lbuf, sizeof lbuf, stdin); |
0f5791a6 | 60 | if (strncmp(lbuf, "From ", 5) != 0 && strncmp(lbuf, ">From ", 6) != 0) |
9adc8f2c | 61 | break; |
9adc8f2c EA |
62 | sscanf(lbuf, "%s %s", junk, ufrom); |
63 | cp = lbuf; | |
0f5791a6 EA |
64 | for (;;) |
65 | { | |
9adc8f2c EA |
66 | cp = index(cp+1, 'r'); |
67 | if (cp == NULL) | |
68 | cp = "remote from somewhere"; | |
69 | #ifdef DEBUG | |
0f5791a6 EA |
70 | if (Debug) |
71 | printf("cp='%s'\n", cp); | |
9adc8f2c EA |
72 | #endif |
73 | if (strncmp(cp, "remote from ", 12)==0) | |
74 | break; | |
75 | } | |
76 | sscanf(cp, "remote from %s", sys); | |
77 | strcat(from, sys); | |
78 | strcat(from, "!"); | |
79 | #ifdef DEBUG | |
0f5791a6 EA |
80 | if (Debug) |
81 | printf("ufrom='%s', sys='%s', from now '%s'\n", ufrom, sys, from); | |
9adc8f2c EA |
82 | #endif |
83 | } | |
84 | strcat(from, ufrom); | |
85 | ||
0f5791a6 EA |
86 | sprintf(cmd, "%s -f%s", MAILER, from); |
87 | while (*++argv != NULL) | |
88 | { | |
89 | strcat(cmd, " '"); | |
90 | strcat(cmd, *argv); | |
91 | strcat(cmd, "'"); | |
92 | } | |
9adc8f2c | 93 | #ifdef DEBUG |
0f5791a6 EA |
94 | if (Debug) |
95 | printf("cmd='%s'\n", cmd); | |
9adc8f2c EA |
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); | |
9adc8f2c | 102 | |
0f5791a6 | 103 | exit(EX_OK); |
9adc8f2c | 104 | } |