mirror of
https://github.com/bulwarkmail/webmail.git
synced 2026-11-01 08:12:43 +00:00
"Send now" and "Reschedule" create a replacement submission and then
cancel the original. The server checks the recipients again for the
replacement, and a throttle used up since the original was taken ("452
4.4.5 Rate limit exceeded") can refuse some of them. The original was
kept only when every recipient was refused; on a partial refusal it was
cancelled, and a recipient the original had taken lost the message
without anyone being told.
- The original's delivery status is read with its envelope. When the
replacement refuses a recipient the original took, the replacement is
cancelled (its record only destroyed when it took nobody) and the
original goes at its old time. A recipient the original refused as
well loses nothing, so the reschedule goes ahead; checked live on
0.16.23 and 1.0 with a relay-refused recipient.
- The toast for a kept schedule leads with "The message is still
scheduled for ..." and says "Nothing was changed: the server refused
...". It used to open with "Not sent", which invited sending the
message a second time.
- Recipients refused while the others were taken are now named after
"Send now", a reschedule from the list or the viewer, and a quick
reply, which said "Email sent".
Files, from the review of d9ffe8a7:
- An own folder opened from search while Files showed a shared folder
opened the shared folder again: its link had no query, and the page
read `?shared=` from the address bar. The link now says it has none.
- The Pro shell kept only the path of a Files link across its redirect,
so a shared folder's link (`/files?shared=...`) didn't survive a
reload, and neither did `?preview=`. The query goes along now.
- A search hit for a file on a "Files from" page opened the first file
of that name there; it is found by the id the link names now.
- Undoing a paste of files cut on a "Files from" page moved them to
"*", the page's id; they go back to their own folders now.
117 lines
5.5 KiB
TypeScript
117 lines
5.5 KiB
TypeScript
import { NoLongerScheduledError, RecipientsRefusedError, RequestTimeoutError, ScheduleTooLateError, SubmissionQuotaError } from '@/lib/jmap/client';
|
|
import type { RefusedRecipient } from '@/lib/jmap/types';
|
|
|
|
type Translate = (key: string, values?: Record<string, string>) => string;
|
|
|
|
/** "nobody@example.net (550 5.1.2 Relay not allowed.)", one per refused recipient. */
|
|
export function formatRefusedRecipients(recipients: RefusedRecipient[]): string {
|
|
return recipients.map((r) => (r.smtpReply ? `${r.email} (${r.smtpReply})` : r.email)).join(', ');
|
|
}
|
|
|
|
/**
|
|
* Thrown by "Undo send" and "Cancel and edit" when the cancel went through
|
|
* but a step after it failed: putting the message back in Drafts
|
|
* (`restore`), or removing the copy of an S/MIME message, which is composed
|
|
* again from scratch (`remove`). Nothing goes out; the message is still in
|
|
* Sent. Reported apart from a failed cancel, which may still let it go.
|
|
*/
|
|
export class SendCancelledCleanupError extends Error {
|
|
constructor(readonly step: 'restore' | 'remove', readonly reason: unknown) {
|
|
super(step === 'restore'
|
|
? 'Sending was cancelled, but the message could not be put back in Drafts'
|
|
: 'Sending was cancelled, but the unsent message could not be removed from Sent');
|
|
this.name = 'SendCancelledCleanupError';
|
|
}
|
|
}
|
|
|
|
/**
|
|
* What to tell the user about a send (or reschedule) that failed, from the
|
|
* `email_composer` messages. Most errors carry the server's own description;
|
|
* these are the ones it would misrepresent or leave unexplained:
|
|
* - a full submission quota on Stalwart: it asks the user to "delete some",
|
|
* but the client has already removed every record it may, so only an
|
|
* administrator can help. Another server's overQuota may stand for any
|
|
* sending limit, so its own description goes with a generic sentence;
|
|
* - a timeout, which is not a clean failure: the submission may have reached
|
|
* the server and gone out, with only the answer lost. Saying "send failed"
|
|
* would invite a re-send and a duplicate, so point at Sent instead (#702);
|
|
* - a hold beyond the server's limit;
|
|
* - every recipient refused: the server took the submission, so nothing
|
|
* else would say that the message went nowhere. Its reply per address
|
|
* goes with it.
|
|
*/
|
|
export function sendFailureMessage(error: unknown, t: Translate): string {
|
|
if (error instanceof SubmissionQuotaError) {
|
|
return error.countsRecords
|
|
? t('submission_quota')
|
|
: t('submission_limit', { reason: error.description || error.jmapType });
|
|
}
|
|
if (error instanceof RequestTimeoutError) return t('send_timeout');
|
|
if (error instanceof ScheduleTooLateError) return t('schedule_send_too_late');
|
|
if (error instanceof RecipientsRefusedError) {
|
|
return t('recipients_refused', { recipients: formatRefusedRecipients(error.recipients) });
|
|
}
|
|
return error instanceof Error && error.message ? error.message : t('send_failed');
|
|
}
|
|
|
|
/**
|
|
* The toast for a failed "Send now" or "Reschedule", from the `email_viewer`
|
|
* (`tViewer`) and `email_composer` (`tComposer`) messages. At a full
|
|
* submission quota no replacement was made, so the message still goes out at
|
|
* its old time, `scheduledAt` (formatted) when known. Making room takes a
|
|
* while, and the original may have gone out meanwhile. When the server
|
|
* refused recipients of the replacement that the original had taken, the
|
|
* original was kept too, for all of its recipients - a headline saying the
|
|
* mail wasn't sent would invite sending it a second time.
|
|
*/
|
|
export function rescheduleFailureToast(
|
|
error: unknown,
|
|
tViewer: Translate,
|
|
tComposer: Translate,
|
|
scheduledAt?: string,
|
|
): { title: string; message?: string } {
|
|
if (error instanceof NoLongerScheduledError) {
|
|
return { title: tViewer(error.sent ? 'already_sent' : 'no_longer_scheduled') };
|
|
}
|
|
const stillScheduled = scheduledAt ? tViewer('still_scheduled_at', { date: scheduledAt }) : tViewer('still_scheduled');
|
|
if (error instanceof SubmissionQuotaError) {
|
|
return { title: stillScheduled, message: sendFailureMessage(error, tComposer) };
|
|
}
|
|
if (error instanceof RecipientsRefusedError) {
|
|
return {
|
|
title: stillScheduled,
|
|
message: tViewer('reschedule_recipients_refused', { recipients: formatRefusedRecipients(error.recipients) }),
|
|
};
|
|
}
|
|
return { title: sendFailureMessage(error, tComposer) };
|
|
}
|
|
|
|
/**
|
|
* The warning after a send, "Send now" or reschedule that the server took for
|
|
* some recipients only (`refusedRecipients`), from the `email_composer`
|
|
* messages; null when it took them all. Nothing else, not even a bounce,
|
|
* tells the user who never gets the message.
|
|
*/
|
|
export function partlyRefusedWarning(result: { refusedRecipients?: RefusedRecipient[] }, tComposer: Translate): string | null {
|
|
return result.refusedRecipients?.length
|
|
? tComposer('recipients_partly_refused', { recipients: formatRefusedRecipients(result.refusedRecipients) })
|
|
: null;
|
|
}
|
|
|
|
/**
|
|
* The toast for a failed "Undo send" or "Cancel and edit". A failed cancel
|
|
* may still let the mail go, so it must never read as done: it gets
|
|
* `cancelFailedTitle` and the reason. One that went through while a step
|
|
* after it failed says where the message is instead.
|
|
*/
|
|
export function cancelFailureToast(
|
|
error: unknown,
|
|
tViewer: Translate,
|
|
cancelFailedTitle: string,
|
|
): { title: string; message?: string } {
|
|
if (error instanceof SendCancelledCleanupError) {
|
|
return { title: tViewer(error.step === 'restore' ? 'send_cancelled_restore_failed' : 'send_cancelled_remove_failed') };
|
|
}
|
|
return { title: cancelFailedTitle, message: error instanceof Error ? error.message : undefined };
|
|
}
|