MCPcopy Create free account
hub / github.com/chatmail/core / simplify

Function simplify

src/simplify.rs:115–160  ·  view source on GitHub ↗

Simplify message text for chat display. Remove quotes, signatures, trailing empty lines etc.

(mut input: String, is_chat_message: bool)

Source from the content-addressed store, hash-verified

113/// Simplify message text for chat display.
114/// Remove quotes, signatures, trailing empty lines etc.
115pub(crate) fn simplify(mut input: String, is_chat_message: bool) -> SimplifiedText {
116 let mut is_cut = false;
117
118 input.retain(|c| c != '\r');
119 let lines = split_lines(&input);
120 let (lines, is_forwarded) = skip_forward_header(&lines);
121
122 let (lines, mut top_quote) = remove_top_quote(lines, is_chat_message);
123 let original_lines = &lines;
124 let (lines, footer_lines) = remove_message_footer(lines);
125 let footer = footer_lines.map(|footer_lines| render_message(footer_lines, false));
126
127 let text = if is_chat_message {
128 render_message(lines, false)
129 } else {
130 let (lines, has_nonstandard_footer) = remove_nonstandard_footer(lines);
131 let (lines, mut bottom_quote) = remove_bottom_quote(lines);
132
133 if top_quote.is_none() && bottom_quote.is_some() {
134 std::mem::swap(&mut top_quote, &mut bottom_quote);
135 }
136
137 if lines.iter().all(|it| it.trim().is_empty()) {
138 render_message(original_lines, false)
139 } else {
140 is_cut = is_cut || has_nonstandard_footer || bottom_quote.is_some();
141 render_message(lines, has_nonstandard_footer || bottom_quote.is_some())
142 }
143 };
144
145 if !is_chat_message {
146 top_quote = top_quote.map(|quote| {
147 let (quote, quote_cut) = simplify_quote(&quote);
148 is_cut |= quote_cut;
149 quote
150 });
151 }
152
153 SimplifiedText {
154 text,
155 is_forwarded,
156 is_cut,
157 top_quote,
158 footer,
159 }
160}
161
162/// Skips "forwarded message" header.
163/// Returns message body lines and a boolean indicating whether

Callers 6

test_chat_messageFunction · 0.85
test_simplify_trimFunction · 0.85

Calls 10

split_linesFunction · 0.85
skip_forward_headerFunction · 0.85
remove_top_quoteFunction · 0.85
remove_message_footerFunction · 0.85
render_messageFunction · 0.85
remove_bottom_quoteFunction · 0.85
simplify_quoteFunction · 0.85
iterMethod · 0.45
is_emptyMethod · 0.45

Tested by 5

test_chat_messageFunction · 0.68
test_simplify_trimFunction · 0.68