Implement new parser in parse.rs

This commit is contained in:
Quentin 2023-06-20 18:58:07 +02:00
parent 8e67af6c2c
commit 34334398d8
Signed by: quentin
GPG key ID: E9602264D639FF68

View file

@ -1,4 +1,4 @@
use imf_codec::fragments::header; use imf_codec::multipass;
use std::io; use std::io;
use std::io::Read; use std::io::Read;
@ -9,14 +9,21 @@ fn main() {
io::stdin().lock().read_to_end(&mut rawmail).unwrap(); io::stdin().lock().read_to_end(&mut rawmail).unwrap();
// Parse it // Parse it
let (email, encoding, malformed) = header::from_bytes(&rawmail); let segment = multipass::segment::Segment::try_from(&rawmail[..]).unwrap();
println!("Encoding: {:?}, Malformed: {:?}", encoding, malformed); let charng = multipass::guess_charset::GuessCharset::from(segment);
let extr = multipass::extract_fields::ExtractFields::try_from(&charng).unwrap();
let lazy = multipass::field_lazy::Parsed::from(extr);
let eager = multipass::field_eager::Parsed::from(lazy);
let section = multipass::header_section::Parsed::from(eager);
//let section: multipass::header_section::Parsed = rawmail.as_ref().into();
//let (email, encoding, malformed) = header::from_bytes(&rawmail);
//println!("Encoding: {:?}, Malformed: {:?}", encoding, malformed);
let (input, hdrs) = header::section(&email).unwrap(); //let (input, hdrs) = header::section(&email).unwrap();
// Checks/debug // Checks/debug
println!("{:?}", hdrs); println!("{:?}", section);
assert!(hdrs.date.is_some()); //assert!(hdrs.date.is_some());
assert!(hdrs.from.len() > 0); //assert!(hdrs.from.len() > 0);
assert!(hdrs.bad_fields.len() == 0); //assert!(hdrs.bad_fields.len() == 0);
} }