The rule editor gets a stop-after-match checkbox in place of the stop action, and each rule a Run now button that confirms what it will do and reports how many messages matched. Disabled rules dim their description only, since Run now still works on them. Trash rows show when they'll be deleted permanently. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
ab854593a3
commit
9550c6ac73
5 files changed
+66
-11
No files matched your search
@@ -15,7 +15,8 @@ Desktop webapp client for [Tern](../) — see [`docs/webapp-client-spec.md`](doc
|
||||
- Opening a conversation marks it read.
|
||||
- **Views, folders and tags** in the sidebar (Inbox, All mail, Sent, Outbox, Trash, your folders, your tags), with tag chips on list rows.
|
||||
- **Conversation actions** — archive, delete/restore, mark read/unread, move, tag — from a toolbar, a right-click context menu (native Popover API, §5), or the keyboard. Keyboard actions apply to the row under the cursor when nothing is open, so mail can be triaged straight from the list.
|
||||
- **Rules editor** — conditions and actions edited as the structured JSON they're stored as, so anything the API accepts the editor can show. Server validation errors (e.g. a bad regex) appear inline without losing the form.
|
||||
- **Rules editor** — conditions and actions edited as the structured JSON they're stored as, so anything the API accepts the editor can show. Each rule can stop later rules when it matches, and **Run now** applies it to existing mail. Server validation errors (e.g. a bad regex) appear inline without losing the form.
|
||||
- **Trash** shows when each conversation will be permanently deleted.
|
||||
- **Keyboard shortcuts** (§4a): `j`/`k`, `Enter`/`o`, `u`/`Esc`, `g`/`G`, `e` archive, `#` delete/restore, `Shift+I`/`Shift+U` read/unread, `v`/`l` move/tag, `c`, `r`/`a`, `Shift+R`, `?`.
|
||||
- Polls `/events` while the tab is open, since WebSocket push is phase 7.
|
||||
- No PWA, no service worker, no offline cache — matches §2's explicit scope cut.
|
||||
@@ -33,7 +34,7 @@ Verified against a message containing a tracking pixel, a remote hero image, a C
|
||||
|
||||
Note the quotes in `img-src 'none'` are load-bearing — unquoted, CSP parses `none` as a *hostname*, which would let `https://none/pixel.gif` through.
|
||||
|
||||
**Not built yet** (later phases): search, attachment download, WebSocket live updates, running a rule over existing mail. Composing is plain text only.
|
||||
**Not built yet** (later phases): search, attachment download, WebSocket live updates. Composing is plain text only.
|
||||
|
||||
## Running
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
onCancel: () => void;
|
||||
} = $props();
|
||||
|
||||
type ActionType = 'tag' | 'move' | 'archive' | 'mark_read' | 'delete' | 'stop';
|
||||
type ActionType = 'tag' | 'move' | 'archive' | 'mark_read' | 'delete';
|
||||
|
||||
const fields: [RuleField, string][] = [
|
||||
['from', 'From'],
|
||||
@@ -44,7 +44,6 @@
|
||||
['archive', 'Archive'],
|
||||
['mark_read', 'Mark read'],
|
||||
['delete', 'Move to Trash'],
|
||||
['stop', 'Stop processing more rules'],
|
||||
];
|
||||
|
||||
// The form deliberately snapshots the rule it opened with — edits are
|
||||
@@ -54,6 +53,7 @@
|
||||
let name = $state(initial.name);
|
||||
let match = $state<'all' | 'any'>(initial.match);
|
||||
let enabled = $state(initial.enabled);
|
||||
let stopAfterMatch = $state(initial.stopAfterMatch);
|
||||
let tests = $state<RuleTest[]>(initial.tests);
|
||||
let actions = $state<{ type: ActionType; target: string }[]>(initial.actions);
|
||||
|
||||
@@ -62,6 +62,7 @@
|
||||
name: rule?.name ?? '',
|
||||
match: rule?.conditions.match ?? ('all' as const),
|
||||
enabled: rule?.enabled ?? true,
|
||||
stopAfterMatch: rule?.stop_after_match ?? false,
|
||||
tests: rule ? rule.conditions.tests.map((t) => ({ ...t, header: t.header ?? '' })) : [blankTest()],
|
||||
actions: rule ? rule.actions.map(toRow) : [{ type: 'tag' as ActionType, target: tags[0]?.id ?? '' }],
|
||||
};
|
||||
@@ -102,6 +103,7 @@
|
||||
await onSave({
|
||||
name,
|
||||
enabled,
|
||||
stop_after_match: stopAfterMatch,
|
||||
conditions: {
|
||||
match,
|
||||
tests: tests.map((t) => ({
|
||||
@@ -183,7 +185,10 @@
|
||||
<button type="button" class="add" onclick={() => actions.push({ type: 'archive', target: '' })}>+ Action</button>
|
||||
</fieldset>
|
||||
|
||||
<label class="enabled"><input type="checkbox" bind:checked={enabled} /> Enabled</label>
|
||||
<label class="enabled"><input type="checkbox" bind:checked={enabled} /> Enabled for new mail</label>
|
||||
<label class="enabled">
|
||||
<input type="checkbox" bind:checked={stopAfterMatch} /> Stop — don't run rules below this one when it matches
|
||||
</label>
|
||||
<p class="hint">Rules run on new mail as it arrives, in the order listed. Delete moves mail to Trash, where it can be restored.</p>
|
||||
|
||||
{#if error}<p class="error">{error}</p>{/if}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
deleteRule,
|
||||
listRules,
|
||||
reorderRules,
|
||||
runRule,
|
||||
updateRule,
|
||||
type Action,
|
||||
type Folder,
|
||||
@@ -19,6 +20,9 @@
|
||||
let rules = $state<Rule[]>([]);
|
||||
let editing = $state<Rule | 'new' | null>(null);
|
||||
let error = $state<string | null>(null);
|
||||
/** Per-rule outcome of the last Run now, shown under that rule. */
|
||||
let runResult = $state<Record<string, string>>({});
|
||||
let running = $state<string | null>(null);
|
||||
|
||||
onMount(load);
|
||||
|
||||
@@ -37,6 +41,20 @@
|
||||
await load();
|
||||
}
|
||||
|
||||
async function runNow(rule: Rule) {
|
||||
const what = describeActions(rule.actions);
|
||||
if (!confirm(`Run "${rule.name}" on your existing mail now?\n\nEvery matching message outside Trash will: ${what}.`)) return;
|
||||
running = rule.id;
|
||||
try {
|
||||
const r = await runRule(rule.id);
|
||||
runResult[rule.id] = `Matched ${r.matched} of ${r.scanned} messages.`;
|
||||
} catch (e) {
|
||||
runResult[rule.id] = e instanceof Error ? e.message : 'failed';
|
||||
} finally {
|
||||
running = null;
|
||||
}
|
||||
}
|
||||
|
||||
async function toggle(rule: Rule) {
|
||||
await updateRule(rule.id, { ...rule, enabled: !rule.enabled });
|
||||
await load();
|
||||
@@ -71,7 +89,6 @@
|
||||
case 'archive': return 'archive';
|
||||
case 'mark_read': return 'mark read';
|
||||
case 'delete': return 'move to Trash';
|
||||
case 'stop': return 'stop';
|
||||
default: return a.type;
|
||||
}
|
||||
})
|
||||
@@ -105,7 +122,7 @@
|
||||
<button class="primary" onclick={() => (editing = 'new')}>New rule</button>
|
||||
</header>
|
||||
<p class="hint">
|
||||
Applied to new mail in this order. Every matching rule runs until one that says stop.
|
||||
Applied to new mail in this order; every matching rule runs unless one above it is set to stop. Run now applies a single rule to mail you already have — disabled rules included, so you can try one before switching it on.
|
||||
</p>
|
||||
{#if error}<p class="error">{error}</p>{/if}
|
||||
{#if rules.length === 0}
|
||||
@@ -120,9 +137,15 @@
|
||||
</div>
|
||||
<div class="body">
|
||||
<strong>{rule.name}</strong>
|
||||
<span class="summary">If {describeTests(rule)} → {describeActions(rule.actions)}</span>
|
||||
<span class="summary">
|
||||
If {describeTests(rule)} → {describeActions(rule.actions)}{rule.stop_after_match ? ', then stop' : ''}
|
||||
</span>
|
||||
{#if runResult[rule.id]}<span class="result">{runResult[rule.id]}</span>{/if}
|
||||
</div>
|
||||
<label class="toggle"><input type="checkbox" checked={rule.enabled} onchange={() => toggle(rule)} /> on</label>
|
||||
<button onclick={() => runNow(rule)} disabled={running !== null} title="Apply to existing mail">
|
||||
{running === rule.id ? 'Running…' : 'Run now'}
|
||||
</button>
|
||||
<button onclick={() => (editing = rule)}>Edit</button>
|
||||
<button onclick={() => remove(rule)}>Delete</button>
|
||||
</li>
|
||||
@@ -172,7 +195,9 @@
|
||||
border: 1px solid var(--secondary);
|
||||
border-radius: 0.45rem;
|
||||
}
|
||||
li.disabled {
|
||||
/* Dim the description only: Run now still works on a disabled rule, so
|
||||
its buttons mustn't look disabled too. */
|
||||
li.disabled .body {
|
||||
opacity: 0.55;
|
||||
}
|
||||
.order {
|
||||
@@ -196,6 +221,10 @@
|
||||
font-size: 0.8rem;
|
||||
color: var(--primary);
|
||||
}
|
||||
.result {
|
||||
font-size: 0.78rem;
|
||||
color: var(--accent);
|
||||
}
|
||||
.toggle {
|
||||
font-size: 0.8rem;
|
||||
display: flex;
|
||||
|
||||
@@ -21,6 +21,11 @@
|
||||
|
||||
const tagById = $derived(new Map(tags.map((t) => [t.id, t])));
|
||||
|
||||
function purgeText(at: string): string {
|
||||
const days = Math.ceil((new Date(at).getTime() - Date.now()) / 86_400_000);
|
||||
return days <= 0 ? 'Deleted permanently soon' : `Deleted permanently in ${days} day${days === 1 ? '' : 's'}`;
|
||||
}
|
||||
|
||||
let listEl = $state<HTMLElement | null>(null);
|
||||
|
||||
// Keep the keyboard cursor visible when j/k walks past the viewport edge.
|
||||
@@ -59,6 +64,9 @@
|
||||
<span class="attach" aria-label="Has attachments">📎</span>
|
||||
{/if}
|
||||
</span>
|
||||
{#if thread.purges_at}
|
||||
<span class="purge">{purgeText(thread.purges_at)}</span>
|
||||
{/if}
|
||||
{#if thread.tag_ids.length > 0}
|
||||
<span class="chips">
|
||||
{#each thread.tag_ids as id (id)}
|
||||
@@ -148,6 +156,10 @@
|
||||
.attach {
|
||||
font-size: 0.75rem;
|
||||
}
|
||||
.purge {
|
||||
font-size: 0.72rem;
|
||||
color: var(--accent);
|
||||
}
|
||||
.chips {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
|
||||
+10
-2
@@ -75,6 +75,8 @@ export interface ThreadSummary {
|
||||
unread_count: number;
|
||||
has_attachments: boolean;
|
||||
tag_ids: string[];
|
||||
/** In Trash: when this conversation is deleted for good. */
|
||||
purges_at: string | null;
|
||||
}
|
||||
|
||||
/** Flags are stored in IMAP wire format, so unread is the absence of \Seen. */
|
||||
@@ -212,8 +214,7 @@ export type Action =
|
||||
| { type: 'mark_read' }
|
||||
| { type: 'mark_unread' }
|
||||
| { type: 'delete' }
|
||||
| { type: 'restore' }
|
||||
| { type: 'stop' };
|
||||
| { type: 'restore' };
|
||||
|
||||
export type RuleField = 'from' | 'to' | 'cc' | 'recipients' | 'subject' | 'body' | 'header';
|
||||
export type RuleOp = 'contains' | 'equals' | 'matches' | 'exists' | 'greater_than' | 'less_than';
|
||||
@@ -232,6 +233,8 @@ export interface Rule {
|
||||
conditions: { match: 'all' | 'any'; tests: RuleTest[] };
|
||||
actions: Action[];
|
||||
enabled: boolean;
|
||||
/** Skip lower-priority rules once this one matches. */
|
||||
stop_after_match: boolean;
|
||||
priority: number;
|
||||
}
|
||||
|
||||
@@ -277,6 +280,11 @@ export function deleteRule(id: string): Promise<{ ok: boolean }> {
|
||||
return request(`/rules/${id}`, { method: 'DELETE' });
|
||||
}
|
||||
|
||||
/** Applies a rule to existing mail — what "Run now" does. */
|
||||
export function runRule(id: string): Promise<{ scanned: number; matched: number }> {
|
||||
return request(`/rules/${id}/run`, { method: 'POST' });
|
||||
}
|
||||
|
||||
export function reorderRules(ids: string[]): Promise<Rule[]> {
|
||||
return request('/rules/reorder', { method: 'POST', body: JSON.stringify({ ids }) });
|
||||
}
|
||||
Reference in new issue
Block a user