]> code.citadel.org Git - citadel.git/blobdiff - citadel/modules/smtp/serv_smtpqueue.c
SMTP-Client: streamline logging; make look more uniq
[citadel.git] / citadel / modules / smtp / serv_smtpqueue.c
index 4704d31ce75ef7267d833e97b2e5561c3c7712f9..a3626c8a7323b19ac558714284fca4c345737222 100644 (file)
@@ -86,6 +86,7 @@
 #include "ctdl_module.h"
 
 #include "smtpqueue.h"
+#include "smtp_clienthandlers.h"
 #include "event_client.h"
 
 
@@ -141,6 +142,22 @@ int DecreaseQReference(OneQueItem *MyQItem)
        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;
@@ -350,7 +367,7 @@ StrBuf *SerializeQueueItem(OneQueItem *MyQItem)
 
        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))
@@ -512,7 +529,7 @@ void smtpq_do_bounce(OneQueItem *MyQItem, StrBuf *OMsgTxt)
        if (MyQItem->SendBounceMail == 0)
                return;
 
-       now = ev_time();
+       now = time (NULL); //ev_time();
 
        if ( (now - MyQItem->Submitted) > SMTP_GIVE_UP ) {
                give_up = 1;
@@ -630,7 +647,7 @@ void smtpq_do_bounce(OneQueItem *MyQItem, StrBuf *OMsgTxt)
        }
 
        /* 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,
@@ -689,6 +706,7 @@ void smtpq_do_bounce(OneQueItem *MyQItem, StrBuf *OMsgTxt)
  * 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;
@@ -746,11 +764,12 @@ void smtp_do_procmsg(long msgnum, void *userdata) {
        /*
         * 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);
@@ -854,6 +873,7 @@ void smtp_do_procmsg(long msgnum, void *userdata) {
        }
        DeleteHashPos(&It);
 
+       MyQItem->NotYetShutdownDeliveries = 
        MyQItem->ActiveDeliveries = CountActiveQueueEntries(MyQItem);
 
        /* failsafe against overload: 
@@ -907,6 +927,7 @@ void smtp_do_procmsg(long msgnum, void *userdata) {
                                       ChrPtr(ThisItem->Recipient),
                                       i,
                                       m);
+                               (*((int*) userdata)) ++;
                                smtp_try_one_queue_entry(MyQItem,
                                                         ThisItem,
                                                         Msg,
@@ -978,16 +999,17 @@ void smtp_do_procmsg(long msgnum, void *userdata) {
 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,
@@ -996,11 +1018,11 @@ void smtp_do_queue(void) {
                                                   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;