#include "smtp_clienthandlers.h"
int SMTPClientDebugEnabled = 0;
-const unsigned short DefaultMXPort = 25;
void DeleteSmtpOutMsg(void *v)
{
SmtpOutMsg *Msg = v;
AsyncIO *IO = &Msg->IO;
- EVS_syslog(LOG_DEBUG, "%s Exit\n", __FUNCTION__);
+ EV_syslog(LOG_DEBUG, "%s Exit\n", __FUNCTION__);
/* these are kept in our own space and free'd below */
Msg->IO.ConnectMe = NULL;
eNextState mx_connect_ip(AsyncIO *IO);
eNextState get_one_mx_host_ip(AsyncIO *IO);
-eNextState FinalizeMessageSendDB(AsyncIO *IO);
-eNextState FinalizeMessageSend_DB1(AsyncIO *IO);
-eNextState FinalizeMessageSend_DB2(AsyncIO *IO);
-eNextState FinalizeMessageSend_DB3(AsyncIO *IO);
-eNextState FinalizeMessageSend_DB4(AsyncIO *IO);
/******************************************************************************
* So, we're finished with sending (regardless of success or failure) *
* we need to free the memory and send bounce messages (on terminal failure) *
* else we just free our SMTP-Message struct. *
******************************************************************************/
-inline void FinalizeMessageSend_1(AsyncIO *IO)
+eNextState FinalizeMessageSend_DB(AsyncIO *IO)
{
const char *Status;
SmtpOutMsg *Msg = IO->Data;
Msg->IDestructQueItem = DecreaseQReference(Msg->MyQItem);
- Msg->nRemain = CountActiveQueueEntries(Msg->MyQItem);
+ Msg->nRemain = CountActiveQueueEntries(Msg->MyQItem, 0);
if (Msg->MyQEntry->Active &&
+ !Msg->MyQEntry->StillActive &&
CheckQEntryIsBounce(Msg->MyQEntry))
{
/* are we casue for a bounce mail? */
Msg->QMsgData = SerializeQueueItem(Msg->MyQItem);
else
Msg->QMsgData = NULL;
-}
-eNextState FinalizeMessageSend(SmtpOutMsg *Msg)
-{
- return QueueDBOperation(&Msg->IO, FinalizeMessageSend_DB1);
-}
-
-inline void FinalizeMessageSend_DB_1(AsyncIO *IO)
-{
- SmtpOutMsg *Msg = IO->Data;
/*
* Uncompleted delivery instructions remain, so delete the old
*/
EVS_syslog(LOG_DEBUG, "%ld", Msg->MyQItem->QueMsgID);
CtdlDeleteMessages(SMTP_SPOOLOUT_ROOM, &Msg->MyQItem->QueMsgID, 1, "");
-}
-eNextState FinalizeMessageSend_DB1(AsyncIO *IO)
-{
- FinalizeMessageSend_1(IO);
- FinalizeMessageSend_DB_1(IO);
- return NextDBOperation(IO, FinalizeMessageSend_DB2);
-}
-
-
-inline void FinalizeMessageSend_DB_2(AsyncIO *IO)
-{
- SmtpOutMsg *Msg = IO->Data;
+ Msg->MyQItem->QueMsgID = -1;
if (Msg->IDestructQueItem)
smtpq_do_bounce(Msg->MyQItem, Msg->msgtext);
-}
-eNextState FinalizeMessageSend_DB2(AsyncIO *IO)
-{
- FinalizeMessageSend_DB_2(IO);
-
- return NextDBOperation(IO, FinalizeMessageSend_DB3);
-}
-
-
-inline void FinalizeMessageSend_DB_3(AsyncIO *IO)
-{
- SmtpOutMsg *Msg = IO->Data;
if (Msg->nRemain > 0)
{
"");
FreeStrBuf(&Msg->QMsgData);
}
- DecreaseShutdownDeliveries(Msg->MyQItem);
-}
-eNextState FinalizeMessageSend_DB3(AsyncIO *IO)
-{
- SmtpOutMsg *Msg = IO->Data;
- FinalizeMessageSend_DB_3(IO);
- if (!Msg->IDestructQueItem)
- return eAbort;
- return NextDBOperation(IO, FinalizeMessageSend_DB4);
-}
-
-eNextState FinalizeMessageSend_DB4(AsyncIO *IO)
-{
- int Done;
- SmtpOutMsg *Msg = IO->Data;
- Done = GetShutdownDeliveries(Msg->MyQItem);
- if (!Done)
- return NextDBOperation(IO, FinalizeMessageSend_DB4);
- else
- return eAbort;
+ RemoveContext(Msg->IO.CitContext);
+ return eAbort;
}
-eNextState FinalizeMessageSend_DB(AsyncIO *IO)
+eNextState Terminate(AsyncIO *IO)
{
SmtpOutMsg *Msg = IO->Data;
- RemoveContext(Msg->IO.CitContext);
if (Msg->IDestructQueItem)
RemoveQItem(Msg->MyQItem);
+
DeleteSmtpOutMsg(Msg);
return eAbort;
}
+eNextState FinalizeMessageSend(SmtpOutMsg *Msg)
+{
+ /* hand over to DB Queue */
+ return QueueDBOperation(&Msg->IO, FinalizeMessageSend_DB);
+}
eNextState FailOneAttempt(AsyncIO *IO)
{
* - connection timeout
* - dns lookup failed
*/
- StopClientWatchers(IO);
+ StopClientWatchers(IO, 1);
if (Msg->pCurrRelay != NULL)
Msg->pCurrRelay = Msg->pCurrRelay->Next;
+ if ((Msg->pCurrRelay != NULL) &&
+ !Msg->pCurrRelay->IsRelay &&
+ Msg->MyQItem->HaveRelay)
+ {
+ EVS_syslog(LOG_DEBUG, "%s Aborting; last relay failed.\n", __FUNCTION__);
+ return eAbort;
+ }
if (Msg->pCurrRelay == NULL) {
EVS_syslog(LOG_DEBUG, "%s Aborting\n", __FUNCTION__);
buf,
Msg->IO.ConnectMe->Port);
- Msg->MyQEntry->Status = 5;
+ Msg->MyQEntry->Status = 4;
StrBufPrintf(Msg->MyQEntry->StatusMessage,
"Timeout while connecting %s [%s]:%d ",
Msg->mx_host,
SmtpOutMsg *Msg = IO->Data;
struct hostent *hostent;
+ IO->ConnectMe = Msg->pCurrRelay;
+
QueryCbDone(IO);
EVS_syslog(LOG_DEBUG, "%s Time[%fs]\n",
__FUNCTION__,
Msg->pCurrRelay->Addr.sin6_family =
hostent->h_addrtype;
Msg->pCurrRelay->Addr.sin6_port =
- htons(DefaultMXPort);
+ htons(Msg->IO.ConnectMe->Port);
}
else {
struct sockaddr_in *addr;
sizeof(uint32_t));
addr->sin_family = hostent->h_addrtype;
- addr->sin_port = htons(DefaultMXPort);
+ addr->sin_port = htons(Msg->IO.ConnectMe->Port);
}
Msg->mx_host = Msg->pCurrRelay->Host;
if (Msg->HostLookup.VParsedDNSReply != NULL) {
SmtpOutMsg * Msg;
Msg = (SmtpOutMsg *) malloc(sizeof(SmtpOutMsg));
+ if (Msg == NULL)
+ return NULL;
memset(Msg, 0, sizeof(SmtpOutMsg));
Msg->n = MsgCount;
SMTPC_syslog(LOG_DEBUG, "%s\n", __FUNCTION__);
Msg = new_smtp_outmsg(MyQItem, MyQEntry, MsgCount);
+ if (Msg == NULL) {
+ SMTPC_syslog(LOG_DEBUG, "%s Failed to alocate message context.\n", __FUNCTION__);
+ if (KeepMsgText)
+ FreeStrBuf (&MsgText);
+ return;
+ }
if (KeepMsgText) Msg->msgtext = MsgText;
else Msg->msgtext = NewStrBufDup(MsgText);
}
else {
/* No recipients? well fail then. */
- if ((Msg==NULL) ||
- (Msg->MyQEntry == NULL)) {
+ if (Msg->MyQEntry != NULL) {
Msg->MyQEntry->Status = 5;
StrBufPlain(Msg->MyQEntry->StatusMessage,
HKEY("Invalid Recipient!"));
}
- FinalizeMessageSend_1(&Msg->IO);
- FinalizeMessageSend_DB_1(&Msg->IO);
- FinalizeMessageSend_DB_2(&Msg->IO);
- FinalizeMessageSend_DB_3(&Msg->IO);
FinalizeMessageSend_DB(&Msg->IO);
+ DeleteSmtpOutMsg(&Msg->IO);
}
}
eNextState SMTP_C_TerminateDB(AsyncIO *IO)
{
EVS_syslog(LOG_DEBUG, "%s\n", __FUNCTION__);
- return FinalizeMessageSend_DB(IO);
+ return Terminate(IO);
}
eNextState SMTP_C_Timeout(AsyncIO *IO)
{
return Finished;
}
-void LogDebugEnableSMTPClient(void)
+void LogDebugEnableSMTPClient(const int n)
{
- SMTPClientDebugEnabled = 1;
+ SMTPClientDebugEnabled = n;
}
CTDL_MODULE_INIT(smtp_eventclient)
{
if (!threading)
- CtdlRegisterDebugFlagHook(HKEY("smtpeventclient"), LogDebugEnableSMTPClient);
+ CtdlRegisterDebugFlagHook(HKEY("smtpeventclient"), LogDebugEnableSMTPClient, &SMTPClientDebugEnabled);
return "smtpeventclient";
}