From: Wilfried Goesgens Date: Tue, 7 Aug 2012 20:34:16 +0000 (+0200) Subject: SMTP-Client: output our current state on the useragent; since we're internal only. X-Git-Tag: v8.20~259 X-Git-Url: https://code.citadel.org/?p=citadel.git;a=commitdiff_plain;h=0d7d457ca13abbbc077633edd900cf20f6552dda SMTP-Client: output our current state on the useragent; since we're internal only. --- diff --git a/citadel/modules/smtp/serv_smtpeventclient.c b/citadel/modules/smtp/serv_smtpeventclient.c index abacc906f..34363eb6f 100644 --- a/citadel/modules/smtp/serv_smtpeventclient.c +++ b/citadel/modules/smtp/serv_smtpeventclient.c @@ -90,6 +90,27 @@ #include "smtpqueue.h" #include "smtp_clienthandlers.h" +ConstStr SMTPStates[] = { + {HKEY("looking up mx - record")}, + {HKEY("evaluating what to do next")}, + {HKEY("looking up a - record")}, + {HKEY("looking up aaaa - record")}, + {HKEY("connecting remote")}, + {HKEY("smtp conversation ongoing")}, + {HKEY("smtp sending maildata")}, + {HKEY("smtp sending done")}, + {HKEY("smtp successfully finished")}, + {HKEY("failed one attempt")}, + {HKEY("failed temporarily")}, + {HKEY("failed permanently")} +}; + +void SetSMTPState(AsyncIO *IO, smtpstate State) +{ + CitContext* CCC = IO->CitContext; + memcpy(CCC->cs_clientname, SMTPStates[State].Key, SMTPStates[State].len + 1); +} + int SMTPClientDebugEnabled = 0; void DeleteSmtpOutMsg(void *v) { @@ -134,12 +155,18 @@ eNextState FinalizeMessageSend_DB(AsyncIO *IO) const char *Status; SmtpOutMsg *Msg = IO->Data; - if (Msg->MyQEntry->Status == 2) + if (Msg->MyQEntry->Status == 2) { + SetSMTPState(IO, eSTMPfinished); Status = "Delivery successful."; - else if (Msg->MyQEntry->Status == 5) + } + else if (Msg->MyQEntry->Status == 5) { + SetSMTPState(IO, eSMTPFailTotal); Status = "Delivery failed permanently; giving up."; - else + } + else { + SetSMTPState(IO, eSMTPFailTemporary); Status = "Delivery failed temporarily; will retry later."; + } EVS_syslog(LOG_INFO, "%s Time[%fs] Recipient <%s> @ <%s> (%s) Status message: %s\n", @@ -226,6 +253,7 @@ eNextState FailOneAttempt(AsyncIO *IO) { SmtpOutMsg *Msg = IO->Data; + SetSMTPState(IO, eSTMPfailOne); if (Msg->MyQEntry->Status == 2) return eAbort; @@ -310,6 +338,7 @@ void SetConnectStatus(AsyncIO *IO) eNextState mx_connect_ip(AsyncIO *IO) { SmtpOutMsg *Msg = IO->Data; + SetSMTPState(IO, eSTMPconnecting); EVS_syslog(LOG_DEBUG, "%s\n", __FUNCTION__); @@ -376,6 +405,7 @@ eNextState get_one_mx_host_ip_done(AsyncIO *IO) return mx_connect_ip(IO); } else { + SetSMTPState(IO, eSTMPfailOne); if (Msg->HostLookup.VParsedDNSReply != NULL) { Msg->HostLookup.DNSReplyFree(Msg->HostLookup.VParsedDNSReply); Msg->HostLookup.VParsedDNSReply = NULL; @@ -393,6 +423,7 @@ eNextState get_one_mx_host_ip(AsyncIO *IO) * - the direct hostname if there was no mx record * - one of the mx'es */ + SetSMTPState(IO, (Msg->pCurrRelay->IPv6)?eSTMPalookup:eSTMPaaaalookup); EVS_syslog(LOG_DEBUG, "%s\n", __FUNCTION__); @@ -509,6 +540,8 @@ eNextState resolve_mx_records(AsyncIO *IO) { SmtpOutMsg * Msg = IO->Data; + SetSMTPState(IO, eSTMPmxlookup); + EVS_syslog(LOG_DEBUG, "%s\n", __FUNCTION__); /* start resolving MX records here. */ if (!QueueQuery(ns_t_mx, @@ -601,15 +634,19 @@ void smtp_try_one_queue_entry(OneQueItem *MyQItem, Msg->MyQItem->MessageID, ChrPtr(Msg->MyQEntry->Recipient), ((CitContext*)Msg->IO.CitContext)->cs_pid); - if (Msg->pCurrRelay == NULL) + if (Msg->pCurrRelay == NULL) { + SetSMTPState(&Msg->IO, eSTMPmxlookup); QueueEventContext(&Msg->IO, resolve_mx_records); + } else { /* oh... via relay host */ if (Msg->pCurrRelay->IsIP) { + SetSMTPState(&Msg->IO, eSTMPconnecting); QueueEventContext(&Msg->IO, mx_connect_ip); } else { + SetSMTPState(&Msg->IO, eSTMPalookup); /* uneducated admin has chosen to add DNS to the equation... */ QueueEventContext(&Msg->IO, @@ -618,6 +655,7 @@ void smtp_try_one_queue_entry(OneQueItem *MyQItem, } } else { + SetSMTPState(&Msg->IO, eSMTPFailTotal); /* No recipients? well fail then. */ if (Msg->MyQEntry != NULL) { Msg->MyQEntry->Status = 5; diff --git a/citadel/modules/smtp/smtp_clienthandlers.c b/citadel/modules/smtp/smtp_clienthandlers.c index e7ccae385..b3de3ae1e 100644 --- a/citadel/modules/smtp/smtp_clienthandlers.c +++ b/citadel/modules/smtp/smtp_clienthandlers.c @@ -122,6 +122,7 @@ eNextState SMTPC_read_greeting(SmtpOutMsg *Msg) /* Process the SMTP greeting from the server */ AsyncIO *IO = &Msg->IO; SMTP_DBG_READ(); + SetSMTPState(IO, eSTMPsmtp); if (!SMTP_IS_STATE('2')) { if (SMTP_IS_STATE('4')) @@ -304,11 +305,13 @@ eNextState SMTPC_read_DATAcmd_reply(SmtpOutMsg *Msg) SMTP_DBG_READ(); if (!SMTP_IS_STATE('3')) { + SetSMTPState(IO, eSTMPfailOne); if (SMTP_IS_STATE('4')) SMTP_VERROR(3); else SMTP_VERROR(5); } + SetSMTPState(IO, eSTMPsmtpdata); return eSendReply; } @@ -352,6 +355,7 @@ eNextState SMTPC_read_data_body_reply(SmtpOutMsg *Msg) SMTP_VERROR(5); } + SetSMTPState(IO, eSTMPsmtpdone); /* We did it! */ StrBufPlain(Msg->MyQEntry->StatusMessage, &ChrPtr(Msg->IO.RecvBuf.Buf)[4], diff --git a/citadel/modules/smtp/smtp_clienthandlers.h b/citadel/modules/smtp/smtp_clienthandlers.h index 149c3ddc5..3cbcb6d4a 100644 --- a/citadel/modules/smtp/smtp_clienthandlers.h +++ b/citadel/modules/smtp/smtp_clienthandlers.h @@ -121,3 +121,22 @@ int smtp_resolve_recipients(SmtpOutMsg *SendMsg); #define SMTPCM_syslog(LEVEL, FORMAT) \ DBGLOG(LEVEL) syslog(LEVEL, \ "SMTPCQ: " FORMAT) + + + +typedef enum __smtpstate { + eSTMPmxlookup, + eSTMPevaluatenext, + eSTMPalookup, + eSTMPaaaalookup, + eSTMPconnecting, + eSTMPsmtp, + eSTMPsmtpdata, + eSTMPsmtpdone, + eSTMPfinished, + eSTMPfailOne, + eSMTPFailTemporary, + eSMTPFailTotal +} smtpstate; + +void SetSMTPState(AsyncIO *IO, smtpstate State);