diff --git a/src/lib.rs b/src/lib.rs index ebe29d5..d2fbe24 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -44,7 +44,7 @@ pub struct MailFrom { #[derive(Debug, Clone, PartialEq, Eq)] pub struct RcptTo { pub address: T, - pub orcpt: Option<(T, T)>, + pub orcpt: Option, pub rrvs: i64, pub flags: u64, } diff --git a/src/request/mod.rs b/src/request/mod.rs index e45293e..3e93bed 100644 --- a/src/request/mod.rs +++ b/src/request/mod.rs @@ -103,6 +103,12 @@ pub(crate) const ORCPT: u128 = (b'O' as u128) | (b'C' as u128) << 16 | (b'P' as u128) << 24 | (b'T' as u128) << 32; +pub(crate) const RFC822: u64 = (b'R' as u64) + | (b'F' as u64) << 8 + | (b'C' as u64) << 16 + | (b'8' as u64) << 24 + | (b'2' as u64) << 32 + | (b'2' as u64) << 40; pub(crate) const RET: u128 = (b'R' as u128) | (b'E' as u128) << 8 | (b'T' as u128) << 16; pub(crate) const ENVID: u128 = (b'E' as u128) | (b'N' as u128) << 8 diff --git a/src/request/parser.rs b/src/request/parser.rs index 6ab6683..2d528ca 100644 --- a/src/request/parser.rs +++ b/src/request/parser.rs @@ -881,7 +881,7 @@ impl<'x, 'y> Rfc5321Parser<'x, 'y> { } ENVID if self.stop_char == b'=' => { let env_id = self.xtext()?; - if self.stop_char.is_ascii_whitespace() && !env_id.is_empty() { + if self.stop_char.is_ascii_whitespace() && (1..=100).contains(&env_id.len()) { params.env_id = env_id.into(); } else { self.seek_lf()?; @@ -1032,17 +1032,14 @@ impl<'x, 'y> Rfc5321Parser<'x, 'y> { } }, ORCPT if self.stop_char == b'=' => { - let addr_type = self.seek_char(b';')?; - if self.stop_char != b';' { + let v = self.hashed_value()?; + if v != RFC822 || self.stop_char != b';' { self.seek_lf()?; return Err(Error::InvalidParameter { param: "ORCPT" }); } let addr = self.xtext()?; - if self.stop_char.is_ascii_whitespace() - && !addr_type.is_empty() - && !addr.is_empty() - { - params.orcpt = (addr_type, addr).into(); + if self.stop_char.is_ascii_whitespace() && (1..=500).contains(&addr.len()) { + params.orcpt = addr.into(); } else { self.seek_lf()?; return Err(Error::InvalidParameter { param: "ORCPT" }); @@ -1802,7 +1799,7 @@ mod tests { Ok(Request::Rcpt { to: RcptTo { address: "".to_string(), - orcpt: ("rfc822".to_string(), "Bob@Example.COM".to_string()).into(), + orcpt: "Bob@Example.COM".to_string().into(), ..Default::default() }, }), @@ -1812,7 +1809,7 @@ mod tests { Ok(Request::Rcpt { to: RcptTo { address: "".to_string(), - orcpt: ("rfc822".to_string(), "George @Tax- ME .GOV".to_string()).into(), + orcpt: "George @Tax- ME .GOV".to_string().into(), ..Default::default() }, }),