diff --git a/src/dc_simplify.rs b/src/dc_simplify.rs index f9c83eed6..30a49ef05 100644 --- a/src/dc_simplify.rs +++ b/src/dc_simplify.rs @@ -1,4 +1,4 @@ -use crate::dc_dehtml::*; +use crate::dehtml::*; #[derive(Copy, Clone)] pub struct Simplify { @@ -34,7 +34,7 @@ impl Simplify { /// The data returned from simplify() must be free()'d when no longer used. pub fn simplify(&mut self, input: &str, is_html: bool, is_msgrmsg: bool) -> String { let mut out = if is_html { - dc_dehtml(input) + dehtml(input) } else { input.to_string() }; diff --git a/src/dc_dehtml.rs b/src/dehtml.rs similarity index 90% rename from src/dc_dehtml.rs rename to src/dehtml.rs index 80a642331..00b59aba9 100644 --- a/src/dc_dehtml.rs +++ b/src/dehtml.rs @@ -1,3 +1,7 @@ +//! De-HTML +//! +//! A module to remove HTML tags from the email text + use lazy_static::lazy_static; use quick_xml; use quick_xml::events::{BytesEnd, BytesStart, BytesText}; @@ -19,22 +23,18 @@ enum AddText { YesPreserveLineEnds, } -// dc_dehtml() returns way too many lineends; however, an optimisation on this issue is not needed as -// the lineends are typically remove in further processing by the caller -pub fn dc_dehtml(buf_terminated: &str) -> String { - let buf_terminated = buf_terminated.trim(); - - if buf_terminated.is_empty() { - return "".into(); - } +// dehtml() returns way too many newlines; however, an optimisation on this issue is not needed as +// the newlines are typically removed in further processing by the caller +pub fn dehtml(buf: &str) -> String { + let buf = buf.trim(); let mut dehtml = Dehtml { - strbuilder: String::with_capacity(buf_terminated.len()), + strbuilder: String::with_capacity(buf.len()), add_text: AddText::YesRemoveLineEnds, last_href: None, }; - let mut reader = quick_xml::Reader::from_str(buf_terminated); + let mut reader = quick_xml::Reader::from_str(buf); let mut buf = Vec::new(); @@ -171,7 +171,7 @@ mod tests { use super::*; #[test] - fn test_dc_dehtml() { + fn test_dehtml() { let cases = vec![ ( " Foo ", @@ -186,7 +186,7 @@ mod tests { ("", ""), ]; for (input, output) in cases { - assert_eq!(dc_dehtml(input), output); + assert_eq!(dehtml(input), output); } } } diff --git a/src/lib.rs b/src/lib.rs index fd61d2821..64c39353a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -65,12 +65,12 @@ mod token; mod wrapmime; pub mod dc_array; -mod dc_dehtml; pub mod dc_mimeparser; pub mod dc_receive_imf; mod dc_simplify; mod dc_strencode; pub mod dc_tools; +mod dehtml; #[cfg(test)] mod test_utils;