mirror of
https://github.com/chatmail/core.git
synced 2026-04-19 14:36:29 +03:00
Move dc_dehtml to dehtml and remove unnecessary is_empty check
This commit is contained in:
@@ -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()
|
||||
};
|
||||
|
||||
@@ -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![
|
||||
(
|
||||
"<a href='https://example.com'> Foo </a>",
|
||||
@@ -186,7 +186,7 @@ mod tests {
|
||||
("", ""),
|
||||
];
|
||||
for (input, output) in cases {
|
||||
assert_eq!(dc_dehtml(input), output);
|
||||
assert_eq!(dehtml(input), output);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user