From: Wilfried Goesgens Date: Thu, 9 Feb 2012 21:49:22 +0000 (+0100) Subject: SMTP-Client: respect MX-Priority in the sequence of attempting delivery. X-Git-Tag: v8.11~196 X-Git-Url: https://code.citadel.org/?p=citadel.git;a=commitdiff_plain;h=8bfe7498818fed3f6e0e0c8d228662706bcf8ae5 SMTP-Client: respect MX-Priority in the sequence of attempting delivery. --- diff --git a/citadel/modules/smtp/serv_smtpeventclient.c b/citadel/modules/smtp/serv_smtpeventclient.c index 3a65977ff..7ac66f3c1 100644 --- a/citadel/modules/smtp/serv_smtpeventclient.c +++ b/citadel/modules/smtp/serv_smtpeventclient.c @@ -372,9 +372,6 @@ eNextState smtp_resolve_mx_record_done(AsyncIO *IO) QueryCbDone(IO); EVS_syslog(LOG_DEBUG, "SMTP: %s\n", __FUNCTION__); - pp = &Msg->Relay; - while ((pp != NULL) && (*pp != NULL) && ((*pp)->Next != NULL)) - pp = &(*pp)->Next; if ((IO->DNS.Query->DNSStatus == ARES_SUCCESS) && (IO->DNS.Query->VParsedDNSReply != NULL)) @@ -390,19 +387,38 @@ eNextState smtp_resolve_mx_record_done(AsyncIO *IO) p = (ParsedURL*) malloc(sizeof(ParsedURL)); memset(p, 0, sizeof(ParsedURL)); + p->Priority = Msg->CurrMX->priority; p->IsIP = 0; p->Port = DefaultMXPort; p->IPv6 = i == 1; p->Host = Msg->CurrMX->host; - - *pp = p; - pp = &p->Next; + if (Msg->Relay == NULL) + Msg->Relay = p; + else { + ParsedURL *pp = Msg->Relay; + + while ((pp->Next != NULL) && + (pp->Next->Priority <= p->Priority)) + pp = pp->Next; + if ((pp == Msg->Relay) && + (pp->Priority > p->Priority)) { + p->Next = Msg->Relay; + Msg->Relay = p; + } + else { + p->Next = pp->Next; + pp->Next = p; + } + } } Msg->CurrMX = Msg->CurrMX->next; } Msg->CXFlags = Msg->CXFlags & F_HAVE_MX; } else { /* else fall back to the plain hostname */ + pp = &Msg->Relay; + while ((pp != NULL) && (*pp != NULL) && ((*pp)->Next != NULL)) + pp = &(*pp)->Next; int i; for (i = 0; i < 2; i++) { ParsedURL *p; diff --git a/libcitadel/lib/libcitadel.h b/libcitadel/lib/libcitadel.h index 7f3da262d..a0a70305a 100644 --- a/libcitadel/lib/libcitadel.h +++ b/libcitadel/lib/libcitadel.h @@ -369,6 +369,7 @@ const char *GetIconFilename(char *MimeType, size_t len); /* URL parsing & connection data */ typedef struct ParsedURL ParsedURL; struct ParsedURL { + int Priority; StrBuf *URL; StrBuf *UrlWithoutCred; StrBuf *CurlCreds;