SMTPClient: when relaying with users/email addresses fail with an aidemessage if...
authorWilfried Goesgens <dothebart@citadel.org>
Mon, 30 Jul 2012 22:58:46 +0000 (00:58 +0200)
committerWilfried Goesgens <dothebart@citadel.org>
Mon, 30 Jul 2012 22:58:46 +0000 (00:58 +0200)
citadel/modules/smtp/serv_smtpeventclient.c
citadel/modules/smtp/serv_smtpqueue.c

index f1901a99641401b044cda0f74451c7b3b7c08fcd..d70e80a3f4e7e217677d587771dbcb089537f31e 100644 (file)
@@ -587,8 +587,10 @@ void smtp_try_one_queue_entry(OneQueItem *MyQItem,
        if (KeepMsgText) Msg->msgtext = MsgText;
        else             Msg->msgtext = NewStrBufDup(MsgText);
 
-       if (smtp_resolve_recipients(Msg)) {
-
+       if (((!MyQItem->HaveRelay ||
+             (MyQItem->URL != NULL)) &&
+            smtp_resolve_recipients(Msg)))
+       {
                safestrncpy(
                        ((CitContext *)Msg->IO.CitContext)->cs_host,
                        Msg->node,
@@ -619,8 +621,9 @@ void smtp_try_one_queue_entry(OneQueItem *MyQItem,
                /* No recipients? well fail then. */
                if (Msg->MyQEntry != NULL) {
                        Msg->MyQEntry->Status = 5;
-                       StrBufPlain(Msg->MyQEntry->StatusMessage,
-                                   HKEY("Invalid Recipient!"));
+                       if (StrLength(Msg->MyQEntry->StatusMessage) == 0)
+                               StrBufPlain(Msg->MyQEntry->StatusMessage,
+                                           HKEY("Invalid Recipient!"));
                }
                FinalizeMessageSend_DB(&Msg->IO);
                DeleteSmtpOutMsg(&Msg->IO);
index cd684c9ff01784ee28877a7a68f7b6167eaa9112..5b471127ed176d4060d13c7f2eac0beda927c50b 100644 (file)
@@ -581,12 +581,16 @@ void smtpq_do_bounce(OneQueItem *MyQItem, StrBuf *OMsgTxt, ParsedURL *Relay)
        }
 
        if ((StrLength(MyQItem->SenderRoom) == 0) && MyQItem->HaveRelay) {
+               const char *RelayUrlStr = "[not found]";
                /* one message that relaying is broken is enough; no extra room error message. */
                StrBuf *RelayDetails = NewStrBuf();
 
+               if (Relay != NULL)
+                       RelayUrlStr = ChrPtr(Relay->URL);
+
                StrBufPrintf(RelayDetails,
                             "Relaying via %s failed permanently. \n Reason:\n%s\n Revalidate your relay configuration.",
-                            ChrPtr(Relay->URL),
+                            RelayUrlStr,
                             ChrPtr(Msg));
                 CtdlAideMessage(ChrPtr(RelayDetails), "Relaying Failed");
                FreeStrBuf(&RelayDetails);
@@ -778,9 +782,10 @@ ParsedURL *LoadRelayUrls(OneQueItem *MyQItem,
                                if (!strcmp(User + 1, Author) ||
                                    !strcmp(User + 1, Address))
                                        StrBufCutAt(One, 0, User);
-                               else
+                               else {
+                                       MyQItem->HaveRelay = 1;
                                        continue;
-
+                               }
                        }
                        if (!ParseURL(Url, One, DefaultMXPort)) {
                                SMTPC_syslog(LOG_DEBUG,
@@ -952,12 +957,52 @@ void smtp_do_procmsg(long msgnum, void *userdata) {
                int m = MyQItem->ActiveDeliveries;
                int i = 1;
 
+               It = GetNewHashPos(MyQItem->MailQEntries, 0);
+
                Msg = smtp_load_msg(MyQItem, n, &Author, &Address);
                RelayUrls = LoadRelayUrls(MyQItem, Author, Address);
+               if ((RelayUrls == NULL) && MyQItem->HaveRelay) {
+
+                       while ((i <= m) &&
+                              (GetNextHashPos(MyQItem->MailQEntries,
+                                              It, &len, &Key, &vQE)))
+                       {
+                               int KeepBuffers = (i == m);
+                               MailQEntry *ThisItem = vQE;
+                               StrBufPrintf(ThisItem->StatusMessage,
+                                            "No relay configured matching %s / %s", 
+                                            (Author != NULL)? Author : "",
+                                            (Address != NULL)? Address : "");
+                               ThisItem->Status = 5;
+
+                               nActivated++;
+
+                               if (i > 1) n = MsgCount++;
+                               syslog(LOG_INFO,
+                                      "SMTPC: giving up on <%ld> <%s> %d / %d \n",
+                                      MyQItem->MessageID,
+                                      ChrPtr(ThisItem->Recipient),
+                                      i,
+                                      m);
+                               (*((int*) userdata)) ++;
+                               smtp_try_one_queue_entry(MyQItem,
+                                                        ThisItem,
+                                                        Msg,
+                                                        KeepBuffers,
+                                                        n,
+                                                        RelayUrls);
+
+                               if (KeepBuffers) HaveBuffers = 1;
+
+                               i++;
+                       }
+                       DeleteHashPos(&It);
+
+                       return;
+               }
                if (Author != NULL) free (Author);
                if (Address != NULL) free (Address);
 
-               It = GetNewHashPos(MyQItem->MailQEntries, 0);
                while ((i <= m) &&
                       (GetNextHashPos(MyQItem->MailQEntries,
                                       It, &len, &Key, &vQE)))