diff options
author | Arun Isaac | 2025-03-16 05:16:22 +0000 |
---|---|---|
committer | Arun Isaac | 2025-03-16 05:16:22 +0000 |
commit | 0a82f91d78e2a0993c198ee4c15ff98c2816ec1b (patch) | |
tree | 0c28f5118ccbeaf814b97c85cae65f9e8c74c434 /email/email.scm | |
parent | dd850b54daec4e2dc2c27bcc820f584871b6f7c5 (diff) | |
download | guile-email-0a82f91d78e2a0993c198ee4c15ff98c2816ec1b.tar.gz guile-email-0a82f91d78e2a0993c198ee4c15ff98c2816ec1b.tar.lz guile-email-0a82f91d78e2a0993c198ee4c15ff98c2816ec1b.zip |
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.
Diffstat (limited to 'email/email.scm')
-rw-r--r-- | email/email.scm | 25 |
1 files changed, 12 insertions, 13 deletions
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}." |