guile-email discussion
 help / color / mirror / Atom feed
From: Andrew Whatson <whatson@tailcall.au>
To: guile-email@systemreboot.net
Cc: Andrew Whatson <whatson@tailcall.au>
Subject: [PATCH] email: Support Date fields with missing seconds.
Date: Thu,  5 Jan 2023 20:33:24 +1000	[thread overview]
Message-ID: <20230105103324.4396-1-whatson@tailcall.au> (raw)

* email/email.scm (parse-email-headers): Extend the date-time parser to
match when seconds are missing, defaulting to "0".
* tests/email.scm ("Parse Date without seconds"): New test.
---
 email/email.scm | 12 +++++++++---
 tests/email.scm | 11 +++++++++++
 2 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/email/email.scm b/email/email.scm
index 71f0718..0d51eef 100644
--- a/email/email.scm
+++ b/email/email.scm
@@ -1,6 +1,7 @@
 ;;; guile-email --- Guile email parser
 ;;; Copyright © 2018, 2019, 2020, 2021 Arun Isaac <arunisaac@systemreboot.net>
 ;;; Copyright © 2021 Mathieu Othacehe <othacehe@gnu.org>
+;;; Copyright © 2023 Andrew Whatson <whatson@tailcall.au>
 ;;;
 ;;; This file is part of guile-email.
 ;;;
@@ -1050,9 +1051,14 @@ list of header keys and values."
      (received-token . ,(match-lambda*
                           (`(received-token ,token) token)))
      (date-time . ,(lambda node
-                     (match-let
-                         ((`((day ,day) (month ,month) (year ,year)
-                             (hours ,hours) (minutes ,minutes) (seconds ,seconds) (zone . ,zone))
+                     (match-let*
+                         (;; Seconds are optional; provide a default
+                          ;; binding which will be shadowed by match.
+                          (seconds "0")
+                          ((('day day) ('month month) ('year year)
+                            ('hours hours) ('minutes minutes)
+                            . (or (('seconds seconds) ('zone . zone))
+                                  (('zone . zone))))
                            (flatten-and-filter
                             '(day month year hours minutes seconds zone)
                             node)))
diff --git a/tests/email.scm b/tests/email.scm
index a6d2b46..cf565ba 100644
--- a/tests/email.scm
+++ b/tests/email.scm
@@ -1,6 +1,7 @@
 ;;; guile-email --- Guile email parser
 ;;; Copyright © 2017 Ricardo Wurmus <rekado@elephly.net>
 ;;; Copyright © 2018, 2019, 2020, 2021 Arun Isaac <arunisaac@systemreboot.net>
+;;; Copyright © 2023 Andrew Whatson <whatson@tailcall.au>
 ;;;
 ;;; This file was adapted from guile-debbugs and is part of guile-email.
 ;;;
@@ -558,6 +559,16 @@ Content-Type: text/plain; charset=utf-8
                   (charset . "utf-8"))
     (content-transfer-encoding . 7bit)))
 
+(test-alist= "Parse Date without seconds"
+  (parse-email-headers
+   "Date: Tue, 22 Nov 94 17:52 GMT
+")
+  `((date . ,(make-date 0 0 52 17 22 11 1994 0))
+    (content-type (type . text)
+                  (subtype . plain)
+                  (charset . "utf-8"))
+    (content-transfer-encoding . 7bit)))
+
 \f
 ;;;
 ;;; Email addresses
-- 
2.38.1




             reply	other threads:[~2023-01-05 10:35 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-05 10:33 Andrew Whatson [this message]
2023-01-06 14:32 ` Arun Isaac
2023-01-06 15:22   ` Arun Isaac

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230105103324.4396-1-whatson@tailcall.au \
    --to=whatson@tailcall.au \
    --cc=guile-email@systemreboot.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox