Commit | Line | Data |
---|---|---|
9adc8f2c | 1 | /* |
b8b8df54 EA |
2 | ** RMAIL -- UUCP mail server. |
3 | ** | |
4 | ** This program reads the >From ... remote from ... lines that | |
5 | ** UUCP is so fond of and turns them into something reasonable. | |
6 | ** It calls sendmail giving it a -f option built from these | |
7 | ** lines. | |
09fa495a | 8 | */ |
9adc8f2c | 9 | |
0f5791a6 EA |
10 | # include <stdio.h> |
11 | # include <sysexits.h> | |
12 | # include "useful.h" | |
b5fd168f | 13 | # include "conf.h" |
9adc8f2c | 14 | |
3e606cd4 | 15 | SCCSID(@(#)rmail.c 3.10 (Berkeley) %G%); |
4e5e456f | 16 | |
0f5791a6 EA |
17 | extern FILE *popen(); |
18 | extern char *index(); | |
19 | ||
20 | bool Debug; | |
21 | ||
22 | # define MAILER "/usr/lib/sendmail" | |
9adc8f2c EA |
23 | |
24 | main(argc, argv) | |
0f5791a6 | 25 | char **argv; |
9adc8f2c | 26 | { |
0f5791a6 | 27 | FILE *out; /* output to sendmail */ |
9adc8f2c EA |
28 | char lbuf[512]; /* one line of the message */ |
29 | char from[512]; /* accumulated path of sender */ | |
30 | char ufrom[64]; /* user on remote system */ | |
31 | char sys[64]; /* a system in path */ | |
32 | char junk[512]; /* scratchpad */ | |
0f5791a6 EA |
33 | char cmd[2000]; |
34 | register char *cp; | |
09fa495a | 35 | register char *uf; /* ptr into ufrom */ |
9777ef27 | 36 | int i; |
9adc8f2c | 37 | |
0f5791a6 EA |
38 | # ifdef DEBUG |
39 | if (argc > 1 && strcmp(argv[1], "-T") == 0) | |
40 | { | |
41 | Debug = TRUE; | |
42 | argc--; | |
43 | argv++; | |
9adc8f2c | 44 | } |
0f5791a6 | 45 | # endif DEBUG |
9adc8f2c | 46 | |
0f5791a6 EA |
47 | if (argc < 2) |
48 | { | |
49 | fprintf(stderr, "Usage: rmail user ...\n"); | |
50 | exit(EX_USAGE); | |
51 | } | |
52 | ||
b8b8df54 EA |
53 | strcpy(from, ""); |
54 | strcpy(ufrom, "/dev/null"); | |
55 | ||
0f5791a6 EA |
56 | for (;;) |
57 | { | |
74c5fe7c | 58 | (void) fgets(lbuf, sizeof lbuf, stdin); |
0f5791a6 | 59 | if (strncmp(lbuf, "From ", 5) != 0 && strncmp(lbuf, ">From ", 6) != 0) |
9adc8f2c | 60 | break; |
ed45aae1 | 61 | (void) sscanf(lbuf, "%s %s", junk, ufrom); |
9adc8f2c | 62 | cp = lbuf; |
09fa495a | 63 | uf = ufrom; |
0f5791a6 EA |
64 | for (;;) |
65 | { | |
9adc8f2c EA |
66 | cp = index(cp+1, 'r'); |
67 | if (cp == NULL) | |
09fa495a EA |
68 | { |
69 | register char *p = rindex(uf, '!'); | |
70 | ||
71 | if (p != NULL) | |
72 | { | |
73 | *p = '\0'; | |
74 | strcpy(sys, uf); | |
75 | uf = p + 1; | |
76 | break; | |
77 | } | |
9adc8f2c | 78 | cp = "remote from somewhere"; |
09fa495a | 79 | } |
9adc8f2c | 80 | #ifdef DEBUG |
0f5791a6 EA |
81 | if (Debug) |
82 | printf("cp='%s'\n", cp); | |
9adc8f2c EA |
83 | #endif |
84 | if (strncmp(cp, "remote from ", 12)==0) | |
85 | break; | |
86 | } | |
09fa495a EA |
87 | if (cp != NULL) |
88 | (void) sscanf(cp, "remote from %s", sys); | |
9adc8f2c EA |
89 | strcat(from, sys); |
90 | strcat(from, "!"); | |
91 | #ifdef DEBUG | |
0f5791a6 | 92 | if (Debug) |
09fa495a | 93 | printf("ufrom='%s', sys='%s', from now '%s'\n", uf, sys, from); |
9adc8f2c EA |
94 | #endif |
95 | } | |
3e606cd4 | 96 | strcat(from, uf); |
9adc8f2c | 97 | |
4e5e456f | 98 | (void) sprintf(cmd, "%s -em -f%s", MAILER, from); |
0f5791a6 EA |
99 | while (*++argv != NULL) |
100 | { | |
101 | strcat(cmd, " '"); | |
674f6e70 EA |
102 | if (**argv == '(') |
103 | strncat(cmd, *argv + 1, strlen(*argv) - 2); | |
104 | else | |
105 | strcat(cmd, *argv); | |
0f5791a6 EA |
106 | strcat(cmd, "'"); |
107 | } | |
9adc8f2c | 108 | #ifdef DEBUG |
0f5791a6 EA |
109 | if (Debug) |
110 | printf("cmd='%s'\n", cmd); | |
9adc8f2c EA |
111 | #endif |
112 | out = popen(cmd, "w"); | |
113 | fputs(lbuf, out); | |
114 | while (fgets(lbuf, sizeof lbuf, stdin)) | |
115 | fputs(lbuf, out); | |
9777ef27 EA |
116 | i = pclose(out); |
117 | if ((i & 0377) != 0) | |
118 | { | |
119 | fprintf(stderr, "pclose: status 0%o\n", i); | |
120 | exit(EX_OSERR); | |
121 | } | |
9adc8f2c | 122 | |
9777ef27 | 123 | exit((i >> 8) & 0377); |
9adc8f2c | 124 | } |