]> code.citadel.org Git - citadel.git/blobdiff - citadel/modules/smtp/serv_smtpqueue.c
SMTP-Client: first add backups, then Relays, since we want Relays to be attempted...
[citadel.git] / citadel / modules / smtp / serv_smtpqueue.c
index c0af5c0f57f36f32829c8e06b716f5801eeabd0c..0fa65bea2000901c0098d814f5fcabbc9f0cb481 100644 (file)
@@ -94,6 +94,7 @@ struct CitContext smtp_queue_CC;
 pthread_mutex_t ActiveQItemsLock;
 HashList *ActiveQItems  = NULL;
 HashList *QItemHandlers = NULL;
+const unsigned short DefaultMXPort = 25;
 int max_sessions_for_outbound_smtp = 500; /* how many sessions might be active till we stop adding more smtp jobs */
 int ndelay_count = 50; /* every n queued messages we will sleep... */
 int delay_msec = 5000; /* this many seconds. */
@@ -397,7 +398,8 @@ void NewMailQEntry(OneQueItem *Item)
 
        if (Item->MailQEntries == NULL)
                Item->MailQEntries = NewHash(1, Flathash);
-       Item->Current->StatusMessage = NewStrBuf();
+       /* alocate big buffer so we won't get problems reallocating later. */
+       Item->Current->StatusMessage = NewStrBufPlain(NULL, SIZ);
        Item->Current->n = GetCount(Item->MailQEntries);
        Put(Item->MailQEntries,
            IKEY(Item->Current->n),
@@ -815,7 +817,7 @@ void smtp_do_procmsg(long msgnum, void *userdata) {
        {
                char mxbuf[SIZ];
                ParsedURL **Url = &MyQItem->URL;
-               nRelays = get_hosts(mxbuf, "smarthost");
+               nRelays = get_hosts(mxbuf, "fallbackhost");
                if (nRelays > 0) {
                        StrBuf *All;
                        StrBuf *One;
@@ -828,22 +830,20 @@ void smtp_do_procmsg(long msgnum, void *userdata) {
                                !IsEmptyStr(Pos)))
                        {
                                StrBufExtract_NextToken(One, All, &Pos, '|');
-                               if (!ParseURL(Url, One, 25)) {
+                               if (!ParseURL(Url, One, DefaultMXPort)) {
                                        SMTPC_syslog(LOG_DEBUG,
                                                     "Failed to parse: %s\n",
                                                     ChrPtr(One));
                                }
                                else {
-                                       ///if (!Url->IsIP)) // todo dupe me fork ipv6
-                                       Url = &(*Url)->Next;
+                                       (*Url)->IsRelay = 1;
+                                       MyQItem->HaveRelay = 1;
                                }
                        }
                        FreeStrBuf(&All);
                        FreeStrBuf(&One);
                }
-
-               Url = &MyQItem->FallBackHost;
-               nRelays = get_hosts(mxbuf, "fallbackhost");
+               nRelays = get_hosts(mxbuf, "smarthost");
                if (nRelays > 0) {
                        StrBuf *All;
                        StrBuf *One;
@@ -856,17 +856,21 @@ void smtp_do_procmsg(long msgnum, void *userdata) {
                                !IsEmptyStr(Pos)))
                        {
                                StrBufExtract_NextToken(One, All, &Pos, '|');
-                               if (!ParseURL(Url, One, 25)) {
+                               if (!ParseURL(Url, One, DefaultMXPort)) {
                                        SMTPC_syslog(LOG_DEBUG,
                                                     "Failed to parse: %s\n",
                                                     ChrPtr(One));
                                }
-                               else
-                                       Url = &(*Url)->Next;
+                               else {
+                                       ///if (!Url->IsIP)) // todo dupe me fork ipv6
+                                       (*Url)->IsRelay = 1;
+                                       MyQItem->HaveRelay = 1;
+                               }
                        }
                        FreeStrBuf(&All);
                        FreeStrBuf(&One);
                }
+
        }
 
        It = GetNewHashPos(MyQItem->MailQEntries, 0);
@@ -1002,14 +1006,9 @@ void smtp_do_procmsg(long msgnum, void *userdata) {
  * Run through the queue sending out messages.
  */
 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);
        SMTPCM_syslog(LOG_INFO, "processing outbound queue");
 
@@ -1029,8 +1028,6 @@ void smtp_do_queue(void) {
                     "queue run completed; %d messages processed %d activated",
                     num_processed, num_activated);
 
-       run_queue_now = 0;
-       is_running = 0;
 }
 
 
@@ -1142,7 +1139,7 @@ CTDL_MODULE_INIT(smtp_queu)
                CtdlRegisterEVCleanupHook(smtp_evq_cleanup);
 
                CtdlRegisterProtoHook(cmd_smtp, "SMTP", "SMTP utility commands");
-               CtdlRegisterSessionHook(smtp_do_queue, EVT_TIMER);
+               CtdlRegisterSessionHook(smtp_do_queue, EVT_TIMER, PRIO_SEND + 10);
        }
 
        /* return our Subversion id for the Log */