From 0a82f91d78e2a0993c198ee4c15ff98c2816ec1b Mon Sep 17 00:00:00 2001 From: Arun Isaac Date: Sun, 16 Mar 2025 05:16:22 +0000 Subject: email: Return #f, not empty list, from field validation. * email/email.scm (sanitize-field): Rename to validate-field, and return #f on failure, not the empty list. (email-from, email-to, email-cc, email-bcc, email-date): Call validate-field, not sanitize-field. --- email/email.scm | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) (limited to 'email') diff --git a/email/email.scm b/email/email.scm index 5e1ef9d..d37b2a9 100644 --- a/email/email.scm +++ b/email/email.scm @@ -79,35 +79,34 @@ (headers mime-entity-headers) (body mime-entity-body)) -(define (sanitize-field email field) - "Sanitize @var{field} value in @var{email} and return a new sanitized -value." +(define (validate-field email field) + "Validate @var{field} value in @var{email}. Return @code{#f} if value +is invalid. Else, return the value unchanged." (let ((field-value (assq-ref (email-headers email) field))) - (if (string? field-value) - ;; Invalid fields show up as strings in the parse tree. - ;; Discard them and return an empty list. - (list) - field-value))) + ;; Invalid fields show up as strings in the parse tree. Discard + ;; them and return #f. + (and (not (string? field-value)) + field-value))) (define (email-from email) "Return list of From addresses in @var{email}." - (or (sanitize-field email 'from) + (or (validate-field email 'from) (list))) (define (email-to email) "Return list of To addresses in @var{email}." - (or (sanitize-field email 'to) + (or (validate-field email 'to) (list))) (define (email-cc email) "Return list of Cc addresses in @var{email}." - (or (sanitize-field email 'cc) + (or (validate-field email 'cc) (list))) (define (email-bcc email) "Return list of Bcc addresses in @var{email}." - (or (sanitize-field email 'bcc) + (or (validate-field email 'bcc) (list))) (define (email-subject email) @@ -117,7 +116,7 @@ value." (define (email-date email) "Return Date of @var{email}." - (sanitize-field email 'date)) + (validate-field email 'date)) (define (email-message-id email) "Return Message-ID of @var{email}." -- cgit v1.2.3