From fd432bcd88b489913369b82afeea5f15636a2901 Mon Sep 17 00:00:00 2001 From: Arun Isaac Date: Mon, 1 Oct 2018 22:58:44 +0530 Subject: email: Handle truncated messages gracefully. * email/email.scm (body->mime-entities)[read-mime-entity]: Check for eof-object so that truncated messages are handled gracefully without raising an error. --- email/email.scm | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/email/email.scm b/email/email.scm index d836908..1075754 100644 --- a/email/email.scm +++ b/email/email.scm @@ -537,11 +537,15 @@ explained in RFC2045), and return that list." (negate (cut string-prefix? (string-append "--" boundary) <>)))) (define (read-mime-entity port) - (if (string-prefix? (string-append "--" boundary "--") - (get-line-with-delimiter port)) - (eof-object) - (read-till-boundary port))) - + (let ((line (get-line-with-delimiter port))) + ;; The eof-object? check returns #t only when the message is + ;; prematurely truncated. It is invoked only to handle truncated + ;; messages gracefully without raising an error. + (if (or (eof-object? line) + (string-prefix? (string-append "--" boundary "--") line)) + (eof-object) + (read-till-boundary port)))) + (call-with-input-string body (lambda (port) (read-till-boundary port) -- cgit v1.2.3