Improve failure handling in mail threads.
authorBrenden Matthews <brenden@diddyinc.com>
Thu, 9 Sep 2010 17:48:57 +0000 (10:48 -0700)
committerBrenden Matthews <brenden@diddyinc.com>
Thu, 9 Sep 2010 17:48:57 +0000 (10:48 -0700)
When we have a failure in the mail thread, lookup the hostname again in
case the failure is due odd to DNS changes, or some other madness.

src/mail.c

index 29d6b6e..1319644 100644 (file)
@@ -672,6 +672,11 @@ static void *imap_thread(void *arg)
                int res;
                fd_set fdset;
 
+               if (fail > 0) {
+                       NORM_ERR("Trying IMAP connection again for %s@%s (try %u/%u)",
+                                       mail->user, mail->host, fail + 1, mail->retries);
+                       resolved_host = 0; /* force us to resolve the hostname again */
+               }
                if (!resolved_host) {
                        memset(&hints, 0, sizeof(struct addrinfo));
                        hints.ai_family = AF_UNSPEC;
@@ -688,10 +693,6 @@ static void *imap_thread(void *arg)
                        }
                        resolved_host = 1;
                }
-               if (fail > 0) {
-                       NORM_ERR("Trying IMAP connection again for %s@%s (try %u/%u)",
-                                       mail->user, mail->host, fail + 1, mail->retries);
-               }
                do {
                        for (rp = ai; rp != NULL; rp = rp->ai_next) {
                                sockfd = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
@@ -1018,6 +1019,12 @@ static void *pop3_thread(void *arg)
                struct timeval fetchtimeout;
                int res;
                fd_set fdset;
+
+               if (fail > 0) {
+                       NORM_ERR("Trying POP3 connection again for %s@%s (try %u/%u)",
+                                       mail->user, mail->host, fail + 1, mail->retries);
+                       resolved_host = 0; /* force us to resolve the hostname again */
+               }
                if (!resolved_host) {
                        memset(&hints, 0, sizeof(struct addrinfo));
                        hints.ai_family = AF_UNSPEC;
@@ -1034,10 +1041,6 @@ static void *pop3_thread(void *arg)
                        }
                        resolved_host = 1;
                }
-               if (fail > 0) {
-                       NORM_ERR("Trying POP3 connection again for %s@%s (try %u/%u)",
-                                       mail->user, mail->host, fail + 1, mail->retries);
-               }
                do {
                        for (rp = ai; rp != NULL; rp = rp->ai_next) {
                                sockfd = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);