SMTP-Client: send a message on first failed, or permanently failed attempt & on last...
authorWilfried Goesgens <dothebart@citadel.org>
Mon, 27 Feb 2012 22:59:43 +0000 (23:59 +0100)
committerWilfried Goesgens <dothebart@citadel.org>
Mon, 27 Feb 2012 22:59:43 +0000 (23:59 +0100)
citadel/modules/smtp/serv_smtpeventclient.c
citadel/modules/smtp/serv_smtpqueue.c

index 7374107d810ccbfcdc20d5427651d4c1a097ea19..90a36b23539f6582b823bd1ec4ce023b834b9562 100644 (file)
@@ -143,7 +143,7 @@ void FinalizeMessageSend(SmtpOutMsg *Msg)
            CheckQEntryIsBounce(Msg->MyQEntry))
        {
                /* are we casue for a bounce mail? */
-               Msg->MyQItem->SendBounceMail = 1;
+               Msg->MyQItem->SendBounceMail |= (1<<Msg->MyQEntry->Status);
        }
 
        if ((nRemain > 0) || IDestructQueItem)
index 00b60f8fa85281f6fca198c92cb7fcc38e3ecb2e..0d1073558e4d32414e1102016783643858131fbf 100644 (file)
@@ -483,39 +483,46 @@ void smtpq_do_bounce(OneQueItem *MyQItem, StrBuf *OMsgTxt)
        StrBuf *Msg = NULL;
        StrBuf *BounceMB;
        struct recptypes *valid;
+       time_t now;
 
        HashPos *It;
        void *vQE;
        long len;
        const char *Key;
 
+       int first_attempt = 0;
        int successful_bounce = 0;
        int num_bounces = 0;
        int give_up = 0;
 
        syslog(LOG_DEBUG, "smtp_do_bounce() called\n");
 
-       if (!MyQItem->SendBounceMail)
+       if (MyQItem->SendBounceMail == 0)
                return;
 
-       if ( (ev_time() - MyQItem->Submitted) > SMTP_GIVE_UP ) {
-               give_up = 1;/// TODO: replace time by libevq timer get
+       now = ev_time();
+
+       if ( (now - MyQItem->Submitted) > SMTP_GIVE_UP ) {
+               give_up = 1;
+       }
+
+       if (MyQItem->Retry == SMTP_RETRY_INTERVAL) {
+               first_attempt = 1;
        }
 
        /*
         * Now go through the instructions checking for stuff.
         */
+       Msg = NewStrBufPlain(NULL, 1024);
        It = GetNewHashPos(MyQItem->MailQEntries, 0);
        while (GetNextHashPos(MyQItem->MailQEntries, It, &len, &Key, &vQE))
        {
                MailQEntry *ThisItem = vQE;
-               if ((ThisItem->Status == 5) || /* failed now? */
-                   ((give_up == 1) &&
-                    (ThisItem->Status != 2)))
+               if ((ThisItem->Active && (ThisItem->Status == 5)) || /* failed now? */
+                   ((give_up == 1) && (ThisItem->Status != 2)) ||
+                   ((first_attempt == 1) && (ThisItem->Status != 2)))
                        /* giving up after failed attempts... */
                {
-                       if (num_bounces == 0)
-                               Msg = NewStrBufPlain(NULL, 1024);
                        ++num_bounces;
 
                        StrBufAppendBuf(Msg, ThisItem->Recipient, 0);