more proto stuff
This commit is contained in:
parent
04a6d45802
commit
043feadd71
5 changed files with 57 additions and 15 deletions
|
@ -1,5 +1,9 @@
|
|||
#![allow(non_snake_case, dead_code)]
|
||||
|
||||
mod prelude;
|
||||
mod rfc2234;
|
||||
mod rfc3501;
|
||||
// data types
|
||||
pub mod response;
|
||||
|
||||
// parsers
|
||||
pub mod parsers;
|
||||
pub mod rfc2234;
|
||||
pub mod rfc3501;
|
||||
|
|
33
imap/src/proto/response.rs
Normal file
33
imap/src/proto/response.rs
Normal file
|
@ -0,0 +1,33 @@
|
|||
use std::borrow::Cow;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Tag(pub String);
|
||||
|
||||
pub enum Response<'a> {
|
||||
Done(ResponseDone<'a>),
|
||||
}
|
||||
|
||||
pub struct ResponseDone<'a> {
|
||||
pub tag: Tag,
|
||||
pub status: Status,
|
||||
pub code: Option<ResponseCode<'a>>,
|
||||
pub info: Option<Cow<'a, str>>,
|
||||
}
|
||||
|
||||
pub enum Status {
|
||||
Ok,
|
||||
No,
|
||||
Bad,
|
||||
PreAuth,
|
||||
Bye,
|
||||
}
|
||||
|
||||
pub enum ResponseCode<'a> {
|
||||
Capabilities(Vec<Capability<'a>>),
|
||||
}
|
||||
|
||||
pub enum Capability<'a> {
|
||||
Imap4rev1,
|
||||
Auth(Cow<'a, str>),
|
||||
Atom(Cow<'a, str>),
|
||||
}
|
|
@ -1,14 +1,8 @@
|
|||
//! Grammar from https://tools.ietf.org/html/rfc2234#section-6.1
|
||||
|
||||
use nom::{
|
||||
branch::alt,
|
||||
character::streaming::{anychar},
|
||||
multi::many0,
|
||||
sequence::pair,
|
||||
IResult,
|
||||
};
|
||||
use nom::{branch::alt, character::streaming::anychar, multi::many0, sequence::pair, IResult};
|
||||
|
||||
use super::prelude::{satisfy, skip, byte};
|
||||
use super::parsers::{byte, satisfy, skip};
|
||||
|
||||
pub fn ALPHA(i: &[u8]) -> IResult<&[u8], u8> {
|
||||
satisfy(|c| (c >= b'a' && c <= b'z') || (c >= b'A' && c <= b'Z'))(i)
|
||||
|
|
|
@ -6,20 +6,29 @@ use nom::{
|
|||
character::streaming::char,
|
||||
combinator::{map, map_res},
|
||||
multi::{many0, many1},
|
||||
sequence::delimited,
|
||||
sequence::{delimited, terminated},
|
||||
IResult,
|
||||
};
|
||||
|
||||
use super::rfc2234::{DIGIT, DQUOTE};
|
||||
use super::rfc2234::{CRLF, DIGIT, DQUOTE};
|
||||
|
||||
/// literal = "{" number "}" CRLF *CHAR8
|
||||
/// ; Number represents the number of CHAR8s
|
||||
pub fn literal(i: &[u8]) -> IResult<&[u8], Vec<u8>> {
|
||||
let mut length_of = delimited(char('{'), number, char('}'));
|
||||
let mut length_of = terminated(delimited(char('{'), number, char('}')), CRLF);
|
||||
let (i, length) = length_of(i)?;
|
||||
println!("length is: {:?}", (i, length));
|
||||
map(take(length), |s: &[u8]| s.to_vec())(i)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_literal() {
|
||||
assert_eq!(
|
||||
literal(b"{13}\r\nHello, world!").unwrap().1,
|
||||
b"Hello, world!"
|
||||
);
|
||||
}
|
||||
|
||||
pub fn nil(i: &[u8]) -> IResult<&[u8], &[u8]> {
|
||||
tag_no_case("NIL")(i)
|
||||
}
|
||||
|
@ -29,7 +38,9 @@ pub fn nstring(i: &[u8]) -> IResult<&[u8], Option<Vec<u8>>> {
|
|||
}
|
||||
|
||||
pub fn number(i: &[u8]) -> IResult<&[u8], u32> {
|
||||
map_res(map_res(many1(DIGIT), String::from_utf8), |s| s.parse::<u32>())(i)
|
||||
map_res(map_res(many1(DIGIT), String::from_utf8), |s| {
|
||||
s.parse::<u32>()
|
||||
})(i)
|
||||
}
|
||||
|
||||
pub fn quoted(i: &[u8]) -> IResult<&[u8], Vec<u8>> {
|
||||
|
|
Loading…
Reference in a new issue