fix compilation
This commit is contained in:
parent
a95095ed5d
commit
52dc154616
3 changed files with 24 additions and 24 deletions
|
@ -8,7 +8,7 @@ use nom::{
|
||||||
use crate::fragments::mime::{Mechanism, Type};
|
use crate::fragments::mime::{Mechanism, Type};
|
||||||
use crate::fragments::model::MessageId;
|
use crate::fragments::model::MessageId;
|
||||||
use crate::fragments::misc_token::Unstructured;
|
use crate::fragments::misc_token::Unstructured;
|
||||||
use crate::fragments::whitespace::perm_crlf;
|
use crate::fragments::whitespace::obs_crlf;
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Default)]
|
#[derive(Debug, PartialEq, Default)]
|
||||||
pub struct PartHeader<'a> {
|
pub struct PartHeader<'a> {
|
||||||
|
@ -29,12 +29,12 @@ pub enum Delimiter {
|
||||||
Last
|
Last
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn boundary(boundary: &[u8]) -> impl Fn(&[u8]) -> IResult<&[u8], Delimiter> {
|
pub fn boundary<'a>(boundary: &'a [u8]) -> impl Fn(&'a [u8]) -> IResult<&'a [u8], Delimiter> {
|
||||||
|input: &[u8]| {
|
move |input: &[u8]| {
|
||||||
let (_, _, _, last, _) = tuple((perm_crlf, tag(b"--"), tag(boundary), opt(tag(b"--")), perm_crlf))(input)?;
|
let (rest, (_, _, _, last, _)) = tuple((obs_crlf, tag(b"--"), tag(boundary), opt(tag(b"--")), obs_crlf))(input)?;
|
||||||
match last {
|
match last {
|
||||||
Some(_) => Delimiter::Last,
|
Some(_) => Ok((rest, Delimiter::Last)),
|
||||||
None => Delimiter::Next,
|
None => Ok((rest, Delimiter::Next)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,15 +1,29 @@
|
||||||
use crate::fragments::quoted::quoted_pair;
|
use crate::fragments::quoted::quoted_pair;
|
||||||
use nom::{
|
use nom::{
|
||||||
branch::alt,
|
branch::alt,
|
||||||
bytes::complete::tag,
|
bytes::complete::{is_not, tag},
|
||||||
character::complete::{crlf, satisfy, space0, space1},
|
character::complete::{crlf, satisfy, space0, space1},
|
||||||
combinator::{opt, recognize},
|
combinator::{opt, recognize},
|
||||||
multi::{many0, many1},
|
multi::{many0, many1},
|
||||||
sequence::tuple,
|
sequence::{pair, tuple},
|
||||||
IResult,
|
IResult,
|
||||||
};
|
};
|
||||||
use crate::fragments::encoding::encoded_word;
|
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
|
// --- whitespaces and comments
|
||||||
|
|
||||||
// Note: WSP = SP / HTAB = %x20 / %x09
|
// Note: WSP = SP / HTAB = %x20 / %x09
|
||||||
|
|
|
@ -1,14 +1,12 @@
|
||||||
use nom::{
|
use nom::{
|
||||||
branch::alt,
|
|
||||||
bytes::complete::{is_not, tag},
|
|
||||||
combinator::recognize,
|
combinator::recognize,
|
||||||
multi::many0,
|
multi::many0,
|
||||||
sequence::{pair, terminated},
|
sequence::terminated,
|
||||||
IResult,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::error::IMFError;
|
use crate::error::IMFError;
|
||||||
use crate::multipass::guess_charset;
|
use crate::multipass::guess_charset;
|
||||||
|
use crate::fragments::whitespace::{obs_crlf, line};
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
pub struct Parsed<'a> {
|
pub struct Parsed<'a> {
|
||||||
|
@ -16,10 +14,6 @@ pub struct Parsed<'a> {
|
||||||
pub body: &'a [u8],
|
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>> {
|
pub fn new<'a>(buffer: &'a [u8]) -> Result<Parsed<'a>, IMFError<'a>> {
|
||||||
terminated(recognize(many0(line)), obs_crlf)(buffer)
|
terminated(recognize(many0(line)), obs_crlf)(buffer)
|
||||||
.map_err(|e| IMFError::Segment(e))
|
.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)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
Loading…
Reference in a new issue