From 562076360934741af7e25ea462e47fe30dace08e Mon Sep 17 00:00:00 2001 From: Amal Saidov <58995855+amalsaidov@users.noreply.github.com> Date: Thu, 3 Dec 2026 17:01:46 +0700 Subject: [PATCH] Accept lower-case 't' separator in RFC 3339 dates (#174) --- CHANGELOG.md | 5 +++++ Cargo.toml | 2 +- src/datetime.rs | 25 +++++++++++++++++++++++-- 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a892e47..83283f3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](https://semver.org/). +## [1.0.4] - Unreleased + +### Fixed +- `DateTime::parse_rfc3339` returned `None` for a date with a lower-case `t` separator, such as `2021-11-20t14:22:01Z`, which RFC 3339 allows (#174). + ## [1.0.3] - 2026-11-29 ### Fixed diff --git a/Cargo.toml b/Cargo.toml index 81acbd3..3a6c363 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "mail-parser" description = "Fast and robust e-mail parsing library for Rust" -version = "1.0.3" +version = "1.0.4" edition = "2024" rust-version = "1.98" authors = [ "Stalwart Labs "] diff --git a/src/datetime.rs b/src/datetime.rs index 2c0b9fa..846f9a2 100644 --- a/src/datetime.rs +++ b/src/datetime.rs @@ -72,14 +72,14 @@ impl DateTime { is_plus = false; skip_digits = false; } - b'T' if pos == 2 => pos += 1, + b'T' | b't' if pos == 2 => pos += 1, b':' if matches!(pos, 3 | 4 | 6) => pos += 1, b'+' if pos == 5 => { pos += 1; skip_digits = false; } b'.' if pos == 5 => skip_digits = true, - b'-' | b'T' | b':' | b'+' | b'.' => return None, + b'-' | b'T' | b't' | b':' | b'+' | b'.' => return None, _ => (), } } @@ -290,6 +290,27 @@ mod tests { assert!(DateTime::parse_rfc3339("2004-06-28+23:43:45").is_none()); } + #[test] + fn rfc3339_lower_case_t_and_z() { + // Lower-case "t" and "z" parse like the upper-case forms (RFC 3339 section 5.6). + let upper = DateTime::parse_rfc3339("2021-11-20T14:22:01Z").expect("valid"); + for input in [ + "2021-11-20t14:22:01Z", + "2021-11-20T14:22:01z", + "2021-11-20t14:22:01z", + ] { + assert_eq!(DateTime::parse_rfc3339(input), Some(upper), "{input}"); + } + // Lower-case "t" with an explicit offset. + assert_eq!( + DateTime::parse_rfc3339("2021-11-20t14:22:01-08:00").map(|d| d.to_rfc3339()), + Some("2021-11-20T14:22:01-08:00".to_string()) + ); + // A misplaced "t" is rejected like a misplaced "T". + assert!(DateTime::parse_rfc3339("2021t11-20T14:22:01Z").is_none()); + assert!(DateTime::parse_rfc3339("2021-11-20T14:22:01t").is_none()); + } + #[test] fn timestamps() { let date = DateTime::parse_rfc3339("2021-11-20T14:22:01-08:00").expect("valid");