]> code.citadel.org Git - citadel.git/blobdiff - citadel/modules/smtp/serv_smtpqueue.c
SMTP-Client: decide when to send a bounce or not.
[citadel.git] / citadel / modules / smtp / serv_smtpqueue.c
index c4b46142a250eef6e7653c256bf0b4d9117ecd9a..00b60f8fa85281f6fca198c92cb7fcc38e3ecb2e 100644 (file)
@@ -161,17 +161,28 @@ void RemoveQItem(OneQueItem *MyQItem)
 void FreeMailQEntry(void *qv)
 {
        MailQEntry *Q = qv;
+/*
+       syslog(LOG_DEBUG, "---------------%s--------------", __FUNCTION__);
+       cit_backtrace();
+*/
        FreeStrBuf(&Q->Recipient);
        FreeStrBuf(&Q->StatusMessage);
+
+       memset(Q, 0, sizeof(MailQEntry));
        free(Q);
 }
 void FreeQueItem(OneQueItem **Item)
 {
+/*
+       syslog(LOG_DEBUG, "---------------%s--------------", __FUNCTION__);
+       cit_backtrace();
+*/
        DeleteHash(&(*Item)->MailQEntries);
        FreeStrBuf(&(*Item)->EnvelopeFrom);
        FreeStrBuf(&(*Item)->BounceTo);
        FreeStrBuf(&(*Item)->SenderRoom);
        FreeURL(&(*Item)->URL);
+       memset(*Item, 0, sizeof(OneQueItem));
        free(*Item);
        Item = NULL;
 }
@@ -185,6 +196,29 @@ void HFreeQueItem(void *Item)
  * - 3/4 (transient errors
  *        were experienced and it's time to try again)
  */
+int CheckQEntryActive(MailQEntry *ThisItem)
+{
+       if ((ThisItem->Status == 0) ||
+           (ThisItem->Status == 3) ||
+           (ThisItem->Status == 4))
+       {
+               return 1;
+       }
+       else
+               return 0;
+}
+int CheckQEntryIsBounce(MailQEntry *ThisItem)
+{
+       if ((ThisItem->Status == 3) ||
+           (ThisItem->Status == 4) ||
+           (ThisItem->Status == 5))
+       {
+               return 1;
+       }
+       else
+               return 0;
+}      
+
 int CountActiveQueueEntries(OneQueItem *MyQItem)
 {
        HashPos  *It;
@@ -198,9 +232,8 @@ int CountActiveQueueEntries(OneQueItem *MyQItem)
        while (GetNextHashPos(MyQItem->MailQEntries, It, &len, &Key, &vQE))
        {
                MailQEntry *ThisItem = vQE;
-               if ((ThisItem->Status == 0) ||
-                   (ThisItem->Status == 3) ||
-                   (ThisItem->Status == 4))
+
+               if (CheckQEntryActive(ThisItem))
                {
                        ActiveDeliveries++;
                        ThisItem->Active = 1;
@@ -315,11 +348,6 @@ StrBuf *SerializeQueueItem(OneQueItem *MyQItem)
        {
                MailQEntry *ThisItem = vQE;
 
-               if (!ThisItem->Active)
-               {
-                       /* skip already sent ones from the spoolfile. */
-                       continue;
-               }
                StrBufAppendBufPlain(QMessage, HKEY("\nremote|"), 0);
                StrBufAppendBuf(QMessage, ThisItem->Recipient, 0);
                StrBufAppendBufPlain(QMessage, HKEY("|"), 0);
@@ -467,6 +495,9 @@ void smtpq_do_bounce(OneQueItem *MyQItem, StrBuf *OMsgTxt)
 
        syslog(LOG_DEBUG, "smtp_do_bounce() called\n");
 
+       if (!MyQItem->SendBounceMail)
+               return;
+
        if ( (ev_time() - MyQItem->Submitted) > SMTP_GIVE_UP ) {
                give_up = 1;/// TODO: replace time by libevq timer get
        }
@@ -1061,7 +1092,7 @@ CTDL_MODULE_INIT(smtp_queu)
                Put(QItemHandlers, HKEY("submitted"), QItem_Handle_Submitted, reference_free_handler);
                smtp_init_spoolout();
 
-               CtdlRegisterCleanupHook(smtp_evq_cleanup);
+               CtdlRegisterEVCleanupHook(smtp_evq_cleanup);
 
                CtdlRegisterProtoHook(cmd_smtp, "SMTP", "SMTP utility commands");
                CtdlRegisterSessionHook(smtp_do_queue, EVT_TIMER);