static char sccsid
[] = "@(#)prmail.c 4.1 (Berkeley) %G%";
prmail -f fromaddress [-l username] [-c] [-k]
Print/forward mail on this machine to another machine.
Preferred usage (Has two modes):
A message is printed that there is mail.
This is intended for people who put netmail -c addr
in their .login files, and don't want to
be prompted for their password.
Mail check is indicated by a -c option.
The mail is "mailed" to the fetcher.
If the -r option is given, the mail is also
appended to the mbox file and then removed.
Forward is indicated by the lack of a -c option.
-l username read username's mail
-f fromaddress forward mail to this address
-c is a mail check, don't forward mail.
-k print "No Mail" for all to see
mail seems to reside in one of three places:
1. the user's home directory/.mail
3. /usr/spool/mail/username
the conditional compilation flags for these three forms are:
# define MAILDIR "/usr/mail"
# define MAILDIR "/usr/spool/mail"
char fn
[BUFSIZ
],*s
,username
[20],
fromaddress
[BUFSIZ
],toaddress
[BUFSIZ
],
fMailCheck
=0, *stimeMail
,fquiet
= 1;
case 'c': fMailCheck
++; break;
case 'f': harg(fromaddress
); break;
case 'k': fquiet
= 0; break;
case 'l': harg(username
); break;
/* it is important to ignore unknown flags for
/* get the name of the user who's mail we're reading */
fprintf(stderr
,"Unknown user\n");
/* handle mail directory in user's directory */
/* can't do getenv because may be logging in as "network" */
pwd
= getpwnam(username
);
fprintf(stderr
,"no passwd file\n");
sprintf(fn
,"%s/.mail",pwd
->pw_dir
);
sprintf(fn
,"%s/%s",MAILDIR
,username
);
sprintf(toaddress
,"%s:%s", longname(local
),username
);
fprintf(stderr
,"Need a From Address\n");
/* don't send anything back if nothing to send */
if(stat(fn
,&statbuf
) < 0 || getsize(&statbuf
) == 0L) {
printf("No mail for %s on the %s machine.\n",
username
,longname(local
));
/* if a mail check, print message and exit */
ltimeMail
= statbuf
.st_mtime
;
stimeMail
= ctime(<imeMail
);
stimeMail
[strlen(stimeMail
) - 6] = 0;
"\"%s\" has mail on the %s machine. \nLast updated on %s. \n",
username
,longname(local
),stimeMail
);
printf("File %s:%s, Length %ld characters. \n",
longname(local
),fn
,getsize(&statbuf
));
/* read the mail and mail it to the account asking for it */
/* send mail to "fromaddress", as from "toaddress" */
ret
= mailmail(fn
,fromaddress
);
ret
= RcAppendMail(fn
,username
);
if(ret
< 0)fprintf(stderr
,"Mail not removed\n");
/* mail contents of file fn to user "toaddress" */
/* read file and mail each message separately */
/* returns return code of executing the mail prorgam */
fdcmd
= mailopen(toaddress
,NULL
,1,0);
/* read line with from on it */
if(line
[0] == 0)fgets(line
,BUFSIZ
,fdfile
);
/* insert a > before the first from line */
fprintf(fdcmd
,">%s",line
);
while(fgets(line
,BUFSIZ
,fdfile
) != NULL
){
if(strncmp(line
,"From ",5) == 0){
"Non-zero return code (%d) from the mail program\n",
RcAppendMail(fnFrom) returns a return code
Copy mail from fnFrom to the end of the mbox file in the user's
Returns -1 if error, 0 if ok.
Can't use getenv() because if there's no entry in utmp
for machines with multiple names per uid, the getenv() will
return the homedir of the first name/uid pair it finds.
char *shdir
, fnTo
[BUFSIZ
], sBuf
[BUFSIZ
];
if(pwd
== NULL
)return(-1);
if(shdir
== NULL
)return(-1);
sprintf(fnTo
,"%s/mbox",shdir
);
fdFrom
= fopen(fnFrom
,"r");
while((nchar
= fread(sBuf
,1,BUFSIZ
,fdFrom
)) > 0){
if(fwrite(sBuf
,1,nchar
,fdTo
) != nchar
){