mirror of
https://github.com/bulwarkmail/native.git
synced 2026-11-04 16:06:41 +00:00
Files in the app assumed Stalwart 0.16 in several places: - Stalwart 1.0 lists the owner's folders above a node shared with the user, without dates and with every right false. The app took the owner's top folder for the shared root, so the folder actually shared sat several levels down, under folders where rename, delete and move could only fail. Those placeholders are now left out of the root and of folder listings. - A node counted as a folder when it had no blobId, so 1.0's symlinks showed up as empty folders that could be opened. Listings ask for `nodeType` (returned since 0.16.6, never sent in FileNode/set), and a symlink is an inert row with a link icon: it can be renamed, moved and deleted, but not opened, downloaded, duplicated or shared. - Only "/" was checked in names, and uploads were not checked at all, so `<>:"\|?*` already failed on 0.16. New folder and rename now apply the naming rules from the filenode capability plus 1.0's stricter ones (control characters, 255 bytes, reserved stems such as `con.txt`) and say what is wrong. Uploaded names are made acceptable instead: `con.txt` becomes `con_.txt`, also on 0.16.6 to 0.16.23. - One refused file stopped a whole upload. The batch now goes on and reports the files that failed at the end. - Every media type over 30 characters, which is every Office document, was stored as application/octet-stream. New files get the bare lowercase media type 1.0 requires, and no `size`, which 1.0 refuses when it differs from the blob. - File errors keep their JMAP type, and the alerts say why an action failed: too many files or folders (`overQuota`), folders nested too deeply, a refused name, missing rights, or a file too large.
23 lines
1.0 KiB
TypeScript
23 lines
1.0 KiB
TypeScript
/** What Stalwart stores for content without a usable media type. */
|
|
export const OCTET_STREAM = 'application/octet-stream';
|
|
|
|
// RFC 6838 restricted-name: a letter or digit, then at most 126 more from a
|
|
// small set.
|
|
const RESTRICTED_NAME = /^[A-Za-z0-9][A-Za-z0-9!#$&^_.+-]{0,126}$/;
|
|
|
|
/**
|
|
* The essence of a media type: `top/sub` in lowercase, without parameters
|
|
* ("Text/Plain; charset=utf-8" becomes "text/plain"), or
|
|
* application/octet-stream when there is none. Stalwart 1.0 refuses any
|
|
* other FileNode `type` (`is_valid_media_type`, types/src/media_type/mod.rs);
|
|
* 0.16.6+ take anything with a "/" up to 256 characters.
|
|
*/
|
|
export function mediaTypeEssence(value: string | null | undefined): string {
|
|
const essence = (value ?? '').split(';', 1)[0].replace(/^[\t\n\f\r ]+|[\t\n\f\r ]+$/g, '');
|
|
const slash = essence.indexOf('/');
|
|
if (slash < 0) return OCTET_STREAM;
|
|
const top = essence.slice(0, slash);
|
|
const sub = essence.slice(slash + 1);
|
|
return RESTRICTED_NAME.test(top) && RESTRICTED_NAME.test(sub) ? essence.toLowerCase() : OCTET_STREAM;
|
|
}
|