diff --git a/crates/flectar-mail-core/src/calendar/mod.rs b/crates/flectar-mail-core/src/calendar/mod.rs index d8a0e3fe..8235d56d 100644 --- a/crates/flectar-mail-core/src/calendar/mod.rs +++ b/crates/flectar-mail-core/src/calendar/mod.rs @@ -515,7 +515,15 @@ pub fn parse_ics(text: &str) -> Vec { } pub(crate) fn escape(v: &str) -> String { - let mut out = String::with_capacity(v.len()); + let capacity = v + .chars() + .map(|character| match character { + '\\' | ',' | ';' | '\n' => 2, + '\r' => 0, + _ => character.len_utf8(), + }) + .sum(); + let mut out = String::with_capacity(capacity); for c in v.chars() { match c { '\\' => out.push_str("\\\\"),