mirror of
https://github.com/chatmail/core.git
synced 2026-05-02 12:56:30 +03:00
Add mappings for some file types to Viewtype / MIME type
Namely: ppt, pptx, xls, heif, heic, avif, txt. But use Viewtype::File for medias without uniform support on all platforms.
This commit is contained in:
@@ -8,6 +8,7 @@
|
|||||||
- Move format=flowed support to a separate crate #3869
|
- Move format=flowed support to a separate crate #3869
|
||||||
- cargo: bump quick-xml from 0.23.0 to 0.26.0 #3722
|
- cargo: bump quick-xml from 0.23.0 to 0.26.0 #3722
|
||||||
- Add fuzzing tests #3853
|
- Add fuzzing tests #3853
|
||||||
|
- Add mappings for some file types to Viewtype / MIME type #3881
|
||||||
|
|
||||||
### API-Changes
|
### API-Changes
|
||||||
- jsonrpc: add python API for webxdc updates #3872
|
- jsonrpc: add python API for webxdc updates #3872
|
||||||
|
|||||||
2
python/tests/data/r
Normal file
2
python/tests/data/r
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
|
||||||
|
hello
|
||||||
@@ -450,24 +450,25 @@ class TestOfflineChat:
|
|||||||
assert msg.filemime == "image/png"
|
assert msg.filemime == "image/png"
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"typein,typeout",
|
"fn,typein,typeout",
|
||||||
[
|
[
|
||||||
(None, "application/octet-stream"),
|
("r", None, "application/octet-stream"),
|
||||||
("text/plain", "text/plain"),
|
("r.txt", None, "text/plain"),
|
||||||
("image/png", "image/png"),
|
("r.txt", "text/plain", "text/plain"),
|
||||||
|
("r.txt", "image/png", "image/png"),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_message_file(self, ac1, chat1, data, lp, typein, typeout):
|
def test_message_file(self, ac1, chat1, data, lp, fn, typein, typeout):
|
||||||
lp.sec("sending file")
|
lp.sec("sending file")
|
||||||
fn = data.get_path("r.txt")
|
fp = data.get_path(fn)
|
||||||
msg = chat1.send_file(fn, typein)
|
msg = chat1.send_file(fp, typein)
|
||||||
assert msg
|
assert msg
|
||||||
assert msg.id > 0
|
assert msg.id > 0
|
||||||
assert msg.is_file()
|
assert msg.is_file()
|
||||||
assert os.path.exists(msg.filename)
|
assert os.path.exists(msg.filename)
|
||||||
assert msg.filename.endswith(msg.basename)
|
assert msg.filename.endswith(msg.basename)
|
||||||
assert msg.filemime == typeout
|
assert msg.filemime == typeout
|
||||||
msg2 = chat1.send_file(fn, typein)
|
msg2 = chat1.send_file(fp, typein)
|
||||||
assert msg2 != msg
|
assert msg2 != msg
|
||||||
assert msg2.filename != msg.filename
|
assert msg2.filename != msg.filename
|
||||||
|
|
||||||
|
|||||||
@@ -1168,6 +1168,7 @@ pub fn guess_msgtype_from_suffix(path: &Path) -> Option<(Viewtype, &str)> {
|
|||||||
"3gp" => (Viewtype::Video, "video/3gpp"),
|
"3gp" => (Viewtype::Video, "video/3gpp"),
|
||||||
"aac" => (Viewtype::Audio, "audio/aac"),
|
"aac" => (Viewtype::Audio, "audio/aac"),
|
||||||
"avi" => (Viewtype::Video, "video/x-msvideo"),
|
"avi" => (Viewtype::Video, "video/x-msvideo"),
|
||||||
|
"avif" => (Viewtype::File, "image/avif"), // supported since Android 12 / iOS 16
|
||||||
"doc" => (Viewtype::File, "application/msword"),
|
"doc" => (Viewtype::File, "application/msword"),
|
||||||
"docx" => (
|
"docx" => (
|
||||||
Viewtype::File,
|
Viewtype::File,
|
||||||
@@ -1176,6 +1177,8 @@ pub fn guess_msgtype_from_suffix(path: &Path) -> Option<(Viewtype, &str)> {
|
|||||||
"epub" => (Viewtype::File, "application/epub+zip"),
|
"epub" => (Viewtype::File, "application/epub+zip"),
|
||||||
"flac" => (Viewtype::Audio, "audio/flac"),
|
"flac" => (Viewtype::Audio, "audio/flac"),
|
||||||
"gif" => (Viewtype::Gif, "image/gif"),
|
"gif" => (Viewtype::Gif, "image/gif"),
|
||||||
|
"heic" => (Viewtype::File, "image/heic"), // supported since Android 10 / iOS 11
|
||||||
|
"heif" => (Viewtype::File, "image/heif"), // supported since Android 10 / iOS 11
|
||||||
"html" => (Viewtype::File, "text/html"),
|
"html" => (Viewtype::File, "text/html"),
|
||||||
"htm" => (Viewtype::File, "text/html"),
|
"htm" => (Viewtype::File, "text/html"),
|
||||||
"ico" => (Viewtype::File, "image/vnd.microsoft.icon"),
|
"ico" => (Viewtype::File, "image/vnd.microsoft.icon"),
|
||||||
@@ -1200,10 +1203,15 @@ pub fn guess_msgtype_from_suffix(path: &Path) -> Option<(Viewtype, &str)> {
|
|||||||
"oga" => (Viewtype::Audio, "audio/ogg"),
|
"oga" => (Viewtype::Audio, "audio/ogg"),
|
||||||
"ogg" => (Viewtype::Audio, "audio/ogg"),
|
"ogg" => (Viewtype::Audio, "audio/ogg"),
|
||||||
"ogv" => (Viewtype::File, "video/ogg"),
|
"ogv" => (Viewtype::File, "video/ogg"),
|
||||||
"opus" => (Viewtype::File, "audio/ogg"), // not supported eg. on Android 4
|
"opus" => (Viewtype::File, "audio/ogg"), // supported since Android 10
|
||||||
"otf" => (Viewtype::File, "font/otf"),
|
"otf" => (Viewtype::File, "font/otf"),
|
||||||
"pdf" => (Viewtype::File, "application/pdf"),
|
"pdf" => (Viewtype::File, "application/pdf"),
|
||||||
"png" => (Viewtype::Image, "image/png"),
|
"png" => (Viewtype::Image, "image/png"),
|
||||||
|
"ppt" => (Viewtype::File, "application/vnd.ms-powerpoint"),
|
||||||
|
"pptx" => (
|
||||||
|
Viewtype::File,
|
||||||
|
"application/vnd.openxmlformats-officedocument.presentationml.presentation",
|
||||||
|
),
|
||||||
"rar" => (Viewtype::File, "application/vnd.rar"),
|
"rar" => (Viewtype::File, "application/vnd.rar"),
|
||||||
"rtf" => (Viewtype::File, "application/rtf"),
|
"rtf" => (Viewtype::File, "application/rtf"),
|
||||||
"spx" => (Viewtype::File, "audio/ogg"), // Ogg Speex Profile
|
"spx" => (Viewtype::File, "audio/ogg"), // Ogg Speex Profile
|
||||||
@@ -1212,6 +1220,7 @@ pub fn guess_msgtype_from_suffix(path: &Path) -> Option<(Viewtype, &str)> {
|
|||||||
"tiff" => (Viewtype::File, "image/tiff"),
|
"tiff" => (Viewtype::File, "image/tiff"),
|
||||||
"tif" => (Viewtype::File, "image/tiff"),
|
"tif" => (Viewtype::File, "image/tiff"),
|
||||||
"ttf" => (Viewtype::File, "font/ttf"),
|
"ttf" => (Viewtype::File, "font/ttf"),
|
||||||
|
"txt" => (Viewtype::File, "text/plain"),
|
||||||
"vcard" => (Viewtype::File, "text/vcard"),
|
"vcard" => (Viewtype::File, "text/vcard"),
|
||||||
"vcf" => (Viewtype::File, "text/vcard"),
|
"vcf" => (Viewtype::File, "text/vcard"),
|
||||||
"wav" => (Viewtype::File, "audio/wav"),
|
"wav" => (Viewtype::File, "audio/wav"),
|
||||||
@@ -1221,11 +1230,12 @@ pub fn guess_msgtype_from_suffix(path: &Path) -> Option<(Viewtype, &str)> {
|
|||||||
"wmv" => (Viewtype::Video, "video/x-ms-wmv"),
|
"wmv" => (Viewtype::Video, "video/x-ms-wmv"),
|
||||||
"xdc" => (Viewtype::Webxdc, "application/webxdc+zip"),
|
"xdc" => (Viewtype::Webxdc, "application/webxdc+zip"),
|
||||||
"xhtml" => (Viewtype::File, "application/xhtml+xml"),
|
"xhtml" => (Viewtype::File, "application/xhtml+xml"),
|
||||||
|
"xls" => (Viewtype::File, "application/vnd.ms-excel"),
|
||||||
"xlsx" => (
|
"xlsx" => (
|
||||||
Viewtype::File,
|
Viewtype::File,
|
||||||
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
||||||
),
|
),
|
||||||
"xml" => (Viewtype::File, "application/vnd.ms-excel"),
|
"xml" => (Viewtype::File, "application/xml"),
|
||||||
"zip" => (Viewtype::File, "application/zip"),
|
"zip" => (Viewtype::File, "application/zip"),
|
||||||
_ => {
|
_ => {
|
||||||
return None;
|
return None;
|
||||||
|
|||||||
Reference in New Issue
Block a user