EV: fix possible nullpointer access in last commit.
[citadel.git] / citadel / modules / smtp / serv_smtpeventclient.c
index c744bb6e4cb81fd3bf2d99a60834d6c21c04f435..dd4e3e2662b08a05a10784a4e36ee4a26dda378f 100644 (file)
@@ -108,7 +108,8 @@ ConstStr SMTPStates[] = {
 void SetSMTPState(AsyncIO *IO, smtpstate State)
 {
        CitContext* CCC = IO->CitContext;
-       memcpy(CCC->cs_clientname, SMTPStates[State].Key, SMTPStates[State].len + 1);
+       if (CCC != NULL)
+               memcpy(CCC->cs_clientname, SMTPStates[State].Key, SMTPStates[State].len + 1);
 }
 
 int SMTPClientDebugEnabled = 0;
@@ -154,7 +155,14 @@ eNextState FinalizeMessageSend_DB(AsyncIO *IO)
 {
        const char *Status;
        SmtpOutMsg *Msg = IO->Data;
-       
+       StrBuf *StatusMessage;
+
+       if (Msg->MyQEntry->AllStatusMessages != NULL)
+               StatusMessage = Msg->MyQEntry->AllStatusMessages;
+       else
+               StatusMessage = Msg->MyQEntry->StatusMessage;
+
+
        if (Msg->MyQEntry->Status == 2) {
                SetSMTPState(IO, eSTMPfinished);
                Status = "Delivery successful.";
@@ -175,7 +183,7 @@ eNextState FinalizeMessageSend_DB(AsyncIO *IO)
                   Msg->user,
                   Msg->node,
                   Msg->name,
-                  ChrPtr(Msg->MyQEntry->StatusMessage));
+                  ChrPtr(StatusMessage));
 
 
        Msg->IDestructQueItem = DecreaseQReference(Msg->MyQItem);
@@ -204,7 +212,7 @@ eNextState FinalizeMessageSend_DB(AsyncIO *IO)
        Msg->MyQItem->QueMsgID = -1;
 
        if (Msg->IDestructQueItem)
-               smtpq_do_bounce(Msg->MyQItem, Msg->msgtext, Msg->pCurrRelay);
+               smtpq_do_bounce(Msg->MyQItem, StatusMessage, Msg->msgtext, Msg->pCurrRelay);
 
        if (Msg->nRemain > 0)
        {
@@ -774,7 +782,9 @@ eNextState SMTP_C_Timeout(AsyncIO *IO)
 
        Msg->MyQEntry->Status = 4;
        EVS_syslog(LOG_DEBUG, "%s\n", __FUNCTION__);
-       StrBufPlain(IO->ErrMsg, CKEY(ReadErrors[Msg->State]));
+       StrBufPrintf(IO->ErrMsg, "Timeout: %s while talking to %s",
+                    ReadErrors[Msg->State].Key,
+                    Msg->mx_host);
        if (Msg->State > eRCPT)
                return eAbort;
        else
@@ -786,7 +796,10 @@ eNextState SMTP_C_ConnFail(AsyncIO *IO)
 
        Msg->MyQEntry->Status = 4;
        EVS_syslog(LOG_DEBUG, "%s\n", __FUNCTION__);
-       StrBufPlain(IO->ErrMsg, CKEY(ReadErrors[Msg->State]));
+       StrBufPrintf(IO->ErrMsg, "Connection failure: %s while talking to %s",
+                    ReadErrors[Msg->State].Key,
+                    Msg->mx_host);
+
        return FailOneAttempt(IO);
 }
 eNextState SMTP_C_DNSFail(AsyncIO *IO)