fix compilation

This commit is contained in:
Quentin 2023-07-16 09:55:47 +02:00
parent a95095ed5d
commit 52dc154616
Signed by: quentin
GPG key ID: E9602264D639FF68
3 changed files with 24 additions and 24 deletions

View file

@ -8,7 +8,7 @@ use nom::{
use crate::fragments::mime::{Mechanism, Type};
use crate::fragments::model::MessageId;
use crate::fragments::misc_token::Unstructured;
use crate::fragments::whitespace::perm_crlf;
use crate::fragments::whitespace::obs_crlf;
#[derive(Debug, PartialEq, Default)]
pub struct PartHeader<'a> {
@ -29,12 +29,12 @@ pub enum Delimiter {
Last
}
pub fn boundary(boundary: &[u8]) -> impl Fn(&[u8]) -> IResult<&[u8], Delimiter> {
|input: &[u8]| {
let (_, _, _, last, _) = tuple((perm_crlf, tag(b"--"), tag(boundary), opt(tag(b"--")), perm_crlf))(input)?;
pub fn boundary<'a>(boundary: &'a [u8]) -> impl Fn(&'a [u8]) -> IResult<&'a [u8], Delimiter> {
move |input: &[u8]| {
let (rest, (_, _, _, last, _)) = tuple((obs_crlf, tag(b"--"), tag(boundary), opt(tag(b"--")), obs_crlf))(input)?;
match last {
Some(_) => Delimiter::Last,
None => Delimiter::Next,
Some(_) => Ok((rest, Delimiter::Last)),
None => Ok((rest, Delimiter::Next)),
}
}
}

View file

@ -1,15 +1,29 @@
use crate::fragments::quoted::quoted_pair;
use nom::{
branch::alt,
bytes::complete::tag,
bytes::complete::{is_not, tag},
character::complete::{crlf, satisfy, space0, space1},
combinator::{opt, recognize},
multi::{many0, many1},
sequence::tuple,
sequence::{pair, tuple},
IResult,
};
use crate::fragments::encoding::encoded_word;
// Bytes CRLF
const CR: u8 = 0x0D;
const LF: u8 = 0x0A;
const CRLF: &[u8] = &[CR, LF];
pub fn line(input: &[u8]) -> IResult<&[u8], (&[u8], &[u8])> {
pair(is_not(CRLF), obs_crlf)(input)
}
pub fn obs_crlf(input: &[u8]) -> IResult<&[u8], &[u8]> {
alt((tag(CRLF), tag(&[CR]), tag(&[LF])))(input)
}
// --- whitespaces and comments
// Note: WSP = SP / HTAB = %x20 / %x09

View file

@ -1,14 +1,12 @@
use nom::{
branch::alt,
bytes::complete::{is_not, tag},
combinator::recognize,
multi::many0,
sequence::{pair, terminated},
IResult,
sequence::terminated,
};
use crate::error::IMFError;
use crate::multipass::guess_charset;
use crate::fragments::whitespace::{obs_crlf, line};
#[derive(Debug, PartialEq)]
pub struct Parsed<'a> {
@ -16,10 +14,6 @@ pub struct Parsed<'a> {
pub body: &'a [u8],
}
const CR: u8 = 0x0D;
const LF: u8 = 0x0A;
const CRLF: &[u8] = &[CR, LF];
pub fn new<'a>(buffer: &'a [u8]) -> Result<Parsed<'a>, IMFError<'a>> {
terminated(recognize(many0(line)), obs_crlf)(buffer)
.map_err(|e| IMFError::Segment(e))
@ -32,14 +26,6 @@ impl<'a> Parsed<'a> {
}
}
fn line(input: &[u8]) -> IResult<&[u8], (&[u8], &[u8])> {
pair(is_not(CRLF), obs_crlf)(input)
}
fn obs_crlf(input: &[u8]) -> IResult<&[u8], &[u8]> {
alt((tag(CRLF), tag(&[CR]), tag(&[LF])))(input)
}
#[cfg(test)]
mod tests {
use super::*;