static char sccsid
[] = "@(#)sendberkmail.c 4.1 (Berkeley) %G%";
sendberkmail [-m mach ] [-f addrfrom] [-h hopcnt] -t addrto
Send remote mail to user on mach.
Sendberkmail uses the network to send an mmail command
to the remote machine. It specifies the source, destination,
Sendberkmail uses the -q option of net, so only error msgs
and non-zero return codes will be sent back.
It is best to think of sendberkmail as a transport mechanism:
It takes mail from one machine to another machine (specified
using the -m option) and executes the local mail program
there with a to-address of "addrto", and a from-address
of "addrfrom". If the -m option is not given, it parses the
"addrto" field to get a berkeley network address.
This extreme generality is necessary when destinations are on
different networks, consider a command from the Ing70:
sendberkmail -m csvax -f schmidt@parc -t research!chuck
This is clearly a forwarding function- send mail from the Arpanet
to the Bell Net, which calls our CSVAX.
Alternatively, executed on the CSVAX,
sendberkmail -m ing70 -f research!chuck -t schmidt@parc
sends mail the other way.
There is duplication in the arguments because of
a need to convert to labelled parameters.
See the note in mmail.c to that effect.
-t addrto mail command on remote machine will be
-f addrfrom mail will be "From" addrfrom
-m mach send this mail to the "mach" machine
-h hopcnt if this hopcnt hits a threshold, there
is presumed to be an infinite loop.
char addrto
[BUFSIZ
], addrfrom
[BUFSIZ
], *sn
;
char mchto
= 0, snto
[BUFSIZ
], snfrom
[BUFSIZ
], smchto
[20], mchfrom
;
int cmdstr
[BUFSIZ
], hopcntstr
[20];
while(argc
> 1 && argv
[1][0] == '-'){
hopcnt
= atoi(hopcntstr
);
/* it is important to ignore unknown flags
for compatibility reasons */
if(argc
> 1)strcpy(addrto
,argv
[1]);
fprintf(stderr
,"Usage: sendberkmail mach:user\n");
mchto
= MchSFromAddr(snto
,addrto
);
fprintf(stderr
,"Unknown host %s\n",addrto
);
"Use mail to send to %s on this machine. Mail not delivered.\n",
sprintf(rcmd
,"mail %s",addrto
);
/* handle from address */
sprintf(addrfrom
,"%s:%s",longname(local
),name
);
mchfrom
= MchSFromAddr(snfrom
,addrfrom
);
/* uses new options of mmail */
/* X's are for compatibility with mmail */
sprintf(cmdstr
,"%s XXX XXX XXX -f '%s' -t '%s' -h %d", MMAILCMD
,
sprintf(cmdstr,"%s '%s' %s '%s'", MMAILCMD,snfrom,
mexecl(netcmd
,"net","-m",longname(mchto
),"-q","-l","network",
fprintf(stderr
,"Network is down\n");
if(sn
== NULL
|| *sn
== 0 || *sn
== ' '){
pwd
= getpwuid(getuid()); /* will read passwd file */
if(pwd
!= NULL
) sn
= pwd
->pw_name
;
fprintf(stderr
,"Who are you?\n");