mirror of
https://github.com/chatmail/core.git
synced 2026-05-05 06:16:30 +03:00
try to work around mailparser not decoding rfc2047 displaynames
this pulls in changes in our fork of rust-email to also correctly generate rfc2047 encoding
This commit is contained in:
@@ -1051,3 +1051,40 @@ pub fn needs_encoding(to_check: impl AsRef<str>) -> bool {
|
||||
!c.is_ascii_alphanumeric() && c != '-' && c != '_' && c != '.' && c != '~' && c != '%'
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use email::rfc2047::decode_rfc2047;
|
||||
use mailparse::{addrparse, MailAddr};
|
||||
|
||||
#[test]
|
||||
fn test_render_email_address() {
|
||||
let display_name = "ä space";
|
||||
let addr = "x@y.org";
|
||||
|
||||
assert!(!display_name.is_ascii());
|
||||
|
||||
let s = format!(
|
||||
"{}",
|
||||
Address::new_mailbox_with_name(display_name.to_string(), addr.to_string())
|
||||
);
|
||||
|
||||
println!("{}", s);
|
||||
assert!(s.is_ascii());
|
||||
|
||||
assert_eq!(s, "=?utf-8?q?=C3=A4_space?= <x@y.org>");
|
||||
|
||||
match &addrparse(&s).unwrap()[0] {
|
||||
MailAddr::Single(info) => {
|
||||
// XXX addrparse should not return rfc2047 encoding
|
||||
// but the decoded string, see
|
||||
// https://github.com/staktrace/mailparse/issues/50
|
||||
let s = decode_rfc2047(&info.display_name.clone().unwrap());
|
||||
assert_eq!(s, Some(display_name.to_string()));
|
||||
assert_eq!(info.addr, addr.to_string());
|
||||
}
|
||||
_ => panic!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user