Update to nom 6

This commit is contained in:
Damian Poddebniak 2021-02-22 16:33:18 +01:00
parent 75d09f91ec
commit cc8551e357
5 changed files with 24 additions and 25 deletions

View File

@ -7,5 +7,5 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
nom = "5.1"
abnf-core = "0.3.0"
nom = "6"
abnf-core = "0.4.0"

View File

@ -17,7 +17,7 @@ use nom::{
};
pub fn command(input: &[u8]) -> IResult<&[u8], Command> {
let parser = alt((
let mut parser = alt((
helo, ehlo, mail, rcpt, data, rset, vrfy, expn, help, noop, quit,
starttls, // Extensions
auth_login, // https://interoperability.blob.core.windows.net/files/MS-XLOGIN/[MS-XLOGIN].pdf
@ -31,7 +31,7 @@ pub fn command(input: &[u8]) -> IResult<&[u8], Command> {
/// helo = "HELO" SP Domain CRLF
pub fn helo(input: &[u8]) -> IResult<&[u8], Command> {
let parser = tuple((
let mut parser = tuple((
tag_no_case(b"HELO"),
SP,
alt((Domain, address_literal)), // address_literal alternative for Geary
@ -50,7 +50,7 @@ pub fn helo(input: &[u8]) -> IResult<&[u8], Command> {
/// ehlo = "EHLO" SP ( Domain / address-literal ) CRLF
pub fn ehlo(input: &[u8]) -> IResult<&[u8], Command> {
let parser = tuple((
let mut parser = tuple((
tag_no_case(b"EHLO"),
SP,
alt((Domain, address_literal)),
@ -69,7 +69,7 @@ pub fn ehlo(input: &[u8]) -> IResult<&[u8], Command> {
/// mail = "MAIL FROM:" Reverse-path [SP Mail-parameters] CRLF
pub fn mail(input: &[u8]) -> IResult<&[u8], Command> {
let parser = tuple((
let mut parser = tuple((
tag_no_case(b"MAIL FROM:"),
opt(SP), // Out-of-Spec, but Outlook does it ...
Reverse_path,
@ -94,7 +94,7 @@ pub fn mail(input: &[u8]) -> IResult<&[u8], Command> {
/// local-parts, the "Postmaster" string shown above is
/// treated as case-insensitive.
pub fn rcpt(input: &[u8]) -> IResult<&[u8], Command> {
let parser = tuple((
let mut parser = tuple((
tag_no_case(b"RCPT TO:"),
opt(SP), // Out-of-Spec, but Outlook does it ...
alt((
@ -119,7 +119,7 @@ pub fn rcpt(input: &[u8]) -> IResult<&[u8], Command> {
/// data = "DATA" CRLF
pub fn data(input: &[u8]) -> IResult<&[u8], Command> {
let parser = tuple((tag_no_case(b"DATA"), CRLF));
let mut parser = tuple((tag_no_case(b"DATA"), CRLF));
let (remaining, _) = parser(input)?;
@ -128,7 +128,7 @@ pub fn data(input: &[u8]) -> IResult<&[u8], Command> {
/// rset = "RSET" CRLF
pub fn rset(input: &[u8]) -> IResult<&[u8], Command> {
let parser = tuple((tag_no_case(b"RSET"), CRLF));
let mut parser = tuple((tag_no_case(b"RSET"), CRLF));
let (remaining, _) = parser(input)?;
@ -137,7 +137,7 @@ pub fn rset(input: &[u8]) -> IResult<&[u8], Command> {
/// vrfy = "VRFY" SP String CRLF
pub fn vrfy(input: &[u8]) -> IResult<&[u8], Command> {
let parser = tuple((tag_no_case(b"VRFY"), SP, String, CRLF));
let mut parser = tuple((tag_no_case(b"VRFY"), SP, String, CRLF));
let (remaining, (_, _, data, _)) = parser(input)?;
@ -151,7 +151,7 @@ pub fn vrfy(input: &[u8]) -> IResult<&[u8], Command> {
/// expn = "EXPN" SP String CRLF
pub fn expn(input: &[u8]) -> IResult<&[u8], Command> {
let parser = tuple((tag_no_case(b"EXPN"), SP, String, CRLF));
let mut parser = tuple((tag_no_case(b"EXPN"), SP, String, CRLF));
let (remaining, (_, _, data, _)) = parser(input)?;
@ -165,7 +165,7 @@ pub fn expn(input: &[u8]) -> IResult<&[u8], Command> {
/// help = "HELP" [ SP String ] CRLF
pub fn help(input: &[u8]) -> IResult<&[u8], Command> {
let parser = tuple((tag_no_case(b"HELP"), opt(preceded(SP, String)), CRLF));
let mut parser = tuple((tag_no_case(b"HELP"), opt(preceded(SP, String)), CRLF));
let (remaining, (_, maybe_data, _)) = parser(input)?;
@ -179,7 +179,7 @@ pub fn help(input: &[u8]) -> IResult<&[u8], Command> {
/// noop = "NOOP" [ SP String ] CRLF
pub fn noop(input: &[u8]) -> IResult<&[u8], Command> {
let parser = tuple((tag_no_case(b"NOOP"), opt(preceded(SP, String)), CRLF));
let mut parser = tuple((tag_no_case(b"NOOP"), opt(preceded(SP, String)), CRLF));
let (remaining, (_, maybe_data, _)) = parser(input)?;
@ -193,7 +193,7 @@ pub fn noop(input: &[u8]) -> IResult<&[u8], Command> {
/// quit = "QUIT" CRLF
pub fn quit(input: &[u8]) -> IResult<&[u8], Command> {
let parser = tuple((tag_no_case(b"QUIT"), CRLF));
let mut parser = tuple((tag_no_case(b"QUIT"), CRLF));
let (remaining, _) = parser(input)?;
@ -201,7 +201,7 @@ pub fn quit(input: &[u8]) -> IResult<&[u8], Command> {
}
pub fn starttls(input: &[u8]) -> IResult<&[u8], Command> {
let parser = tuple((tag_no_case(b"STARTTLS"), CRLF));
let mut parser = tuple((tag_no_case(b"STARTTLS"), CRLF));
let (remaining, _) = parser(input)?;
@ -220,7 +220,7 @@ pub fn starttls(input: &[u8]) -> IResult<&[u8], Command> {
/// auth_login_password_challenge = "334 UGFzc3dvcmQ6" CRLF
/// auth_login_password_response = password CRLF
pub fn auth_login(input: &[u8]) -> IResult<&[u8], Command> {
let parser = tuple((
let mut parser = tuple((
tag_no_case(b"AUTH"),
SP,
tag_no_case("LOGIN"),
@ -237,7 +237,7 @@ pub fn auth_login(input: &[u8]) -> IResult<&[u8], Command> {
}
pub fn auth_plain(input: &[u8]) -> IResult<&[u8], Command> {
let parser = tuple((
let mut parser = tuple((
tag_no_case(b"AUTH"),
SP,
tag_no_case("PLAIN"),
@ -420,7 +420,7 @@ pub fn Ldh_str(input: &[u8]) -> IResult<&[u8], &[u8]> {
/// ) "]"
/// ; See Section 4.1.3
pub fn address_literal(input: &[u8]) -> IResult<&[u8], &str> {
let parser = delimited(
let mut parser = delimited(
tag(b"["),
map_res(
alt((

View File

@ -23,7 +23,7 @@ fn is_base64_char(i: u8) -> bool {
}
pub fn base64(input: &[u8]) -> IResult<&[u8], &str> {
let parser = map_res(
let mut parser = map_res(
recognize(tuple((
take_while(is_base64_char),
opt(alt((tag("=="), tag("=")))),

View File

@ -19,7 +19,7 @@ use nom::{
/// *( "220-" [ textstring ] CRLF )
/// "220" [ SP textstring ] CRLF )
pub fn Greeting(input: &[u8]) -> IResult<&[u8], GreetingType> {
let parser = alt((
let mut parser = alt((
map(
tuple((
tag(b"220 "),

View File

@ -1,11 +1,10 @@
use crate::{parse::command::Domain, types::EhloOkResp};
use abnf_core::streaming::{is_ALPHA, is_DIGIT, CRLF, SP};
use nom::multi::separated_list;
use nom::{
branch::alt,
bytes::streaming::{tag, take_while, take_while1, take_while_m_n},
combinator::{map, map_res, opt, recognize},
multi::many0,
multi::{many0, separated_list0},
sequence::{delimited, preceded, tuple},
IResult,
};
@ -17,7 +16,7 @@ use nom::{
///
/// Edit: collapsed ("250" SP) to ("250 ")
pub fn ehlo_ok_rsp(input: &[u8]) -> IResult<&[u8], EhloOkResp> {
let parser = alt((
let mut parser = alt((
map(
tuple((tag(b"250 "), Domain, opt(preceded(SP, ehlo_greet)), CRLF)),
|(_, domain, maybe_ehlo, _)| EhloOkResp {
@ -87,11 +86,11 @@ pub fn ehlo_greet(input: &[u8]) -> IResult<&[u8], &str> {
///
/// TODO: SMTP servers often respond with "AUTH=LOGIN PLAIN". Why?
pub fn ehlo_line(input: &[u8]) -> IResult<&[u8], (&str, Vec<&str>)> {
let parser = tuple((
let mut parser = tuple((
map_res(ehlo_keyword, std::str::from_utf8),
opt(preceded(
alt((SP, tag("="))), // TODO: For Outlook?
separated_list(SP, ehlo_param),
separated_list0(SP, ehlo_param),
)),
));