Group six more clusters out of web/src/lib

Takes the flat module count from 66 to 42, continuing what admin/ and
calendar/ started.

  lib/mailbox/  archiveDate, emptyFolder, folderMove, labelTree,
                mailboxName, mailboxRoute
  lib/sieve/    sieve, sieveApply, sieveFolders
  lib/input/    keyboard, swipe, touch, listSelection, dropUpload
  lib/notify/   notify, webpush, webpushEnable
  lib/sw/       swCache, swFacts, staleBuild
  lib/text/     html, markdown, text, emlName

FOUR THINGS THE FILENAMES GET WRONG, each checked by reading the file
rather than trusting what it is called:

  - appFolder is not a mailbox. It is the `ihasmail` folder in JMAP
    *Files*, where the client keeps signature images and synced settings.
    It stays flat.
  - format holds no formatting of text. It re-exports the date and clock
    formatters, so it belongs with dates/datetime, not with text/.
  - preview is the file viewer deciding what it can show without
    downloading, and source is where to point someone asking for this
    instance's AGPL source. Neither is about text.
  - notify is not Web Push. It is the tab title, the favicon badge and
    the new-mail sound -- in-app notification, which is why it sits with
    webpush rather than under sw/ with the service worker's own concerns.

threadScroll stays flat too: it decides where a conversation opens, which
is view state rather than a gesture, and input/ is honest only if
everything in it interprets something the reader did.

No behavior change. Almost every reference was on the @/ alias; eight
relative imports in files that did not move, or that moved away from a
sibling, needed rewriting by hand.
This commit is contained in:
jcoffey-dev committed 2026-09-15 23:17:50 -07:00
1 parent 5cc31037c1
commit bd6a605d61
95 files changed
+104 -104

No files matched your search

+81
View File
@@ -0,0 +1,81 @@
import type { SieveRule } from "./sieve";
/** A folder as it was before it moved, so rules that name it can be found again. */
export interface FolderRef {
id: string;
/** The path the folder had when the rules were written, e.g. "Work/Invoices". */
path: string;
}
/**
* Whether a rule files mail into this folder.
*
* Rules record the folder both ways: `mailboxId` since the rule editor started
* setting it, and `mailbox` as the path Sieve actually needs. The id is the
* reliable half — it survives a rename — but rules written before it existed,
* or by hand in the Scripts tab, only have the path.
*/
function filesInto(rule: SieveRule, ref: FolderRef): boolean {
return rule.actions.some(
(a) => a.type === "fileinto" && (a.mailboxId === ref.id || a.mailbox.toLowerCase() === ref.path.toLowerCase()),
);
}
/**
* Rewrites the paths of rules filing into folders that have moved or been
* renamed. Returns the rules unchanged, and `changed: 0`, when none match, so
* callers can skip saving.
*/
export function retargetRules(rules: SieveRule[], moves: Array<FolderRef & { newPath: string }>): { rules: SieveRule[]; changed: number } {
const wanted = moves.filter((m) => m.newPath !== m.path);
if (!wanted.length) return { rules, changed: 0 };
let changed = 0;
const next = rules.map((rule) => {
const move = wanted.find((m) => filesInto(rule, m));
if (!move) return rule;
changed++;
return {
...rule,
actions: rule.actions.map((a) =>
a.type === "fileinto" && (a.mailboxId === move.id || a.mailbox.toLowerCase() === move.path.toLowerCase())
? { ...a, mailbox: move.newPath, mailboxId: move.id }
: a,
),
};
});
return changed ? { rules: next, changed } : { rules, changed: 0 };
}
/**
* Takes the deleted folders out of the rules that filed into them.
*
* Only the `fileinto` action goes. A rule that also marks read, flags, or stops
* processing keeps doing those things — deleting a folder says nothing about
* whether the rest of the rule was still wanted. A rule left with no actions at
* all has nothing to do, so that one goes.
*/
export function detachFolders(rules: SieveRule[], gone: FolderRef[]): { rules: SieveRule[]; edited: SieveRule[]; removed: SieveRule[] } {
if (!gone.length) return { rules, edited: [], removed: [] };
const targets = (a: SieveRule["actions"][number]) =>
a.type === "fileinto" && gone.some((ref) => a.mailboxId === ref.id || a.mailbox.toLowerCase() === ref.path.toLowerCase());
const edited: SieveRule[] = [];
const removed: SieveRule[] = [];
const next: SieveRule[] = [];
for (const rule of rules) {
if (!rule.actions.some(targets)) {
next.push(rule);
continue;
}
const actions = rule.actions.filter((a) => !targets(a));
if (!actions.length) {
removed.push(rule);
continue;
}
const trimmed = { ...rule, actions };
edited.push(trimmed);
next.push(trimmed);
}
if (!edited.length && !removed.length) return { rules, edited: [], removed: [] };
return { rules: next, edited, removed };
}