#include <arpa/netopen.h>
#include <arpa/hostnames.h>
static char SccsId
[] = "@(#)mail-dm.c 4.1 7/25/83";
handle the MAIL <user> command over the command connection
see if we have a known user
if mailbox file can't be gotten
tell him it is ok to go ahead with mail
while he doesn't type a period
initial coding Mark Kampe UCLA-ATS
modified 4/13/76 by S. F. Holmgren for Illinois version
modified 6/30/76 by S. F. Holmgren to call getmbox
modified 10/18/76 by J. S. Kravitz to improve net mail header
chown removed by R. Balocca @ CAC, Sunday 1977 February 20
getline removed and limit on line length removed by using
getch and putch added by R. Balocca @ CAC, 1977 March 8 Tuesday
Fixed oversight in above (forgot to translate <crlf> to <lf>)
1977 March 10 Thursday by Rick Balocca @ CAC
Added openmail & closemail, added logging, and fixed several
bugs on or about 12/21/79 by Eric Allman, UCB/INGRES.
Changed to always accept mail -- bad mail will be sent back --
1/9/80 by Eric Allman, UCB/INGRES.
Don't print out 350 enter mail or 256 mail accepted messages --
sendmail will do that. 8/19/81 Eric Allman UCB/INGRES.
register char *p
; /* general use */
/* extern struct io_buf obuf; */
/* get to open mailbox file descriptor */
if( (fout
= openmail(arg
, 0)) < 0 )
for(;;) /* while no error or <crlf>.<crlf> */
/* we are at beginning of line */
write(fout
, "\n***** Sender aborted connection *****\n", 39);
/* is arpa escape for "\r" */
make sure we have a valid user
get open mailbox file descriptor
call rcvdata to receive mail
initial coding 4/13/76 by S. F. Holmgren
modified 10/18/76 by J. S. Kravitz to put net mail header
chown removed by R. Balocca @ CAC, Sunday 1977 February 20
netreply("455 Mail server temporarily unavailable\r\n");
if ((fout
= openmail(arg
, 1)) < 0)
/* open data connection */
netdata
= dataconnection( U4
);
/* say its ok to proceed */
/* get data from net connection and copy to mail file */
/* rcvdata( netdata,mboxfid ); */
if (rcvdata(netdata
, fout
) < 0)
/* close the mail, see if ok; if so say ok */
** OPENMAIL -- Open a channel to the mail server
** Gets the mail server started up ready to handle our
** See if the user is specified.
** If not, send to user "root".
** See if the user exists.
** If not, signal error 450 and return.
** Signal "unavailable" and exit on failure.
** Signal "unavailable" and exit on failure
** Call mailer: /etc/delivermail is preferred.
** Avoid pipe signals in case delivermail dies.
** Return file descriptor.
** The check to see if the user actually exists should
** go away so that we can do real mail forwarding.
** who -- the user to send the mail to.
** mode -- 0 -- called from mail
** File descriptor to send mail to.
** Forks /etc/delivermail or /bin/mail or /usr/bin/mail.
** Becomes "network" in the child.
** 1/9/80 -- Added 050 & 455 reply messages if execl's
** fail. Eric Allman UCB/INGRES.
** 11/26/79 -- Modified to map upper case to lower
** case. Eric Allman UCB/INGRES.
** 11/10/79 -- Written by Eric Allman UCB/INGRES
** 3/6/80 -- Dropped case mapping; delivermail does
** that now. EPA UCB/INGRES.
** 8/19/81 -- Added "mode" parameter; call sendmail
** instead of delivermail. EPA
/* see if the user exists */
/* try to get a pipe to the mailer */
netreply("455 Mail server temporarily unavailable\r\n");
/* try to call something to deliver the mail */
execl("/etc/sendmail", "sendmail", "-v", mode
== 1 ? "-af" : "-am", w
, 0);
/* doesn't seem to be anything around */
netreply("455 Mail server unavailable\r\n");
signal(SIGPIPE
, SIG_IGN
);
** CLOSEMAIL -- Close the mail file and get actual status
** The mail file is closed.
** Wait for the mailer to die.
** If it wasn't there, be non-comittal.
** If it died a violent death, give error.
** fd -- the file descriptor of the mail file.
** 1/9/80 -- Changed to not check for errors in mailing,
** since these will be mailed back.
** 11/10/79 -- Written by Eric Allman UCB/INGRES.
/* close the pipe -- mail should go away */
while ((i
= wait(&st
)) != Mail_pid
)
/* how did this happen? */
logmsg(LOG_ERR
, "mail from host %d to %s: no child",
openparams
.o_frnhost
& 0377, Mail_user
);
/* 'st' is now the status of the mailer */
logmsg(LOG_ERR
, "mail from host %d to %s: status %o",
openparams
.o_frnhost
& 0377, Mail_user
, st
);
netreply("455 Mail not delivered -- local system error\r\n");