mirror of
https://github.com/bulwarkmail/webmail.git
synced 2026-10-31 16:13:15 +00:00
Stalwart 1.0 counts every EmailSubmission record of an account against `maxSubmissions` (500 by default), whatever its status or age, and its own purge of old records never runs. Bulwark never destroyed a submission, so after about 500 JMAP sends an account could not send at all: every send, read receipt and reschedule failed with a raw "There are too many email submissions" error, and each failed attempt left one more copy of the message in Drafts. Bulwark now removes the records that can no longer be cancelled. Destroying a record never stops its delivery, but a pending one could no longer be cancelled, so pending records are never touched: - an immediate send (no hold, no undo window) destroys its own record right after the send, riding along with the old-draft cleanup; only where `urn:stalwart:jmap` is advertised, and never decided by the created `undoStatus`, which 0.16.10-0.16.16 report as final for held sends - a throttled background prune destroys canceled records and final records whose `sendAt` has passed, going by `EmailSubmission/get`, in every submission account; it runs at startup, after sends, after undo and on EmailSubmission state changes - a confirmed cancel (undo, cancel, reschedule) destroys the canceled record in a request of its own - an `overQuota` on a submission create prunes at once, on Stalwart walks the change log for records older than the query's three-day window, retries once, and otherwise throws `SubmissionQuotaError`, shown as a translated explanation in the composer, quick reply, read receipts and the scheduled-send actions Failed sends now clean up after themselves and say so: - a failed send removes the Drafts copy it created and keeps the user's draft; the raw send paths remove their import the same way - a read receipt that did not go out is taken back out of Sent, a method-level error counts as a failure, `$MDNSent` is only set after a sent receipt, and the automatic receipt no longer retries on every refresh of the open message - quick-reply failures, "Send now", "Reschedule" and a failed undo are shown instead of only logged - the scheduled list reads every page of `EmailSubmission/query`; it stopped after the first because `total` needs `calculateTotal`
71 lines
3.1 KiB
TypeScript
71 lines
3.1 KiB
TypeScript
import { describe, it, expect, vi } from 'vitest';
|
|
import { JMAPClient, sendMethodErrors } from '../jmap/client';
|
|
|
|
// JMAP names a failed method call "error" (RFC 8620 §3.6.2); the client used
|
|
// to test for "<Method>/error", which never matches.
|
|
|
|
function clientResponding(methodResponses: unknown[]): JMAPClient {
|
|
const client = new JMAPClient('https://jmap.example.com', 'user@example.com', 'pass');
|
|
Object.assign(client, { apiUrl: 'https://jmap.example.com/api', accountId: 'a1' });
|
|
vi.spyOn(client as unknown as { request: () => Promise<unknown> }, 'request')
|
|
.mockResolvedValue({ methodResponses });
|
|
return client;
|
|
}
|
|
|
|
describe('sendMethodErrors', () => {
|
|
it('reports an error before the submission as a failed send', () => {
|
|
const { failure, filing } = sendMethodErrors([
|
|
['error', { type: 'forbidden', description: 'nope' }, '0'],
|
|
['error', { type: 'invalidResultReference' }, '1'],
|
|
]);
|
|
expect(failure).toEqual({ type: 'forbidden', description: 'nope' });
|
|
expect(filing).toBeUndefined();
|
|
});
|
|
|
|
it('reports an error after a created submission as a filing problem', () => {
|
|
const { failure, filing } = sendMethodErrors([
|
|
['Email/set', { created: { draft: { id: 'e1' } } }, '0'],
|
|
['EmailSubmission/set', { created: { 1: { id: 's1' } } }, '1'],
|
|
['error', { type: 'serverFail' }, '1'],
|
|
]);
|
|
expect(failure).toBeUndefined();
|
|
expect(filing).toEqual({ type: 'serverFail' });
|
|
});
|
|
|
|
it('treats a submission that created nothing as not sent', () => {
|
|
const { failure } = sendMethodErrors([
|
|
['EmailSubmission/set', { created: {}, notCreated: { 1: { type: 'forbiddenFrom' } } }, '1'],
|
|
['error', { type: 'serverFail' }, '1'],
|
|
]);
|
|
expect(failure).toEqual({ type: 'serverFail' });
|
|
});
|
|
});
|
|
|
|
describe('search method errors', () => {
|
|
const unsupported = ['error', { type: 'unsupportedFilter', description: 'Unsupported filter' }, '0'];
|
|
|
|
it('searchEmails throws instead of returning "no results"', async () => {
|
|
const client = clientResponding([unsupported, ['error', { type: 'invalidResultReference' }, '1']]);
|
|
vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
await expect(client.searchEmails('x')).rejects.toThrow('Search failed: Unsupported filter');
|
|
});
|
|
|
|
it('advancedSearchEmails throws on a failed Email/query', async () => {
|
|
const client = clientResponding([unsupported]);
|
|
vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
await expect(client.advancedSearchEmails({ text: 'x' })).rejects.toThrow('Search failed: Unsupported filter');
|
|
});
|
|
});
|
|
|
|
describe('submission method errors', () => {
|
|
it('cancelEmailSubmission reports a failed call instead of a cancel, and destroys nothing', async () => {
|
|
const client = clientResponding([['error', { type: 'serverFail', description: 'Temporary failure' }, '0']]);
|
|
|
|
await expect(client.cancelEmailSubmission('sub-1', 'a1')).rejects.toThrow('Temporary failure');
|
|
|
|
// The mail may still be queued, and its record is the only way to cancel it.
|
|
const request = (client as unknown as { request: ReturnType<typeof vi.fn> }).request;
|
|
expect(request).toHaveBeenCalledTimes(1);
|
|
});
|
|
});
|