]> code.citadel.org Git - citadel.git/blobdiff - citadel/modules/smtp/serv_smtpqueue.c
SMTP-Client: when relaying failed also notify aide that somethings broken.
[citadel.git] / citadel / modules / smtp / serv_smtpqueue.c
index 589b13a482156ecdc9de2ba9e1a9fd1f15fe1490..5161a1eb060b52ee8ba651d47c95fa73f69aa630 100644 (file)
@@ -246,7 +246,7 @@ int CheckQEntryIsBounce(MailQEntry *ThisItem)
                return 0;
 }      
 
-int CountActiveQueueEntries(OneQueItem *MyQItem)
+int CountActiveQueueEntries(OneQueItem *MyQItem, int before)
 {
        HashPos  *It;
        long len;
@@ -258,15 +258,20 @@ int CountActiveQueueEntries(OneQueItem *MyQItem)
        It = GetNewHashPos(MyQItem->MailQEntries, 0);
        while (GetNextHashPos(MyQItem->MailQEntries, It, &len, &Key, &vQE))
        {
+               int Active;
                MailQEntry *ThisItem = vQE;
 
                if (CheckQEntryActive(ThisItem))
                {
                        ActiveDeliveries++;
-                       ThisItem->Active = 1;
+                       Active = 1;
                }
                else
-                       ThisItem->Active = 0;
+                       Active = 0;
+               if (before)
+                       ThisItem->Active = Active;
+               else
+                       ThisItem->StillActive = Active;
        }
        DeleteHashPos(&It);
        return ActiveDeliveries;
@@ -505,7 +510,7 @@ StrBuf *smtp_load_msg(OneQueItem *MyQItem, int n)
  * instructions for "5" codes (permanent fatal errors) and produce/deliver
  * a "bounce" message (delivery status notification).
  */
-void smtpq_do_bounce(OneQueItem *MyQItem, StrBuf *OMsgTxt)
+void smtpq_do_bounce(OneQueItem *MyQItem, StrBuf *OMsgTxt, ParsedURL *Relay)
 {
        static int seq = 0;
 
@@ -556,6 +561,7 @@ void smtpq_do_bounce(OneQueItem *MyQItem, StrBuf *OMsgTxt)
                {
                        ++num_bounces;
 
+                       StrBufAppendBufPlain(Msg, HKEY(" "), 0);
                        StrBufAppendBuf(Msg, ThisItem->Recipient, 0);
                        StrBufAppendBufPlain(Msg, HKEY(": "), 0);
                        StrBufAppendBuf(Msg, ThisItem->StatusMessage, 0);
@@ -572,6 +578,18 @@ void smtpq_do_bounce(OneQueItem *MyQItem, StrBuf *OMsgTxt)
                return;
        }
 
+       if ((StrLength(MyQItem->SenderRoom) == 0) && MyQItem->HaveRelay) {
+               /* one message that relaying is broken is enough; no extra room error message. */
+               StrBuf *RelayDetails = NewStrBuf();
+
+               StrBufPrintf(RelayDetails,
+                            "Relaying via %s failed permanently. \n Reason:\n%s\n Revalidate your relay configuration.",
+                            ChrPtr(Relay->URL),
+                            ChrPtr(Msg));
+                CtdlAideMessage(ChrPtr(RelayDetails), "Relaying Failed");
+               FreeStrBuf(&RelayDetails);
+       }
+
        boundary = NewStrBufPlain(HKEY("=_Citadel_Multipart_"));
        StrBufAppendPrintf(boundary,
                           "%s_%04x%04x",
@@ -817,7 +835,7 @@ void smtp_do_procmsg(long msgnum, void *userdata) {
        {
                char mxbuf[SIZ];
                ParsedURL **Url = &MyQItem->URL;
-               nRelays = get_hosts(mxbuf, "smarthost");
+               nRelays = get_hosts(mxbuf, "fallbackhost");
                if (nRelays > 0) {
                        StrBuf *All;
                        StrBuf *One;
@@ -836,16 +854,14 @@ void smtp_do_procmsg(long msgnum, void *userdata) {
                                                     ChrPtr(One));
                                }
                                else {
-                                       ///if (!Url->IsIP)) // todo dupe me fork ipv6
-                                       Url = &(*Url)->Next;
+                                       (*Url)->IsRelay = 1;
+                                       MyQItem->HaveRelay = 1;
                                }
                        }
                        FreeStrBuf(&All);
                        FreeStrBuf(&One);
                }
-
-               Url = &MyQItem->FallBackHost;
-               nRelays = get_hosts(mxbuf, "fallbackhost");
+               nRelays = get_hosts(mxbuf, "smarthost");
                if (nRelays > 0) {
                        StrBuf *All;
                        StrBuf *One;
@@ -863,12 +879,16 @@ void smtp_do_procmsg(long msgnum, void *userdata) {
                                                     "Failed to parse: %s\n",
                                                     ChrPtr(One));
                                }
-                               else
-                                       Url = &(*Url)->Next;
+                               else {
+                                       ///if (!Url->IsIP)) // todo dupe me fork ipv6
+                                       (*Url)->IsRelay = 1;
+                                       MyQItem->HaveRelay = 1;
+                               }
                        }
                        FreeStrBuf(&All);
                        FreeStrBuf(&One);
                }
+
        }
 
        It = GetNewHashPos(MyQItem->MailQEntries, 0);
@@ -882,7 +902,7 @@ void smtp_do_procmsg(long msgnum, void *userdata) {
        DeleteHashPos(&It);
 
        MyQItem->NotYetShutdownDeliveries = 
-       MyQItem->ActiveDeliveries = CountActiveQueueEntries(MyQItem);
+               MyQItem->ActiveDeliveries = CountActiveQueueEntries(MyQItem, 1);
 
        /* failsafe against overload: 
         * will we exceed the limit set? 
@@ -1137,7 +1157,7 @@ CTDL_MODULE_INIT(smtp_queu)
                CtdlRegisterEVCleanupHook(smtp_evq_cleanup);
 
                CtdlRegisterProtoHook(cmd_smtp, "SMTP", "SMTP utility commands");
-               CtdlRegisterSessionHook(smtp_do_queue, EVT_TIMER);
+               CtdlRegisterSessionHook(smtp_do_queue, EVT_TIMER, PRIO_SEND + 10);
        }
 
        /* return our Subversion id for the Log */