#include "ctdl_module.h"
#include "smtpqueue.h"
+#include "smtp_clienthandlers.h"
#include "event_client.h"
return IDestructQueItem;
}
+void DecreaseShutdownDeliveries(OneQueItem *MyQItem)
+{
+ pthread_mutex_lock(&ActiveQItemsLock);
+ MyQItem->NotYetShutdownDeliveries--;
+ pthread_mutex_unlock(&ActiveQItemsLock);
+}
+
+int GetShutdownDeliveries(OneQueItem *MyQItem)
+{
+ int DestructNow;
+
+ pthread_mutex_lock(&ActiveQItemsLock);
+ DestructNow = MyQItem->ActiveDeliveries == 0;
+ pthread_mutex_unlock(&ActiveQItemsLock);
+ return DestructNow;
+}
void RemoveQItem(OneQueItem *MyQItem)
{
long len;
StrBufAppendBufPlain(QMessage, HKEY("\nattempted|"), 0);
StrBufAppendPrintf(QMessage, "%ld",
- ctdl_ev_now() + MyQItem->Retry);
+ time(NULL) /*ctdl_ev_now()*/ + MyQItem->Retry);
It = GetNewHashPos(MyQItem->MailQEntries, 0);
while (GetNextHashPos(MyQItem->MailQEntries, It, &len, &Key, &vQE))
if (MyQItem->SendBounceMail == 0)
return;
- now = ev_time();
+ now = time (NULL); //ev_time();
if ( (now - MyQItem->Submitted) > SMTP_GIVE_UP ) {
give_up = 1;
}
/* Attach the original message */
- StrBufAppendBufPlain(BounceMB, HKEY("--"), 0);
+ StrBufAppendBufPlain(BounceMB, HKEY("\r\n--"), 0);
StrBufAppendBuf(BounceMB, boundary, 0);
StrBufAppendBufPlain(BounceMB, HKEY("\r\n"), 0);
StrBufAppendBufPlain(BounceMB,
* Called by smtp_do_queue() to handle an individual message.
*/
void smtp_do_procmsg(long msgnum, void *userdata) {
+ time_t now;
int mynumsessions = num_sessions;
struct CtdlMessage *msg = NULL;
char *instr = NULL;
/*
* Postpone delivery if we've already tried recently.
*/
+ now = time(NULL);
if ((MyQItem->ReattemptWhen != 0) &&
- (time(NULL) < MyQItem->ReattemptWhen) &&
+ (now < MyQItem->ReattemptWhen) &&
(run_queue_now == 0))
{
- syslog(LOG_DEBUG, "SMTP client: Retry time not yet reached.\n");
+ syslog(LOG_DEBUG, "SMTP client: Retry time not yet reached. %ld seconds left.", MyQItem->ReattemptWhen - now);
It = GetNewHashPos(MyQItem->MailQEntries, 0);
pthread_mutex_lock(&ActiveQItemsLock);
}
DeleteHashPos(&It);
+ MyQItem->NotYetShutdownDeliveries =
MyQItem->ActiveDeliveries = CountActiveQueueEntries(MyQItem);
/* failsafe against overload:
ChrPtr(ThisItem->Recipient),
i,
m);
+ (*((int*) userdata)) ++;
smtp_try_one_queue_entry(MyQItem,
ThisItem,
Msg,
void smtp_do_queue(void) {
static int is_running = 0;
int num_processed = 0;
+ int num_activated = 0;
if (is_running)
return; /* Concurrency check - only one can run */
is_running = 1;
pthread_setspecific(MyConKey, (void *)&smtp_queue_CC);
- syslog(LOG_INFO, "SMTP client: processing outbound queue");
+ SMTPCM_syslog(LOG_INFO, "processing outbound queue");
if (CtdlGetRoom(&CC->room, SMTP_SPOOLOUT_ROOM) != 0) {
- syslog(LOG_ERR, "Cannot find room <%s>", SMTP_SPOOLOUT_ROOM);
+ SMTPC_syslog(LOG_ERR, "Cannot find room <%s>", SMTP_SPOOLOUT_ROOM);
}
else {
num_processed = CtdlForEachMessage(MSGS_ALL,
SPOOLMIME,
NULL,
smtp_do_procmsg,
- NULL);
+ &num_activated);
}
- syslog(LOG_INFO,
- "SMTP client: queue run completed; %d messages processed",
- num_processed);
+ SMTPC_syslog(LOG_INFO,
+ "queue run completed; %d messages processed %d activated",
+ num_processed, num_activated);
run_queue_now = 0;
is_running = 0;