From 6de3c1f36c6c8e327864c6f0e8585724709f4256 Mon Sep 17 00:00:00 2001 From: Wilfried Goesgens Date: Mon, 27 Feb 2012 23:59:43 +0100 Subject: [PATCH] SMTP-Client: send a message on first failed, or permanently failed attempt & on last fail. --- citadel/modules/smtp/serv_smtpeventclient.c | 2 +- citadel/modules/smtp/serv_smtpqueue.c | 23 ++++++++++++++------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/citadel/modules/smtp/serv_smtpeventclient.c b/citadel/modules/smtp/serv_smtpeventclient.c index 7374107d8..90a36b235 100644 --- a/citadel/modules/smtp/serv_smtpeventclient.c +++ b/citadel/modules/smtp/serv_smtpeventclient.c @@ -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<MyQEntry->Status); } if ((nRemain > 0) || IDestructQueItem) diff --git a/citadel/modules/smtp/serv_smtpqueue.c b/citadel/modules/smtp/serv_smtpqueue.c index 00b60f8fa..0d1073558 100644 --- a/citadel/modules/smtp/serv_smtpqueue.c +++ b/citadel/modules/smtp/serv_smtpqueue.c @@ -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); -- 2.30.2