mirror of
https://github.com/chatmail/core.git
synced 2026-04-28 02:46:29 +03:00
use encoded-words crate, which friedel ported from python
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
#![deny(clippy::correctness, missing_debug_implementations, clippy::all)]
|
||||
// for now we hide warnings to not clutter/hide errors during "cargo check"
|
||||
// for now we hide warnings to not clutter/hide errors during "cargo clippy"
|
||||
#![allow(
|
||||
clippy::type_complexity,
|
||||
clippy::cognitive_complexity,
|
||||
|
||||
@@ -382,7 +382,7 @@ impl<'a, 'b> MimeFactory<'a, 'b> {
|
||||
let mut unprotected_headers: Vec<Header> = Vec::new();
|
||||
|
||||
let from = Address::new_mailbox_with_name(
|
||||
quoted_printable::encode_to_str(&self.from_displayname),
|
||||
encode_words(&self.from_displayname),
|
||||
self.from_addr.clone(),
|
||||
);
|
||||
|
||||
@@ -394,7 +394,7 @@ impl<'a, 'b> MimeFactory<'a, 'b> {
|
||||
to.push(Address::new_mailbox(addr.clone()));
|
||||
} else {
|
||||
to.push(Address::new_mailbox_with_name(
|
||||
quoted_printable::encode_to_str(name),
|
||||
encode_words(name),
|
||||
addr.clone(),
|
||||
));
|
||||
}
|
||||
@@ -450,7 +450,7 @@ impl<'a, 'b> MimeFactory<'a, 'b> {
|
||||
let e2ee_guranteed = self.is_e2ee_guranteed();
|
||||
let mut encrypt_helper = EncryptHelper::new(self.context)?;
|
||||
|
||||
let subject = quoted_printable::encode_to_str(&subject_str);
|
||||
let subject = encode_words(&subject_str);
|
||||
|
||||
let mut message = match self.loaded {
|
||||
Loaded::Message => {
|
||||
@@ -610,7 +610,7 @@ impl<'a, 'b> MimeFactory<'a, 'b> {
|
||||
if chat.typ == Chattype::Group || chat.typ == Chattype::VerifiedGroup {
|
||||
protected_headers.push(Header::new("Chat-Group-ID".into(), chat.grpid.clone()));
|
||||
|
||||
let encoded = quoted_printable::encode_to_str(&chat.name);
|
||||
let encoded = encode_words(&chat.name);
|
||||
protected_headers.push(Header::new("Chat-Group-Name".into(), encoded));
|
||||
|
||||
match command {
|
||||
@@ -988,7 +988,7 @@ fn build_body_file(
|
||||
let cd_value = if needs_encoding(&filename_to_send) {
|
||||
format!(
|
||||
"attachment; filename*=\"{}\"",
|
||||
quoted_printable::encode_to_str(&filename_to_send)
|
||||
encode_words(&filename_to_send)
|
||||
)
|
||||
} else {
|
||||
format!("attachment; filename=\"{}\"", &filename_to_send)
|
||||
@@ -1030,6 +1030,10 @@ fn is_file_size_okay(context: &Context, msg: &Message) -> bool {
|
||||
* Encode/decode header words, RFC 2047
|
||||
******************************************************************************/
|
||||
|
||||
fn encode_words(word: &str) -> String {
|
||||
encoded_words::encode(word, None, encoded_words::EncodingFlag::Shortest, None)
|
||||
}
|
||||
|
||||
pub fn needs_encoding(to_check: impl AsRef<str>) -> bool {
|
||||
let to_check = to_check.as_ref();
|
||||
|
||||
|
||||
@@ -579,23 +579,14 @@ impl<'a> MimeParser<'a> {
|
||||
// `Content-Disposition: ... filename*=...`
|
||||
// or `Content-Disposition: ... filename*0*=... filename*1*=... filename*2*=...`
|
||||
// or `Content-Disposition: ... filename=...`
|
||||
use quoted_printable::ParseMode::Robust;
|
||||
|
||||
let ct = mail.get_content_disposition()?;
|
||||
let mut desired_filename = ct
|
||||
.params
|
||||
.iter()
|
||||
.filter(|(key, _value)| key.starts_with("filename"))
|
||||
.fold(String::new(), |mut acc, (key, value)| {
|
||||
if key.starts_with("filename*") {
|
||||
quoted_printable::decode(&value, Robust)
|
||||
.map(|ref res| {
|
||||
acc += &String::from_utf8_lossy(res);
|
||||
})
|
||||
.ok();
|
||||
} else {
|
||||
acc += value;
|
||||
};
|
||||
.fold(String::new(), |mut acc, (_key, value)| {
|
||||
acc += value;
|
||||
acc
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user