From e25a5c8819292fd170cda4d2337e9d0f38e7743a Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Fri, 27 Apr 2018 19:52:38 +0200 Subject: [PATCH] Implement support for RFC822.HEADER (see #11) --- imap-proto/src/parser.rs | 17 ++++++++++++++++- imap-proto/src/types.rs | 1 + 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/imap-proto/src/parser.rs b/imap-proto/src/parser.rs index 4dca6c1..5fdadf0 100644 --- a/imap-proto/src/parser.rs +++ b/imap-proto/src/parser.rs @@ -520,6 +520,12 @@ named!(msg_att_rfc822, do_parse!( (AttributeValue::Rfc822(raw)) )); +named!(msg_att_rfc822_header, do_parse!( + tag_s!("RFC822.HEADER ") >> + raw: nstring >> + (AttributeValue::Rfc822Header(raw)) +)); + named!(msg_att_rfc822_size, do_parse!( tag_s!("RFC822.SIZE ") >> num: number >> @@ -546,6 +552,7 @@ named!(msg_att, alt!( msg_att_flags | msg_att_mod_seq | msg_att_rfc822 | + msg_att_rfc822_header | msg_att_rfc822_size | msg_att_uid )); @@ -670,7 +677,7 @@ pub fn parse_response(msg: &[u8]) -> ParseResult { #[cfg(test)] mod tests { use types::*; - use super::{parse_response, IResult}; + use super::{nom, parse_response, IResult}; #[test] fn test_number_overflow() { @@ -753,4 +760,12 @@ mod tests { rsp @ _ => panic!("unexpected response {:?}", rsp), } } + + #[test] + fn test_uid_fetch() { + match parse_response(b"* 4 FETCH (UID 71372 RFC822.HEADER {10275}\r\n") { + IResult::Incomplete(nom::Needed::Size(10319)) => {}, + rsp => panic!("unexpected response {:?}", rsp), + } + } } diff --git a/imap-proto/src/types.rs b/imap-proto/src/types.rs index dd9f478..36e632e 100644 --- a/imap-proto/src/types.rs +++ b/imap-proto/src/types.rs @@ -122,6 +122,7 @@ pub enum AttributeValue<'a> { InternalDate(&'a str), ModSeq(u64), // RFC 4551, section 3.3.2 Rfc822(Option<&'a [u8]>), + Rfc822Header(Option<&'a [u8]>), Rfc822Size(u32), Uid(u32), }