X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=citadel%2Fmodules%2Fsmtp%2Fserv_smtpeventclient.c;h=d70e80a3f4e7e217677d587771dbcb089537f31e;hb=c1c91208257a253e65275545aea79bba4699ba09;hp=0d3428fea894f5ed529b75e2b50254875ad2064d;hpb=9238afa2572989d7b10a5d2d59e44145c613504d;p=citadel.git diff --git a/citadel/modules/smtp/serv_smtpeventclient.c b/citadel/modules/smtp/serv_smtpeventclient.c index 0d3428fea..d70e80a3f 100644 --- a/citadel/modules/smtp/serv_smtpeventclient.c +++ b/citadel/modules/smtp/serv_smtpeventclient.c @@ -91,12 +91,11 @@ #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; @@ -154,9 +153,10 @@ eNextState FinalizeMessageSend_DB(AsyncIO *IO) 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? */ @@ -177,7 +177,7 @@ eNextState FinalizeMessageSend_DB(AsyncIO *IO) Msg->MyQItem->QueMsgID = -1; if (Msg->IDestructQueItem) - smtpq_do_bounce(Msg->MyQItem, Msg->msgtext); + smtpq_do_bounce(Msg->MyQItem, Msg->msgtext, Msg->pCurrRelay); if (Msg->nRemain > 0) { @@ -203,14 +203,16 @@ eNextState FinalizeMessageSend_DB(AsyncIO *IO) } RemoveContext(Msg->IO.CitContext); - if (Msg->IDestructQueItem) - RemoveQItem(Msg->MyQItem); return eAbort; } eNextState Terminate(AsyncIO *IO) { SmtpOutMsg *Msg = IO->Data; + + if (Msg->IDestructQueItem) + RemoveQItem(Msg->MyQItem); + DeleteSmtpOutMsg(Msg); return eAbort; } @@ -232,10 +234,17 @@ 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__); @@ -320,6 +329,8 @@ eNextState get_one_mx_host_ip_done(AsyncIO *IO) SmtpOutMsg *Msg = IO->Data; struct hostent *hostent; + IO->ConnectMe = Msg->pCurrRelay; + QueryCbDone(IO); EVS_syslog(LOG_DEBUG, "%s Time[%fs]\n", __FUNCTION__, @@ -337,7 +348,7 @@ eNextState get_one_mx_host_ip_done(AsyncIO *IO) 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; @@ -355,7 +366,7 @@ eNextState get_one_mx_host_ip_done(AsyncIO *IO) 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) { @@ -528,6 +539,8 @@ SmtpOutMsg *new_smtp_outmsg(OneQueItem *MyQItem, SmtpOutMsg * Msg; Msg = (SmtpOutMsg *) malloc(sizeof(SmtpOutMsg)); + if (Msg == NULL) + return NULL; memset(Msg, 0, sizeof(SmtpOutMsg)); Msg->n = MsgCount; @@ -565,11 +578,19 @@ void smtp_try_one_queue_entry(OneQueItem *MyQItem, 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); - if (smtp_resolve_recipients(Msg)) { - + if (((!MyQItem->HaveRelay || + (MyQItem->URL != NULL)) && + smtp_resolve_recipients(Msg))) + { safestrncpy( ((CitContext *)Msg->IO.CitContext)->cs_host, Msg->node, @@ -598,11 +619,11 @@ void smtp_try_one_queue_entry(OneQueItem *MyQItem, } 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!")); + if (StrLength(Msg->MyQEntry->StatusMessage) == 0) + StrBufPlain(Msg->MyQEntry->StatusMessage, + HKEY("Invalid Recipient!")); } FinalizeMessageSend_DB(&Msg->IO); DeleteSmtpOutMsg(&Msg->IO); @@ -734,6 +755,28 @@ eNextState SMTP_C_Shutdown(AsyncIO *IO) EVS_syslog(LOG_DEBUG, "%s\n", __FUNCTION__); SmtpOutMsg *Msg = IO->Data; + switch (IO->NextState) { + case eSendDNSQuery: + case eReadDNSReply: + + /* todo: abort c-ares */ + case eConnect: + case eSendReply: + case eSendMore: + case eSendFile: + case eReadMessage: + case eReadMore: + case eReadPayload: + case eReadFile: + StopClientWatchers(IO, 1); + break; + case eDBQuery: + + break; + case eTerminateConnection: + case eAbort: + break; + } Msg->MyQEntry->Status = 3; StrBufPlain(Msg->MyQEntry->StatusMessage, HKEY("server shutdown during message submit."));