From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [192.168.2.1] (port=24313 helo=ringwood.hosting-cloud.net) by systemreboot.net with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1pDNaQ-0002Xl-1o for guile-email@systemreboot.net; Thu, 05 Jan 2023 16:05:03 +0530 X-Mailborder-Info: host=console.hosting-cloud.net, gmt_time=1672914899, scan_time=2.1s X-Mailborder-Spam-Score: 1.6 X-Mailborder-Spam-X: xx X-Mailborder-Spam-Report: ALL_TRUSTED, BAYES_50, URIBL_DBL_BLOCKED_OPENDNS, URIBL_ZEN_BLOCKED_OPENDNS, SPF_FAIL, DKIM_SIGNED, DKIM_INVALID, MB_DMARC_FAIL, Received: from cp61.hosting-cloud.net (unknown [103.119.110.239]) by smtp.hosting-cloud.net (Postfix) with ESMTPSA id AE88E7F1DF for ; Thu, 5 Jan 2023 21:33:33 +1100 (AEDT) DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.hosting-cloud.net AE88E7F1DF Authentication-Results: console.hosting-cloud.net; dmarc=fail (p=quarantine dis=none) header.from=tailcall.au Authentication-Results: console.hosting-cloud.net; spf=fail smtp.mailfrom=whatson@tailcall.au DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.hosting-cloud.net AE88E7F1DF Authentication-Results: smtp.hosting-cloud.net; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=tailcall.au header.i=@tailcall.au header.b="TCk1jPk6"; dkim-atps=neutral DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tailcall.au ; s=x; h=Content-Transfer-Encoding:Content-Type:MIME-Version:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:Content-ID:Content-Description:Resent-Date :Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Id:List-Help:List-Unsubscribe:List-Subscribe:List-Post: List-Owner:List-Archive; bh=eYCTgKpxvcGbNG/NPm78BuBLSWoxUDlxZzdmIo4J634=; b=T Ck1jPk6nsuXDC4+UIxl8Td4N8PvVIXSw5uCXM4lqYoPS9j2GwiXk08ZlvcIxxGW9eWr4q88nrKaeV g84WdtLJjt7v1+ENV49tdFufeIwri+/SbEhofEvOp4MKAeRN40OTmOqk1Fy+i7wH4CPiDFe38u76l BwG9BNPAckrkLdT6nMhfrGx8+EqvsnBQOadLyj6NBPBsYMrjnxa4FNmVvz4xkmiTVoMgQMJACad1w YDwI/eJHh1LouHMCLuo4BG4s3aZ0FrbKn68e6FXqR/DQUPzYtJPowIo8KnAexSEox/R0qlDv64kde 0GlYbZtCdbropxS98D3tEtFMb9NcaO4nw==; Received: from eft1854679.lnk.telstra.net ([101.187.131.186] helo=fumo.fritz.box) by cp61.hosting-cloud.net with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1pDNZ0-0067WR-0v; Thu, 05 Jan 2023 21:33:34 +1100 From: Andrew Whatson To: guile-email@systemreboot.net Cc: Andrew Whatson Subject: [PATCH] email: Support Date fields with missing seconds. Date: Thu, 5 Jan 2023 20:33:24 +1000 Message-Id: <20230105103324.4396-1-whatson@tailcall.au> X-Mailer: git-send-email 2.38.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-AuthUser: whatson@tailcall.au List-Id: * 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 ;;; Copyright © 2021 Mathieu Othacehe +;;; Copyright © 2023 Andrew Whatson ;;; ;;; 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 ;;; Copyright © 2018, 2019, 2020, 2021 Arun Isaac +;;; Copyright © 2023 Andrew Whatson ;;; ;;; 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))) + ;;; ;;; Email addresses -- 2.38.1