}
while(1) {
- TRACE;
memset(expanded_buf, 0, sizeof(expanded_buf));
ret = dn_expand(startptr, endptr, ptr, expanded_buf, sizeof(expanded_buf));
if (ret < 0) break;
ptr += INT16SZ + INT32SZ;
GETSHORT(n, ptr);
- syslog(LOG_DEBUG, "\033[35mgetmx: found record of type %d and length %d\033[0m", type, n);
if (type != T_MX) {
ptr += n;
}
ret = dn_expand(startptr, endptr, ptr, expanded_buf, sizeof(expanded_buf));
ptr += ret;
- ++num_mxrecs;
- if (mxrecs == NULL) {
- mxrecs = malloc(sizeof(struct mx));
- }
- else {
- mxrecs = realloc(mxrecs, (sizeof(struct mx) * num_mxrecs) );
- }
+ // If there are no MX records for the domain, resolv will give us a single one with zero length.
+ // Make sure we only record actual MX records and not the blank.
+ if (strlen(expanded_buf) > 0) {
+ ++num_mxrecs;
+ if (mxrecs == NULL) {
+ mxrecs = malloc(sizeof(struct mx));
+ }
+ else {
+ mxrecs = realloc(mxrecs, (sizeof(struct mx) * num_mxrecs) );
+ }
- mxrecs[num_mxrecs - 1].pref = pref;
- strcpy(mxrecs[num_mxrecs - 1].host, expanded_buf);
+ mxrecs[num_mxrecs - 1].pref = pref;
+ strcpy(mxrecs[num_mxrecs - 1].host, expanded_buf);
+ }
}
}
}
strcpy(mxbuf, "");
for (n=0; n<num_mxrecs; ++n) {
- syslog(LOG_DEBUG, "\033[35mgetmx: %d : <%s>\033[0m", n, mxrecs[n].host);
strcat(mxbuf, mxrecs[n].host);
strcat(mxbuf, "|");
}
try_this_mx, CtdlGetConfigStr("c_fqdn")
);
curl_easy_setopt(curl, CURLOPT_URL, smtp_url);
- syslog(LOG_DEBUG, "smtpclient: trying mx %d of %d <%s>", i, num_mx, smtp_url); // send the message
+ syslog(LOG_DEBUG, "smtpclient: trying MX %d of %d <%s>", i+1, num_mx, smtp_url); // send the message
res = curl_easy_perform(curl);
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response_code);
syslog(LOG_DEBUG,