SCCSID(@
(#)usersmtp.c 3.25 %G% (no SMTP));
SCCSID(@
(#)usersmtp.c 3.25 %G%);
** SMTPINIT -- initialize SMTP.
** Opens the connection and sends the initial protocol.
** m -- mailer to create connection to.
** pvp -- pointer to parameter vector to pass to
** ctladdr -- controlling address for this mailer.
** appropriate exit status -- EX_OK on success.
** creates connection and sends initial protocol.
# define REPLYTYPE(r) ((r) / 100)
# define REPLYCLASS(r) (((r) / 10) % 10)
static FILE *SmtpOut
; /* output file */
static FILE *SmtpIn
; /* input file */
static int SmtpPid
; /* pid of mailer */
static int SmtpErrstat
; /* error status if open fails */
smtpinit(m
, pvp
, ctladdr
)
extern char *canonname();
** Open the connection to the mailer.
SmtpPid
= openmailer(m
, pvp
, ctladdr
, TRUE
, &SmtpOut
, &SmtpIn
);
printf("smtpinit: cannot open: Errstat %d errno %d\n",
** Get the greeting message.
** This should appear spontaneously.
if (r
< 0 || REPLYTYPE(r
) != 2)
** Send the HELO command.
** My mother taught me to always introduce myself.
smtpmessage("HELO %s", HostName
);
else if (REPLYTYPE(r
) == 5)
else if (REPLYTYPE(r
) != 2)
** Send the HOPS command.
** This is non-standard and may give an "unknown command".
** It can give a "bad hop count" error if the hop
** Send the MAIL command.
** Designates the sender.
expand("$g", buf
, &buf
[sizeof buf
- 1], CurEnv
);
if (CurEnv
->e_from
.q_mailer
== LocalMailer
||
!bitset(M_FULLSMTP
, m
->m_flags
))
smtpmessage("MAIL From:<%s>", canonname(buf
, 1));
smtpmessage("MAIL From:<@%s%c%s>", HostName
,
buf
[0] == '@' ? ',' : ':', canonname(buf
, 1));
if (r
< 0 || REPLYTYPE(r
) == 4)
** SMTPRCPT -- designate recipient.
** to -- address of recipient.
** exit status corresponding to recipient status.
** Sends the mail via SMTP.
extern char *canonname();
smtpmessage("RCPT To:<%s>", canonname(to
->q_user
, 2));
if (r
< 0 || REPLYTYPE(r
) == 4)
else if (REPLYTYPE(r
) == 2)
else if (r
== 550 || r
== 551 || r
== 553)
else if (r
== 552 || r
== 554)
** SMTPFINISH -- finish up sending all the SMTP protocol.
** m -- mailer being sent to.
** e -- the envelope for this message.
** exit status corresponding to DATA command.
** Dot hiding is done here.
if (r
< 0 || REPLYTYPE(r
) == 4)
(*e
->e_puthdr
)(SmtpOut
, m
, CurEnv
);
(*e
->e_putbody
)(SmtpOut
, m
, TRUE
);
if (r
< 0 || REPLYTYPE(r
) == 4)
else if (r
== 552 || r
== 554)
** SMTPQUIT -- close the SMTP connection.
** name -- name of mailer we are quitting.
** showresp -- if set, give a response message.
** sends the final protocol and closes the connection.
i
= endmailer(SmtpPid
, name
);
giveresponse(i
, TRUE
, LocalMailer
);
** REPLY -- read arpanet reply
** flushes the mail file.
** Read the input line, being careful not to hang.
/* actually do the read */
(void) fflush(Xscript
); /* for debugging */
p
= sfgets(buf
, sizeof buf
, SmtpIn
);
/* log the input in the transcript for future error returns */
if (Verbose
&& !HoldErrs
)
nmessage(Arpa_Info
, "%s", buf
);
fprintf(Xscript
, "%s\n", buf
);
/* if continuation is required, we can go on */
if (buf
[3] == '-' || !isdigit(buf
[0]))
/* decode the reply code */
/* extra semantics: 0xx codes are "informational" */
** SMTPMESSAGE -- send message to server
** writes message to SmtpOut.
(void) sprintf(buf
, f
, a
, b
, c
);
if (tTd(18, 1) || (Verbose
&& !HoldErrs
))
nmessage(Arpa_Info
, ">>> %s", buf
);
fprintf(Xscript
, " >>> %s\n", buf
);
fprintf(SmtpOut
, "%s\r\n", buf
);