Skip to content

Commit

Permalink
Implement support for RFC822.HEADER (see #11)
Browse files Browse the repository at this point in the history
  • Loading branch information
djc committed Apr 27, 2018
1 parent 09848b9 commit e25a5c8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
17 changes: 16 additions & 1 deletion imap-proto/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,12 @@ named!(msg_att_rfc822<AttributeValue>, do_parse!(
(AttributeValue::Rfc822(raw))
));

named!(msg_att_rfc822_header<AttributeValue>, do_parse!(
tag_s!("RFC822.HEADER ") >>
raw: nstring >>
(AttributeValue::Rfc822Header(raw))
));

named!(msg_att_rfc822_size<AttributeValue>, do_parse!(
tag_s!("RFC822.SIZE ") >>
num: number >>
Expand All @@ -546,6 +552,7 @@ named!(msg_att<AttributeValue>, alt!(
msg_att_flags |
msg_att_mod_seq |
msg_att_rfc822 |
msg_att_rfc822_header |
msg_att_rfc822_size |
msg_att_uid
));
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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),
}
}
}
1 change: 1 addition & 0 deletions imap-proto/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
Expand Down

3 comments on commit e25a5c8

@jonhoo
Copy link
Contributor

@jonhoo jonhoo commented on e25a5c8 Apr 27, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe also add a test case for a successful parse? :p
Could you also publish a new minor version including this fix?

@djc
Copy link
Owner Author

@djc djc commented on e25a5c8 Apr 27, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you can try the successful parse case? ;) 0.4.1 is live on crates.io now.

@jonhoo
Copy link
Contributor

@jonhoo jonhoo commented on e25a5c8 Apr 27, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems to work perfectly!

Please sign in to comment.