//! De-HTML. //! //! A module to remove HTML tags from the email text use std::io::BufRead; use once_cell::sync::Lazy; use quick_xml::{ events::{BytesEnd, BytesStart, BytesText}, Reader, }; use crate::simplify::{simplify_quote, SimplifiedText}; struct Dehtml { strbuilder: String, quote: String, add_text: AddText, last_href: Option, /// GMX wraps a quote in `
`. After a `
`, this count is /// increased at each `
` and decreased at each `
`. This way we know when the quote ends. /// If this is > `0`, then we are inside a `
` divs_since_quote_div: u32, /// Everything between `
` and `
` is usually metadata /// If this is > `0`, then we are inside a `
`. divs_since_quoted_content_div: u32, /// All-Inkl just puts the quote into `
`. This count is /// increased at each `
` and decreased at each `
`. blockquotes_since_blockquote: u32, } impl Dehtml { /// Returns true if HTML parser is currently inside the quote. fn is_quote(&self) -> bool { self.divs_since_quoted_content_div > 0 || self.blockquotes_since_blockquote > 0 } /// Returns the buffer where the text should be written. /// /// If the parser is inside the quote, returns the quote buffer. fn get_buf(&mut self) -> &mut String { if self.is_quote() { &mut self.quote } else { &mut self.strbuilder } } fn get_add_text(&self) -> AddText { if self.divs_since_quote_div > 0 && self.divs_since_quoted_content_div == 0 { AddText::No // Everything between `
` and `
` is metadata which we don't want } else { self.add_text } } } #[derive(Debug, PartialEq, Clone, Copy)] enum AddText { /// Inside `