mirror of
https://github.com/chatmail/core.git
synced 2026-05-08 09:26:29 +03:00
Do not ellipsize everything in a message
This commit is contained in:
@@ -41,19 +41,28 @@ pub fn simplify(mut input: String, is_chat_message: bool) -> (String, bool) {
|
|||||||
let lines = split_lines(&input);
|
let lines = split_lines(&input);
|
||||||
let (lines, is_forwarded) = skip_forward_header(&lines);
|
let (lines, is_forwarded) = skip_forward_header(&lines);
|
||||||
|
|
||||||
|
let original_lines = &lines;
|
||||||
|
|
||||||
let lines = remove_message_footer(lines);
|
let lines = remove_message_footer(lines);
|
||||||
let (lines, has_nonstandard_footer) = remove_nonstandard_footer(lines);
|
let (lines, mut has_nonstandard_footer) = remove_nonstandard_footer(lines);
|
||||||
let (lines, has_bottom_quote) = if !is_chat_message {
|
let (lines, mut has_bottom_quote) = if !is_chat_message {
|
||||||
remove_bottom_quote(lines)
|
remove_bottom_quote(lines)
|
||||||
} else {
|
} else {
|
||||||
(lines, false)
|
(lines, false)
|
||||||
};
|
};
|
||||||
let (lines, has_top_quote) = if !is_chat_message {
|
let (mut lines, mut has_top_quote) = if !is_chat_message {
|
||||||
remove_top_quote(lines)
|
remove_top_quote(lines)
|
||||||
} else {
|
} else {
|
||||||
(lines, false)
|
(lines, false)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if lines.iter().all(|it| it.trim().is_empty()) {
|
||||||
|
lines = original_lines;
|
||||||
|
has_top_quote = false;
|
||||||
|
has_bottom_quote = false;
|
||||||
|
has_nonstandard_footer = false;
|
||||||
|
}
|
||||||
|
|
||||||
// re-create buffer from the remaining lines
|
// re-create buffer from the remaining lines
|
||||||
let text = render_message(
|
let text = render_message(
|
||||||
lines,
|
lines,
|
||||||
@@ -203,6 +212,17 @@ mod tests {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_dont_remove_whole_message() {
|
||||||
|
let input = "\n------\nFailed\n------\n\nUh-oh, this workflow did not succeed!\n\nlots of other text".to_string();
|
||||||
|
let (plain, is_forwarded) = simplify(input, false);
|
||||||
|
assert_eq!(
|
||||||
|
plain,
|
||||||
|
"------\nFailed\n------\n\nUh-oh, this workflow did not succeed!\n\nlots of other text"
|
||||||
|
);
|
||||||
|
assert!(!is_forwarded);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_simplify_trim() {
|
fn test_simplify_trim() {
|
||||||
let input = "line1\n\r\r\rline2".to_string();
|
let input = "line1\n\r\r\rline2".to_string();
|
||||||
|
|||||||
Reference in New Issue
Block a user