SMTP-Client: decide when to send a bounce or not.
authorWilfried Goesgens <dothebart@citadel.org>
Mon, 27 Feb 2012 21:50:38 +0000 (22:50 +0100)
committerWilfried Goesgens <dothebart@citadel.org>
Mon, 27 Feb 2012 21:50:38 +0000 (22:50 +0100)
citadel/modules/smtp/serv_smtpeventclient.c
citadel/modules/smtp/serv_smtpqueue.c
citadel/modules/smtp/smtpqueue.h

index d1815f91bccf3d068ae52172c3edfe48ef1607ea..7374107d810ccbfcdc20d5427651d4c1a097ea19 100644 (file)
@@ -139,6 +139,13 @@ void FinalizeMessageSend(SmtpOutMsg *Msg)
 
        nRemain = CountActiveQueueEntries(Msg->MyQItem);
 
+       if (Msg->MyQEntry->Active && 
+           CheckQEntryIsBounce(Msg->MyQEntry))
+       {
+               /* are we casue for a bounce mail? */
+               Msg->MyQItem->SendBounceMail = 1;
+       }
+
        if ((nRemain > 0) || IDestructQueItem)
                MsgData = SerializeQueueItem(Msg->MyQItem);
        else
index e9053981e1e28053bb94240d402f0b0d94074e6d..00b60f8fa85281f6fca198c92cb7fcc38e3ecb2e 100644 (file)
@@ -196,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;
@@ -209,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;
@@ -326,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);
@@ -478,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
        }
index 1b834f9b122a896842501aa78300870b90d7dd16..be14ea5b568ffb4b2d55c8d0c56c4173239baa5c 100644 (file)
@@ -42,6 +42,7 @@ typedef struct _mailq_entry {
 }MailQEntry;
 
 typedef struct queueitem {
+       long SendBounceMail;
        long MessageID;
        long QueMsgID;
        long Submitted;
@@ -69,3 +70,5 @@ void    RemoveQItem(OneQueItem *MyQItem);
 int     CountActiveQueueEntries(OneQueItem *MyQItem);
 StrBuf *SerializeQueueItem(OneQueItem *MyQItem);
 void    smtpq_do_bounce(OneQueItem *MyQItem, StrBuf *OMsgTxt);
+
+int CheckQEntryIsBounce(MailQEntry *ThisItem);