mirror of
https://github.com/chatmail/core.git
synced 2026-04-17 21:46:35 +03:00
passes test but needs cleanup
This commit is contained in:
@@ -477,6 +477,30 @@ class TestOnlineAccount:
|
|||||||
assert msg2.filename.endswith("html.zip")
|
assert msg2.filename.endswith("html.zip")
|
||||||
assert msg.filename != msg2.filename
|
assert msg.filename != msg2.filename
|
||||||
|
|
||||||
|
def test_send_file_html_attachment(self, tmpdir, acfactory, lp):
|
||||||
|
ac1, ac2 = acfactory.get_two_online_accounts()
|
||||||
|
chat = self.get_chat(ac1, ac2)
|
||||||
|
|
||||||
|
basename = "test.html"
|
||||||
|
content = "<html><body>text</body>data"
|
||||||
|
|
||||||
|
p = os.path.join(tmpdir.strpath, basename)
|
||||||
|
with open(p, "w") as f:
|
||||||
|
# write wrong html to see if core tries to parse it
|
||||||
|
# (it shouldn't as it's a file attachment)
|
||||||
|
f.write(content)
|
||||||
|
|
||||||
|
lp.sec("ac1: prepare and send attachment + text to ac2")
|
||||||
|
chat.send_file(p, mime_type="text/html")
|
||||||
|
|
||||||
|
lp.sec("ac2: receive message")
|
||||||
|
ev = ac2._evlogger.get_matching("DC_EVENT_INCOMING_MSG|DC_EVENT_MSGS_CHANGED")
|
||||||
|
assert ev[2] > const.DC_CHAT_ID_LAST_SPECIAL
|
||||||
|
msg = ac2.get_message_by_id(ev[2])
|
||||||
|
|
||||||
|
assert open(msg.filename).read() == content
|
||||||
|
assert msg.filename.endswith(basename)
|
||||||
|
|
||||||
def test_mvbox_sentbox_threads(self, acfactory, lp):
|
def test_mvbox_sentbox_threads(self, acfactory, lp):
|
||||||
lp.sec("ac1: start with mvbox thread")
|
lp.sec("ac1: start with mvbox thread")
|
||||||
ac1 = acfactory.get_online_configuring_account(mvbox=True, sentbox=True)
|
ac1 = acfactory.get_online_configuring_account(mvbox=True, sentbox=True)
|
||||||
|
|||||||
@@ -509,11 +509,22 @@ impl<'a> MimeParser<'a> {
|
|||||||
let (mime_type, msg_type) = get_mime_type(mail)?;
|
let (mime_type, msg_type) = get_mime_type(mail)?;
|
||||||
let raw_mime = mail.ctype.mimetype.to_lowercase();
|
let raw_mime = mail.ctype.mimetype.to_lowercase();
|
||||||
|
|
||||||
|
info!(
|
||||||
|
self.context,
|
||||||
|
"add_single_part_if_known {:?} {:?}", mime_type, msg_type
|
||||||
|
);
|
||||||
|
|
||||||
let old_part_count = self.parts.len();
|
let old_part_count = self.parts.len();
|
||||||
|
|
||||||
|
let is_attachment = mail
|
||||||
|
.get_content_disposition()?
|
||||||
|
.params
|
||||||
|
.iter()
|
||||||
|
.any(|(key, _value)| key.starts_with("filename"));
|
||||||
|
|
||||||
// regard `Content-Transfer-Encoding:`
|
// regard `Content-Transfer-Encoding:`
|
||||||
match mime_type.type_() {
|
match mime_type.type_() {
|
||||||
mime::TEXT | mime::HTML => {
|
mime::TEXT | mime::HTML if !is_attachment => {
|
||||||
let decoded_data = match mail.get_body() {
|
let decoded_data = match mail.get_body() {
|
||||||
Ok(decoded_data) => decoded_data,
|
Ok(decoded_data) => decoded_data,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
@@ -547,7 +558,12 @@ impl<'a> MimeParser<'a> {
|
|||||||
self.is_forwarded = true;
|
self.is_forwarded = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mime::IMAGE | mime::AUDIO | mime::VIDEO | mime::APPLICATION => {
|
mime::TEXT
|
||||||
|
| mime::HTML
|
||||||
|
| mime::IMAGE
|
||||||
|
| mime::AUDIO
|
||||||
|
| mime::VIDEO
|
||||||
|
| mime::APPLICATION => {
|
||||||
// try to get file name from
|
// try to get file name from
|
||||||
// `Content-Disposition: ... filename*=...`
|
// `Content-Disposition: ... filename*=...`
|
||||||
// or `Content-Disposition: ... filename*0*=... filename*1*=... filename*2*=...`
|
// or `Content-Disposition: ... filename*0*=... filename*1*=... filename*2*=...`
|
||||||
|
|||||||
Reference in New Issue
Block a user