-/*****************************************************************************/
-/* SMTP CLIENT STATE CALLBACKS */
-/*****************************************************************************/
-eNextState SMTPC_read_greeting(SmtpOutMsg *SendMsg)
-{
- /* Process the SMTP greeting from the server */
- SMTP_DBG_READ();
-
- if (!SMTP_IS_STATE('2')) {
- if (SMTP_IS_STATE('4'))
- SMTP_VERROR(4);
- else
- SMTP_VERROR(5);
- }
- return eSendReply;
-}
-
-eNextState SMTPC_send_EHLO(SmtpOutMsg *SendMsg)
-{
- /* At this point we know we are talking to a real SMTP server */
-
- /* Do a EHLO command. If it fails, try the HELO command. */
- StrBufPrintf(SendMsg->IO.SendBuf.Buf,
- "EHLO %s\r\n", config.c_fqdn);
-
- SMTP_DBG_SEND();
- return eReadMessage;
-}
-
-eNextState SMTPC_read_EHLO_reply(SmtpOutMsg *SendMsg)
-{
- SMTP_DBG_READ();
-
- if (SMTP_IS_STATE('2')) {
- SendMsg->State ++;
-
- if ((SendMsg->pCurrRelay == NULL) ||
- (SendMsg->pCurrRelay->User == NULL))
- SendMsg->State ++; /* Skip auth... */
- }
- /* else we fall back to 'helo' */
- return eSendReply;
-}
-
-eNextState STMPC_send_HELO(SmtpOutMsg *SendMsg)
-{
- StrBufPrintf(SendMsg->IO.SendBuf.Buf,
- "HELO %s\r\n", config.c_fqdn);
-
- SMTP_DBG_SEND();
- return eReadMessage;
-}
-
-eNextState SMTPC_read_HELO_reply(SmtpOutMsg *SendMsg)
-{
- SMTP_DBG_READ();
-
- if (!SMTP_IS_STATE('2')) {
- if (SMTP_IS_STATE('4'))
- SMTP_VERROR(4);
- else
- SMTP_VERROR(5);
- }
- if ((SendMsg->pCurrRelay == NULL) ||
- (SendMsg->pCurrRelay->User == NULL))
- SendMsg->State ++; /* Skip auth... */
- return eSendReply;
-}
-
-eNextState SMTPC_send_auth(SmtpOutMsg *SendMsg)
-{
- char buf[SIZ];
- char encoded[1024];
-
- if ((SendMsg->pCurrRelay == NULL) ||
- (SendMsg->pCurrRelay->User == NULL))
- SendMsg->State ++; /* Skip auth, shouldn't even come here!... */
- else {
- /* Do an AUTH command if necessary */
- sprintf(buf, "%s%c%s%c%s",
- SendMsg->pCurrRelay->User, '\0',
- SendMsg->pCurrRelay->User, '\0',
- SendMsg->pCurrRelay->Pass);
- CtdlEncodeBase64(encoded, buf,
- strlen(SendMsg->pCurrRelay->User) * 2 +
- strlen(SendMsg->pCurrRelay->Pass) + 2, 0);
- StrBufPrintf(SendMsg->IO.SendBuf.Buf,
- "AUTH PLAIN %s\r\n", encoded);
- }
- SMTP_DBG_SEND();
- return eReadMessage;
-}
-
-eNextState SMTPC_read_auth_reply(SmtpOutMsg *SendMsg)
-{
- /* Do an AUTH command if necessary */
-
- SMTP_DBG_READ();
-
- if (!SMTP_IS_STATE('2')) {
- if (SMTP_IS_STATE('4'))
- SMTP_VERROR(4);
- else
- SMTP_VERROR(5);
- }
- return eSendReply;
-}
-
-eNextState SMTPC_send_FROM(SmtpOutMsg *SendMsg)
-{
- /* previous command succeeded, now try the MAIL FROM: command */
- StrBufPrintf(SendMsg->IO.SendBuf.Buf,
- "MAIL FROM:<%s>\r\n",
- SendMsg->envelope_from);
-
- SMTP_DBG_SEND();
- return eReadMessage;
-}
-
-eNextState SMTPC_read_FROM_reply(SmtpOutMsg *SendMsg)
-{
- SMTP_DBG_READ();
-
- if (!SMTP_IS_STATE('2')) {
- if (SMTP_IS_STATE('4'))
- SMTP_VERROR(4);
- else
- SMTP_VERROR(5);
- }
- return eSendReply;
-}
-
-
-eNextState SMTPC_send_RCPT(SmtpOutMsg *SendMsg)
-{
- /* MAIL succeeded, now try the RCPT To: command */
- StrBufPrintf(SendMsg->IO.SendBuf.Buf,
- "RCPT TO:<%s@%s>\r\n",
- SendMsg->user,
- SendMsg->node);
-
- SMTP_DBG_SEND();
- return eReadMessage;
-}
-
-eNextState SMTPC_read_RCPT_reply(SmtpOutMsg *SendMsg)
-{
- SMTP_DBG_READ();
-
- if (!SMTP_IS_STATE('2')) {
- if (SMTP_IS_STATE('4'))
- SMTP_VERROR(4);
- else
- SMTP_VERROR(5);
- }
- return eSendReply;
-}
-
-eNextState SMTPC_send_DATAcmd(SmtpOutMsg *SendMsg)
-{
- /* RCPT succeeded, now try the DATA command */
- StrBufPlain(SendMsg->IO.SendBuf.Buf,
- HKEY("DATA\r\n"));
-
- SMTP_DBG_SEND();
- return eReadMessage;
-}
-
-eNextState SMTPC_read_DATAcmd_reply(SmtpOutMsg *SendMsg)
-{
- SMTP_DBG_READ();
-
- if (!SMTP_IS_STATE('3')) {
- if (SMTP_IS_STATE('4'))
- SMTP_VERROR(3);
- else
- SMTP_VERROR(5);
- }
- return eSendReply;
-}
-
-eNextState SMTPC_send_data_body(SmtpOutMsg *SendMsg)
-{
- StrBuf *Buf;
- /* If we reach this point, the server is expecting data.*/
-
- Buf = SendMsg->IO.SendBuf.Buf;
- SendMsg->IO.SendBuf.Buf = SendMsg->msgtext;
- SendMsg->msgtext = Buf;
- SendMsg->State ++;
-
- return eSendMore;
-}
-
-eNextState SMTPC_send_terminate_data_body(SmtpOutMsg *SendMsg)
-{
- StrBuf *Buf;
-
- Buf = SendMsg->IO.SendBuf.Buf;
- SendMsg->IO.SendBuf.Buf = SendMsg->msgtext;
- SendMsg->msgtext = Buf;
-
- StrBufPlain(SendMsg->IO.SendBuf.Buf,
- HKEY(".\r\n"));
-
- return eReadMessage;
-
-}
-
-eNextState SMTPC_read_data_body_reply(SmtpOutMsg *SendMsg)
-{
- SMTP_DBG_READ();
-
- if (!SMTP_IS_STATE('2')) {
- if (SMTP_IS_STATE('4'))
- SMTP_VERROR(4);
- else
- SMTP_VERROR(5);
- }
-
- /* We did it! */
- StrBufPlain(SendMsg->MyQEntry->StatusMessage,
- &ChrPtr(SendMsg->IO.RecvBuf.Buf)[4],
- StrLength(SendMsg->IO.RecvBuf.Buf) - 4);
- SendMsg->MyQEntry->Status = 2;
- return eSendReply;
-}
-
-eNextState SMTPC_send_QUIT(SmtpOutMsg *SendMsg)
-{
- StrBufPlain(SendMsg->IO.SendBuf.Buf,
- HKEY("QUIT\r\n"));
-
- SMTP_DBG_SEND();
- return eReadMessage;
-}
-
-eNextState SMTPC_read_QUIT_reply(SmtpOutMsg *SendMsg)
-{
- SMTP_DBG_READ();
-
- CtdlLogPrintf(CTDL_INFO, "SMTP client[%ld]: delivery to <%s> @ <%s> (%s) succeeded\n",
- SendMsg->n, SendMsg->user, SendMsg->node, SendMsg->name);
- return eTerminateConnection;
-}
-
-eNextState SMTPC_read_dummy(SmtpOutMsg *SendMsg)
-{
- return eSendReply;
-}
-
-eNextState SMTPC_send_dummy(SmtpOutMsg *SendMsg)
-{
- return eReadMessage;
-}
-