diff options
author | Arun Isaac | 2025-03-12 22:57:40 +0000 |
---|---|---|
committer | Arun Isaac | 2025-03-13 00:56:25 +0000 |
commit | 5fb1bc16aeff1e42a6e92045e0bf88dc8c034e39 (patch) | |
tree | 5d8d9eb4e8130ac8ec817212d3ee6300310ca8bb /email | |
parent | 284d26ebf06ae0bfe3fb888e895efcebf25d5ff8 (diff) | |
download | guile-email-5fb1bc16aeff1e42a6e92045e0bf88dc8c034e39.tar.gz guile-email-5fb1bc16aeff1e42a6e92045e0bf88dc8c034e39.tar.lz guile-email-5fb1bc16aeff1e42a6e92045e0bf88dc8c034e39.zip |
email: Add accessors for common header fields.
* email/email.scm (sanitize-field): New function.
(email-from, email-to, email-cc, email-bcc, email-subject, email-date,
email-message-id, email-content-type): New public functions.
* doc/guile-email.texi (Data Types): Document them.
Diffstat (limited to 'email')
-rw-r--r-- | email/email.scm | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/email/email.scm b/email/email.scm index 22d9739..5e1ef9d 100644 --- a/email/email.scm +++ b/email/email.scm @@ -43,6 +43,14 @@ email? email-headers email-body + email-from + email-to + email-cc + email-bcc + email-subject + email-date + email-message-id + email-content-type <mime-entity> make-mime-entity mime-entity? @@ -71,6 +79,56 @@ (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." + (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))) + +(define (email-from email) + "Return list of From addresses in @var{email}." + (or (sanitize-field email 'from) + (list))) + +(define (email-to email) + "Return list of To addresses in @var{email}." + (or (sanitize-field email 'to) + (list))) + +(define (email-cc email) + "Return list of Cc addresses in @var{email}." + (or (sanitize-field email 'cc) + (list))) + +(define (email-bcc email) + "Return list of Bcc addresses in @var{email}." + (or (sanitize-field email 'bcc) + (list))) + +(define (email-subject email) + "Return Subject of @var{email}." + (assq-ref (email-headers email) + 'subject)) + +(define (email-date email) + "Return Date of @var{email}." + (sanitize-field email 'date)) + +(define (email-message-id email) + "Return Message-ID of @var{email}." + (assq-ref (email-headers email) + 'message-id)) + +(define (email-content-type email) + "Return Content-Type of @var{email}." + (assq-ref (email-headers email) + 'content-type)) + (define string->lcase-symbol (compose string->symbol string-downcase)) |