Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion docs/commands.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ mailly domains verify-inbound <domain-id>
mailly inbox addresses list
mailly inbox addresses create --domain <domain> [--prefix <prefix>]
mailly inbox addresses delete <address-id> --yes
mailly inbox threads list [--address-id <id>] [--sender-domain <domain>] [--recipient <email>] [--sender <email>] [--subject <text>] [--match exact|fuzzy] [--query <text>] \
mailly inbox threads list [--address-id <id>] [--unread] [--sender-domain <domain>] [--recipient <email>] [--sender <email>] [--subject <text>] [--match exact|fuzzy] [--query <text>] \
[--since <time>] [--until <time>] \
[--limit N] [--cursor <cursor>]
mailly inbox threads show <thread-id>
Expand Down Expand Up @@ -267,6 +267,8 @@ mailly inbox addresses create \
```bash
mailly inbox addresses list --json
mailly inbox threads list --limit 20 --json
# 只列有未读邮件的会话;第一页同时返回 unread_threads(未读会话总数)
mailly inbox threads list --unread --json
mailly inbox threads show <thread-id> --json
mailly inbox messages list --address-id <address-id> --limit 20 --json
mailly inbox messages show <message-id> --json
Expand Down
2 changes: 2 additions & 0 deletions skills/mailly/reference/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,8 @@ mailly inbox addresses create \
# Thread list and details (GET has no side effects; cursor comes from the previous page)
mailly inbox threads list --limit 20 --json
mailly inbox threads list --address-id <address-id> --cursor '<cursor>' --json
# Only threads with unread mail; the first page also returns unread_threads, the total
mailly inbox threads list --unread --json
mailly inbox threads show <thread-id> --json

# Search by recipient / sender / subject (exact by default, --match fuzzy for substring; --query is fuzzy across fields; bodies are not searched)
Expand Down
8 changes: 6 additions & 2 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -938,7 +938,7 @@ export class MaillyClient {
return this.request<{ success: boolean }>('POST', `/inbox/messages/${encodeURIComponent(messageId)}/release`);
}

listInboxThreads(options: InboxListOptions = {}) {
listInboxThreads(options: InboxListOptions & { unread?: boolean } = {}) {
return this.request<{
success: boolean;
threads: Array<{
Expand All @@ -949,7 +949,11 @@ export class MaillyClient {
latest_message: InboxMessage | null;
}>;
cursor: string | null;
}>('GET', '/inbox/threads', { query: inboxListQuery(options) });
// On the first page (no cursor): threads matching the same filters that have unread mail.
unread_threads?: number;
}>('GET', '/inbox/threads', {
query: { ...inboxListQuery(options), unread: options.unread ? 'true' : undefined },
});
}

getInboxThread(threadId: string, folder?: string) {
Expand Down
4 changes: 3 additions & 1 deletion src/commands/inbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -423,8 +423,9 @@ export function registerInbox(program: Command) {
.option('--limit <n>', 'Number of results', parsePositiveInteger)
.option('--cursor <cursor>', 'Next-page cursor returned by the server')
.option('--folder <folder>', 'inbox / quarantine (default inbox)', parseInboxFolder)
.option('--unread', 'Only threads with unread mail')
.option('--sender-domain <domain>', 'Filter by sender domain (case-insensitive exact domain match, subdomains excluded; indexed)'), INBOX_SEARCH_LABELS)
.action(async (opts: InboxListOptions, command) => {
.action(async (opts: InboxListOptions & { unread?: boolean }, command) => {
const res = await (await clientFor(command)).listInboxThreads(opts);
if (getOutputFormat() === 'json') return printJSON(res);
if (!res.threads.length) return info('No threads');
Expand All @@ -435,6 +436,7 @@ export function registerInbox(program: Command) {
truncate(thread.latest_message?.subject),
thread.thread_id,
]));
if (typeof res.unread_threads === 'number') info(`Threads with unread mail: ${res.unread_threads}`);
if (res.cursor) info(`Next page cursor: ${res.cursor}`);
});

Expand Down
17 changes: 17 additions & 0 deletions tests/inbox-addresses.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -879,3 +879,20 @@ test('reply all, cc and bcc reach reply, forward, send, drafts and agent approva
await runCli(baseUrl, ['agents', 'runs', 'approve', 'run-1', '--text-file', textPath, '--without-cc', '--yes', '--json']);
assert.deepEqual(received.at(-1).body, { text: 'Approved text', cc: [] });
});

test('threads list --unread asks for unread threads and shows the total', async (t) => {
const requests = [];
const baseUrl = await startMockServer(t, (request, response) => {
requests.push(request.url);
response.writeHead(200, { 'Content-Type': 'application/json' });
response.end(JSON.stringify({ success: true, threads: [], cursor: null, unread_threads: 12 }));
});
await runCli(baseUrl, ['inbox', 'threads', 'list', '--unread', '--address-id', 'a1', '--json']);
await runCli(baseUrl, ['inbox', 'threads', 'list', '--json']);
const { stdout, stderr } = await runCli(baseUrl, ['inbox', 'threads', 'list']);
assert.deepEqual(requests.map((url) => {
const parsed = new URL(url, 'http://localhost');
return Object.fromEntries(parsed.searchParams);
}), [{ address_id: 'a1', unread: 'true' }, {}, {}]);
assert.match(stdout + stderr, /No threads/);
});