Avoid stack overflow with long responses.
authorTaylor R Campbell <campbell@mumble.net>
Tue, 19 Dec 2017 14:14:46 +0000 (14:14 +0000)
committerTaylor R Campbell <campbell@mumble.net>
Tue, 19 Dec 2017 14:14:46 +0000 (14:14 +0000)
src/imail/imail-imap.scm

index 34f7c52bc07d3a677b0476ef9f7bf52a779fb0f2..b4fed13a597523dc09beb6f4b9c91c6b308a3b6c 100644 (file)
@@ -2680,12 +2680,15 @@ USA.
 (define (process-queued-responses connection command)
   (with-modification-events-deferred
     (lambda ()
-      (let loop ((responses (dequeue-imap-responses connection)))
+      (let loop
+         ((responses (dequeue-imap-responses connection))
+          (returned '()))
        (if (pair? responses)
-           (if (process-response connection command (car responses))
-               (cons (car responses) (loop (cdr responses)))
-               (loop (cdr responses)))
-           '())))))
+           (loop (cdr responses)
+                 (if (process-response connection command (car responses))
+                     (cons (car responses) returned)
+                     returned))
+           (reverse! returned))))))
 \f
 (define (process-response connection command response)
   (cond ((imap:response:status-response? response)