2 Proprietary Rand Corporation
, 1981.
3 Further distribution of
this software
4 subject to the terms of the Rand
8 static char *sccsid
= "@(#)from rmail.c 4.1 (Berkeley) 10/1/80";
10 * rmail: front end for mail to stack up those stupid >From ... remote from ...
11 * lines and make a correct return address. This works with the -f option
12 * to /etc/delivermail so it won't work on systems without delivermail.
13 * However, it ought to be easy to modify a standard /bin/mail to do the
16 * NOTE: Rmail is SPECIFICALLY INTENDED for ERNIE COVAX because of its
17 * physical position as a gateway between the uucp net and the arpanet.
18 * By default, other sites will probably want /bin/rmail to be a link
19 * to /bin/mail, as it was intended by BTL. However, other than the
20 * (somewhat annoying) loss of information about when the mail was
21 * originally sent, rmail should work OK on other systems running uucp.
22 * If you don't run uucp you don't even need any rmail.
24 * This version revised around New Year's Day 1981 to interface with
25 * Rand's MH system. The nature of the revision is to (1) do nothing
26 * if the destination is uucp-remote (note the assumption of single
27 * destination) and (2) to call "/etc/mh/deliver" to do the deed.
29 * Revised Aug 1981 to add NOGATEWAY screen. Also fixed a few bugs.
32 * 5/8/82: Tack on uu-Date: if msg has no date. PK.
48 FILE *out
; /* output to delivermail */
49 char *tmpfil
; /* file name of same */
50 char tmpfila
[24]; /* array for tmpfil */
51 char *to
; /* argv[1] */
52 char from
[512]; /* accumulated path of sender */
53 char lbuf
[512]; /* one line of the message */
55 char d1
[10], d2
[10], d3
[10], d4
[10], d5
[10]; /*** ctime() fields ***/
58 int netaddr
; /* set if "to" contains an arpanet address */
64 char ufrom
[64]; /* user on remote system */
65 char sys
[64]; /* a system in path */
66 char junk
[512]; /* scratchpad */
72 fprintf(stderr
, "Usage: rmail user\n");
80 sprintf (tmpfil
, "/tmp/%s", makename ("mail",".tmp"));
81 if ((out
=fopen(tmpfil
, "w")) == NULL
) {
82 fprintf(stderr
, "Can't create %s\n", tmpfil
);
87 fgets(lbuf
, sizeof lbuf
, stdin
);
88 if (strncmp(lbuf
, "From ", 5) && strncmp(lbuf
, ">From ", 6))
90 fputs(lbuf
, out
); /* Save--in case we are just forwarding */
91 /***/ sscanf(lbuf
, "%s %s %s %s %s %s %s remote from %s",
92 junk
, ufrom
, d1
, d2
, d3
, d4
, d5
, sys
);
93 /* sscanf(lbuf, "%s %s", junk, ufrom); */
96 cp
= index(cp
+1, 'r');
98 cp
= "remote from somewhere";
100 printf("cp='%s'\n", cp
);
102 if (strncmp(cp
, "remote from ", 12) == MATCH
)
105 sscanf(cp
, "remote from %s", sys
);
109 printf("ufrom='%s', sys='%s', from now '%s'\n", ufrom
, sys
, from
);
115 printf("from now '%s'\n", from
);
120 netaddr
= isarpa(to
); /* Arpanet destination? */
123 if(netaddr
&& !okhost(sys
))
126 returnmail("Sorry, not an Arpanet gateway!");
131 if (index (to
, '!') && !netaddr
) {
133 if (index (to
, '!')) {
135 /* Just forwarding! */
142 /* fprintf(out, "To: %s\n",to); */
145 if( !((cp
= index(lbuf
, ':')) && (cp
- lbuf
< NAMESZ
))) {
146 fputs("\n",out
);/* Doesn't look good; terminate hdr */
149 putmsg(badhdr
?NOPARSE
:PARSE
);
161 printf("%s would get called here; Delivery to: %s \n", mh_deliver
,to
);
166 if ((pid
=fork()) == -1) {
167 fprintf(stderr
, "Cannot fork Deliver!\n");
169 #ifndef DEBUG /* Extra precaution */
175 while(((waitid
= wait(&sts
)) != pid
) && (waitid
!= -1));
177 #ifndef DEBUG /* Extra precaution */
182 execl(mh_deliver
, "deliver", "-deliver", to
, tmpfil
, 0);
184 perror( "Cannot exec Deliver ");
192 isarpa(str
) /* Gateway to Arpanet? */
197 if (index (str
, '@'))
201 if((cp
= index(cp
, ' ')) == NULL
)
205 if ((strncmp(cp
, "at ", 3) == MATCH
) ||
206 (strncmp(cp
, "AT ", 3) == MATCH
) ||
207 (strncmp(cp
, "At ", 3) == MATCH
))
214 okhost(str
) /* Host permitted to use us as an arpanet gateway? */
219 for (i
=0; rhosts
[i
]; i
++)
220 if (strcmp (str
, rhosts
[i
]) == MATCH
)
231 printf("returnmail()\n");
236 fprintf(out
, "To: %s\n", from
);
238 fputs (message
, out
);
239 fputs("\n\n\n*--------------RETURNED MESSAGE---------------*\n\n",
248 #include <sys/types.h>
249 #include <sys/timeb.h>
255 register char *t
, *p
;
259 static char *wday
[] = {
269 now
= time((long *)0);
272 tmp
= localtime(&now
);
273 p
= timezone(tb
.timezone
, tmp
->tm_isdst
);
275 /* day 13 Apr 1981 20 :38 -PST */
276 fprintf(out
, "Date: %sday, %.2s %.3s %.4s %.2s:%.2s-%.3s\n",
277 wday
[tmp
->tm_wday
], t
+8, t
+4, t
+20, t
+11, t
+14, p
);
286 fprintf(out
, "From: %s at %s\n",from
, HOSTNAME
);
288 fprintf(out
, "From: %s\n", from
);
290 fprintf(out
, "From: %s\n",from
);
304 if (uleqn(lbuf
, "date:", 5) == 0)
307 while (fgets(lbuf
, sizeof lbuf
, stdin
)) {
308 if(lbuf
[0] == '\n' ) { /* end of hdrs */
313 if (uleqn(lbuf
, "date:", 5) == 0)
325 while (fgets(lbuf
, sizeof lbuf
, stdin
))
332 /* Truncate those "...remote from..." header lines. */
333 /* They're kept only if the message is to be uucp-forwarded */
336 fclose (out
); out
=fopen(tmpfil
, "w");
343 * Compare strings (at most n bytes) without regard to case.
344 * Returns: s1>s2: >0, s1==s2: 0, s1<s2: <0.
348 register char *s1
, *s2
;
352 while (--n
>= 0 && (*s1
|040) == (*s2
|040)) {
357 return(n
<0 ? 0 : (*s1
|040) - (*s2
|040));
365 /* day 13 Apr 1981 20 :38 -PST */
366 fprintf(out
, "Date: %sday, %.2s %.3s %.4s %.2s:%.2s-%.3s\n",
367 prefix(d1
), d3
, d2
, d5
, d4
, d4
+3, "???");
374 static char *wday
[] = {
387 for(wp
=wday
; wp
; wp
++)
388 if(uleqn(str
, *wp
, 3) == 0)