mirror of
https://github.com/bulwarkmail/native.git
synced 2026-11-03 16:07:32 +00:00
fix: subscribe folders created on the phone so IMAP clients show them #951
This commit is contained in:
@@ -0,0 +1,46 @@
|
|||||||
|
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||||
|
|
||||||
|
vi.mock('../jmap-client', () => ({
|
||||||
|
jmapClient: {
|
||||||
|
accountId: 'acc-1',
|
||||||
|
request: vi.fn(),
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
|
||||||
|
import { jmapClient } from '../jmap-client';
|
||||||
|
import { createMailbox } from '../email';
|
||||||
|
|
||||||
|
const mockRequest = jmapClient.request as ReturnType<typeof vi.fn>;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
vi.clearAllMocks();
|
||||||
|
mockRequest.mockResolvedValue({
|
||||||
|
methodResponses: [['Mailbox/set', { created: { 'new-mailbox': { id: 'mb-new' } } }, '0']],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('createMailbox', () => {
|
||||||
|
it('subscribes the new folder so IMAP clients list it (#951)', async () => {
|
||||||
|
const id = await createMailbox({ name: 'Projects' });
|
||||||
|
|
||||||
|
expect(id).toBe('mb-new');
|
||||||
|
const [[call]] = mockRequest.mock.calls[0];
|
||||||
|
expect(call[0]).toBe('Mailbox/set');
|
||||||
|
expect(call[1]).toEqual({
|
||||||
|
accountId: 'acc-1',
|
||||||
|
create: { 'new-mailbox': { name: 'Projects', parentId: null, isSubscribed: true } },
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('subscribes subfolders created in another account', async () => {
|
||||||
|
await createMailbox({ name: 'Child', parentId: 'parent-id' }, 'shared-account');
|
||||||
|
|
||||||
|
const [[call]] = mockRequest.mock.calls[0];
|
||||||
|
expect(call[1].accountId).toBe('shared-account');
|
||||||
|
expect(call[1].create['new-mailbox']).toEqual({
|
||||||
|
name: 'Child',
|
||||||
|
parentId: 'parent-id',
|
||||||
|
isSubscribed: true,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -215,9 +215,13 @@ export async function createMailbox(
|
|||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
const accountId = accountIdOverride ?? jmapClient.accountId;
|
const accountId = accountIdOverride ?? jmapClient.accountId;
|
||||||
const cid = 'new-mailbox';
|
const cid = 'new-mailbox';
|
||||||
|
// Subscribe explicitly: IMAP clients that list folders via LSUB
|
||||||
|
// (Thunderbird) hide unsubscribed mailboxes, and the server default is
|
||||||
|
// not guaranteed to be true. (#951)
|
||||||
const create: Record<string, unknown> = {
|
const create: Record<string, unknown> = {
|
||||||
name: data.name,
|
name: data.name,
|
||||||
parentId: data.parentId ?? null,
|
parentId: data.parentId ?? null,
|
||||||
|
isSubscribed: true,
|
||||||
};
|
};
|
||||||
if (data.role !== undefined) create.role = data.role;
|
if (data.role !== undefined) create.role = data.role;
|
||||||
const res = await jmapClient.request([
|
const res = await jmapClient.request([
|
||||||
|
|||||||
Reference in New Issue
Block a user