mirror of
https://github.com/chatmail/core.git
synced 2026-05-03 13:26:28 +03:00
decode filenames as CHARSET'LANG'test%2E%70%64%66
This commit is contained in:
@@ -26,6 +26,7 @@ use crate::param::*;
|
|||||||
use crate::peerstate::Peerstate;
|
use crate::peerstate::Peerstate;
|
||||||
use crate::simplify::*;
|
use crate::simplify::*;
|
||||||
use crate::stock::StockMessage;
|
use crate::stock::StockMessage;
|
||||||
|
use percent_encoding::percent_decode_str;
|
||||||
|
|
||||||
/// A parsed MIME message.
|
/// A parsed MIME message.
|
||||||
///
|
///
|
||||||
@@ -1302,6 +1303,18 @@ fn get_attachment_filename(mail: &mailparse::ParsedMail) -> Result<Option<String
|
|||||||
let desired_filename =
|
let desired_filename =
|
||||||
desired_filename.or_else(|| mail.ctype.params.get("name").map(|s| s.to_string()));
|
desired_filename.or_else(|| mail.ctype.params.get("name").map(|s| s.to_string()));
|
||||||
|
|
||||||
|
// decode filename as CHARSET'LANG'test%2E%70%64%66.
|
||||||
|
// we're always assuming utf-8,
|
||||||
|
// however, due to lossy decoding, the extension is preserved
|
||||||
|
// and things should not be totally bad for other encodings.
|
||||||
|
// we can tweak that when we see sth. else really used in the wild nowadays.
|
||||||
|
let desired_filename = if let Some(name) = desired_filename {
|
||||||
|
let name = name.splitn(3, '\'').last().unwrap().to_string();
|
||||||
|
Some(percent_decode_str(&name).decode_utf8_lossy().to_string())
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
|
||||||
// If there is no filename, but part is an attachment, guess filename
|
// If there is no filename, but part is an attachment, guess filename
|
||||||
if ct.disposition == DispositionType::Attachment && desired_filename.is_none() {
|
if ct.disposition == DispositionType::Attachment && desired_filename.is_none() {
|
||||||
if let Some(subtype) = mail.ctype.mimetype.split('/').nth(1) {
|
if let Some(subtype) = mail.ctype.mimetype.split('/').nth(1) {
|
||||||
|
|||||||
Reference in New Issue
Block a user