From fd7bf7dffdb77cad6f7fcf30a9abec2276cfab56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rodolphe=20Br=C3=A9ard?= Date: Sat, 22 Jul 2023 15:11:33 +0200 Subject: [PATCH] Allow to parse emails with an invalid base32 code --- src/address.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/address.rs b/src/address.rs index d8b5d0b..9ea840f 100644 --- a/src/address.rs +++ b/src/address.rs @@ -27,7 +27,9 @@ impl CodedAddress { None }; let code = if parts.len() >= 3 { - BASE32_NOPAD.decode(parts[2].to_uppercase().as_bytes())? + BASE32_NOPAD + .decode(parts[2].to_uppercase().as_bytes()) + .unwrap_or(Vec::new()) } else { Vec::new() }; @@ -158,6 +160,18 @@ mod tests { assert_eq!(addr.domain, Some("example.org".to_string())); } + #[test] + fn parse_valid_coded_addr_with_invalid_base32() { + let addr_str = "a+test+invalid@example.org"; + let addr = CodedAddress::parse(addr_str, '+'); + assert!(addr.is_ok(), "unable to parse {addr_str}: {addr:?}"); + let addr = addr.unwrap(); + assert_eq!(addr.local_part, "a"); + assert_eq!(addr.sub_addr, Some("test".to_string())); + assert_eq!(addr.code, Vec::new()); + assert_eq!(addr.domain, Some("example.org".to_string())); + } + #[test] fn parse_valid_coded_addr_without_domain() { let addr_str = "local.part+test+orsxg5a";