mirror of
https://github.com/chatmail/core.git
synced 2026-05-02 04:46:29 +03:00
try fix filename encoding bug -- fails in one test
This commit is contained in:
@@ -448,7 +448,7 @@ class TestOnlineAccount:
|
|||||||
|
|
||||||
lp.sec("ac1: prepare and send attachment + text to ac2")
|
lp.sec("ac1: prepare and send attachment + text to ac2")
|
||||||
blobdir = ac1.get_blobdir()
|
blobdir = ac1.get_blobdir()
|
||||||
basename = "somedata.txt" # XXX try unicode
|
basename = "somedäüta.txt"
|
||||||
p = os.path.join(blobdir, basename)
|
p = os.path.join(blobdir, basename)
|
||||||
with open(p, "w") as f:
|
with open(p, "w") as f:
|
||||||
f.write("some data")
|
f.write("some data")
|
||||||
|
|||||||
@@ -980,21 +980,18 @@ fn build_body_file(
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let needs_ext = dc_needs_ext_header(&filename_to_send);
|
|
||||||
|
|
||||||
// create mime part, for Content-Disposition, see RFC 2183.
|
// create mime part, for Content-Disposition, see RFC 2183.
|
||||||
// `Content-Disposition: attachment` seems not to make a difference to `Content-Disposition: inline`
|
// `Content-Disposition: attachment` seems not to make a difference to `Content-Disposition: inline`
|
||||||
// at least on tested Thunderbird and Gma'l in 2017.
|
// at least on tested Thunderbird and Gma'l in 2017.
|
||||||
// But I've heard about problems with inline and outl'k, so we just use the attachment-type until we
|
// But I've heard about problems with inline and outl'k, so we just use the attachment-type until we
|
||||||
// run into other problems ...
|
// run into other problems ...
|
||||||
let cd_value = if needs_ext {
|
let cd_value = if needs_encoding(&filename_to_send) {
|
||||||
format!("attachment; filename=\"{}\"", &filename_to_send)
|
|
||||||
} else {
|
|
||||||
// XXX do we need to encode filenames?
|
|
||||||
format!(
|
format!(
|
||||||
"attachment; filename*=\"{}\"",
|
"attachment; filename*=\"{}\"",
|
||||||
quoted_printable::encode_to_str(&filename_to_send)
|
quoted_printable::encode_to_str(&filename_to_send)
|
||||||
)
|
)
|
||||||
|
} else {
|
||||||
|
format!("attachment; filename=\"{}\"", &filename_to_send)
|
||||||
};
|
};
|
||||||
|
|
||||||
let body = std::fs::read(blob.to_abs_path())?;
|
let body = std::fs::read(blob.to_abs_path())?;
|
||||||
@@ -1033,7 +1030,7 @@ fn is_file_size_okay(context: &Context, msg: &Message) -> bool {
|
|||||||
* Encode/decode header words, RFC 2047
|
* Encode/decode header words, RFC 2047
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
pub fn dc_needs_ext_header(to_check: impl AsRef<str>) -> bool {
|
pub fn needs_encoding(to_check: impl AsRef<str>) -> bool {
|
||||||
let to_check = to_check.as_ref();
|
let to_check = to_check.as_ref();
|
||||||
|
|
||||||
if to_check.is_empty() {
|
if to_check.is_empty() {
|
||||||
|
|||||||
@@ -579,14 +579,23 @@ impl<'a> MimeParser<'a> {
|
|||||||
// `Content-Disposition: ... filename*=...`
|
// `Content-Disposition: ... filename*=...`
|
||||||
// or `Content-Disposition: ... filename*0*=... filename*1*=... filename*2*=...`
|
// or `Content-Disposition: ... filename*0*=... filename*1*=... filename*2*=...`
|
||||||
// or `Content-Disposition: ... filename=...`
|
// or `Content-Disposition: ... filename=...`
|
||||||
|
use quoted_printable::ParseMode::Robust;
|
||||||
|
|
||||||
let ct = mail.get_content_disposition()?;
|
let ct = mail.get_content_disposition()?;
|
||||||
let mut desired_filename = ct
|
let mut desired_filename = ct
|
||||||
.params
|
.params
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|(key, _value)| key.starts_with("filename"))
|
.filter(|(key, _value)| key.starts_with("filename"))
|
||||||
.fold(String::new(), |mut acc, (_key, value)| {
|
.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;
|
acc += value;
|
||||||
|
};
|
||||||
acc
|
acc
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user