domma-cms 1.28.4 → 1.29.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. package/CHANGELOG.md +5 -0
  2. package/admin/js/lib/contacts-arrange.js +1 -1
  3. package/docs/DommaFeatures.md +5 -3
  4. package/package.json +4 -1
  5. package/plugins/_lib/admin/mail/body-menu.js +2 -0
  6. package/plugins/_lib/admin/mail/cms-host.js +22 -0
  7. package/plugins/_lib/admin/mail/compose-window.js +1027 -1021
  8. package/plugins/_lib/admin/mail/contacts.js +10 -8
  9. package/plugins/_lib/admin/mail/diagnostics-section.js +2 -0
  10. package/plugins/_lib/admin/mail/drag-drop.js +46 -0
  11. package/plugins/_lib/admin/mail/folder-tree.js +2 -0
  12. package/plugins/_lib/admin/mail/font-controls.js +6 -4
  13. package/plugins/_lib/admin/mail/fonts.js +1 -1
  14. package/plugins/_lib/admin/mail/host-context.js +87 -0
  15. package/plugins/_lib/admin/mail/identity.js +2 -0
  16. package/plugins/_lib/admin/mail/image-senders-section.js +2 -0
  17. package/plugins/_lib/admin/mail/keyboard.js +2 -0
  18. package/plugins/_lib/admin/mail/mail.css +1 -1
  19. package/plugins/_lib/admin/mail/mail.html +4 -0
  20. package/plugins/_lib/admin/mail/message-actions.js +2 -0
  21. package/plugins/_lib/admin/mail/oauth-panel.js +2 -0
  22. package/plugins/_lib/admin/mail/panes.js +2 -0
  23. package/plugins/_lib/admin/mail/reader-kit.js +2 -0
  24. package/plugins/_lib/admin/mail/reader-runtime.js +6534 -0
  25. package/plugins/_lib/admin/mail/reader-view.js +9 -6380
  26. package/plugins/_lib/admin/mail/resizable.js +2 -0
  27. package/plugins/_lib/admin/mail/restore-spam.js +13 -0
  28. package/plugins/_lib/admin/mail/rules.js +14 -0
  29. package/plugins/_lib/admin/mail/scheduling.js +4 -1
  30. package/plugins/_lib/admin/mail/section-kit.js +4 -1
  31. package/plugins/_lib/admin/mail/security-note.js +2 -0
  32. package/plugins/_lib/admin/mail/settings-section.js +11 -10
  33. package/plugins/_lib/admin/mail/templates.js +5 -2
  34. package/plugins/_lib/admin/mail/threads.js +2 -0
  35. package/plugins/_lib/admin/mail/vacation.js +16 -2
  36. package/plugins/_lib/admin/mail/when-closed.js +24 -2
  37. package/plugins/_lib/admin/ui/dates.js +2 -0
  38. package/plugins/_lib/admin/ui/resizable.js +7 -5
  39. package/plugins/_lib/contacts/mailContact.js +69 -0
  40. package/plugins/_lib/contacts/model.js +199 -0
  41. package/plugins/_lib/domma-mail-contacts.lock.json +10 -0
  42. package/plugins/_lib/domma-mail.lock.json +85 -0
  43. package/plugins/_lib/mail/accountFileStore.js +66 -0
  44. package/plugins/_lib/mail/accountRepository.js +617 -0
  45. package/plugins/_lib/mail/accountRoutes.js +130 -0
  46. package/plugins/_lib/mail/accounts.js +66 -940
  47. package/plugins/_lib/mail/automationLock.js +10 -0
  48. package/plugins/_lib/mail/bodyTokenProvider.js +36 -0
  49. package/plugins/_lib/mail/bodyTokens.js +5 -99
  50. package/plugins/_lib/mail/compose.js +5 -3
  51. package/plugins/_lib/mail/defaults.js +2 -0
  52. package/plugins/_lib/mail/envelope.js +3 -1
  53. package/plugins/_lib/mail/folderActions.js +83 -0
  54. package/plugins/_lib/mail/folderRuntime.js +109 -0
  55. package/plugins/_lib/mail/folders.js +4 -9
  56. package/plugins/_lib/mail/imapPool.js +11 -389
  57. package/plugins/_lib/mail/imapPoolRuntime.js +396 -0
  58. package/plugins/_lib/mail/mbox.js +2 -0
  59. package/plugins/_lib/mail/message-action.js +2 -0
  60. package/plugins/_lib/mail/messageSecurity.js +4 -111
  61. package/plugins/_lib/mail/messageSecurityProvider.js +116 -0
  62. package/plugins/_lib/mail/networkAddresses.js +77 -0
  63. package/plugins/_lib/mail/networkPolicy.js +62 -0
  64. package/plugins/_lib/mail/oauth.js +3 -451
  65. package/plugins/_lib/mail/oauthAccounts.js +178 -0
  66. package/plugins/_lib/mail/oauthRouteRuntime.js +282 -0
  67. package/plugins/_lib/mail/oauthRoutes.js +7 -289
  68. package/plugins/_lib/mail/oauthRuntime.js +456 -0
  69. package/plugins/_lib/mail/pollSchedule.js +2 -0
  70. package/plugins/_lib/mail/poller.js +4 -136
  71. package/plugins/_lib/mail/pollerRuntime.js +150 -0
  72. package/plugins/_lib/mail/priority.js +2 -0
  73. package/plugins/_lib/mail/publicMailbox.js +27 -0
  74. package/plugins/_lib/mail/readRoutes.js +14 -827
  75. package/plugins/_lib/mail/readRuntime.js +701 -0
  76. package/plugins/_lib/mail/render.js +2 -0
  77. package/plugins/_lib/mail/ruleRunner.js +27 -10
  78. package/plugins/_lib/mail/scheduler.js +11 -279
  79. package/plugins/_lib/mail/schedulerRuntime.js +259 -0
  80. package/plugins/_lib/mail/secretProvider.js +112 -0
  81. package/plugins/_lib/mail/secretbox.js +12 -225
  82. package/plugins/_lib/mail/send.js +21 -537
  83. package/plugins/_lib/mail/sieve.js +211 -0
  84. package/plugins/_lib/mail/sieveHost.js +24 -0
  85. package/plugins/_lib/mail/smtpService.js +553 -0
  86. package/plugins/_lib/mail/snoozeRuntime.js +60 -0
  87. package/plugins/_lib/mail/store.js +122 -64
  88. package/plugins/_lib/mail/subscriptions.js +11 -0
  89. package/plugins/_lib/mail/sync.js +64 -290
  90. package/plugins/_lib/mail/syncPlan.js +2 -0
  91. package/plugins/_lib/mail/syncRuntime.js +255 -0
  92. package/plugins/_lib/mail/syncSelection.js +2 -0
  93. package/plugins/_lib/mail/unreadBadge.js +2 -0
  94. package/plugins/_lib/mail/unsubscribe.js +2 -0
  95. package/plugins/_lib/mail/vacationRunner.js +3 -116
  96. package/plugins/_lib/mail/vacationRuntime.js +70 -0
  97. package/plugins/_lib/mail/write.js +44 -13
  98. package/server/routes/api/contacts.js +2 -196
@@ -0,0 +1,150 @@
1
+ // Source: @domma-mail/core 0.18.0, packages/core/src/mail/pollerRuntime.js.
2
+ // Update with domma-mail/scripts/sync-cms.mjs; edit the shared source.
3
+ /**
4
+ * The background poller.
5
+ *
6
+ * One ticker for the whole plugin rather than a timer per mailbox: mailboxes
7
+ * come and go while the process runs, and a per-mailbox timer means tracking
8
+ * and cancelling each one. A single tick asks `selectDuePolls()` who is due
9
+ * and works through them.
10
+ *
11
+ * The scheduling decision - including the backoff that stops a dead mail
12
+ * server being knocked every few minutes for a week - lives in
13
+ * `pollSchedule.js`, pure and tested there.
14
+ *
15
+ * @module _lib/mail/poller
16
+ */
17
+ import {selectDuePolls} from './pollSchedule.js';
18
+ import {describeError} from './imapPoolRuntime.js';
19
+
20
+ /** How often the ticker looks for work. Finer than any poll interval. */
21
+ const TICK_MS = 30_000;
22
+
23
+ /**
24
+ * Create a poller.
25
+ *
26
+ * @param {{listAccounts: Function, syncAccount: Function, defaultMinutes: number,
27
+ * logger: object, tickMs?: number}} deps
28
+ * @returns {{start: Function, stop: Function, state: Function, pollNow: Function}}
29
+ */
30
+ export function createPoller({listAccounts, syncAccount, defaultMinutes, logger, tickMs = TICK_MS}) {
31
+ /** @type {Map<string, {lastAttemptAt?: number, failures?: number, running?: boolean, lastError?: string|null}>} */
32
+ const state = new Map();
33
+ let timer = null;
34
+ let stopped = false;
35
+ let active = null;
36
+
37
+ /**
38
+ * Sync one mailbox, recording whether it worked.
39
+ *
40
+ * @param {object} account
41
+ * @returns {Promise<void>}
42
+ */
43
+ async function runOne(account) {
44
+ const entry = state.get(account.id) ?? {};
45
+ state.set(account.id, {...entry, running: true, lastAttemptAt: Date.now()});
46
+
47
+ try {
48
+ const result = await syncAccount(account);
49
+ state.set(account.id, {
50
+ lastAttemptAt: Date.now(), failures: 0, running: false, lastError: null,
51
+ lastResult: result
52
+ });
53
+ } catch (err) {
54
+ const failures = (entry.failures ?? 0) + 1;
55
+ state.set(account.id, {
56
+ lastAttemptAt: Date.now(), failures, running: false, lastError: describeError(err)
57
+ });
58
+ // Warn, not error: a mail server being unreachable is an ordinary
59
+ // condition, and the backoff already handles it.
60
+ logger.warn(
61
+ `[mail] poll failed for mailbox ${account.id} (${failures} in a row): ${err.message}`
62
+ );
63
+ }
64
+ }
65
+
66
+ /**
67
+ * One pass: find who is due and sync them, one at a time.
68
+ *
69
+ * Sequential on purpose. Polling every mailbox at once means opening every
70
+ * connection at once, which is exactly the burst a mail server throttles.
71
+ *
72
+ * @returns {Promise<void>}
73
+ */
74
+ async function pass() {
75
+ if (stopped) return;
76
+
77
+ let accounts;
78
+ try {
79
+ accounts = await listAccounts();
80
+ } catch (err) {
81
+ logger.warn(`[mail] could not list mailboxes to poll: ${err.message}`);
82
+ return;
83
+ }
84
+
85
+ // Forget state for mailboxes that have been removed, so the map does
86
+ // not grow for the life of the process.
87
+ if (stopped) return;
88
+ const live = new Set(accounts.map(a => a.id));
89
+ for (const id of [...state.keys()]) {
90
+ if (!live.has(id)) state.delete(id);
91
+ }
92
+
93
+ const due = selectDuePolls(accounts, state, {now: Date.now(), defaultMinutes});
94
+ for (const {id} of due) {
95
+ if (stopped) return;
96
+ const account = accounts.find(a => a.id === id);
97
+ if (account) await runOne(account);
98
+ }
99
+ }
100
+
101
+ function tick() {
102
+ if (stopped) return Promise.resolve();
103
+ // A timer and a manual pass share the same promise, including the
104
+ // account-listing phase before per-account running flags exist.
105
+ if (active) return active;
106
+ active = pass().finally(() => { active = null; });
107
+ return active;
108
+ }
109
+
110
+ return {
111
+ /**
112
+ * @returns {void}
113
+ */
114
+ start() {
115
+ if (timer) return;
116
+ stopped = false;
117
+ timer = setInterval(() => {
118
+ tick().catch(err => logger.warn(`[mail] poll tick failed: ${err.message}`));
119
+ }, tickMs);
120
+ // Never hold the process open for a poll.
121
+ timer.unref?.();
122
+ },
123
+
124
+ /**
125
+ * @returns {Promise<void>} resolves once the active pass has drained
126
+ */
127
+ stop() {
128
+ stopped = true;
129
+ if (timer) clearInterval(timer);
130
+ timer = null;
131
+ return active ?? Promise.resolve();
132
+ },
133
+
134
+ /**
135
+ * Run a pass immediately, for a manual "sync now".
136
+ *
137
+ * @returns {Promise<void>}
138
+ */
139
+ pollNow: tick,
140
+
141
+ /**
142
+ * What the poller currently believes about each mailbox.
143
+ *
144
+ * @returns {object}
145
+ */
146
+ state() {
147
+ return Object.fromEntries(state);
148
+ }
149
+ };
150
+ }
@@ -1,3 +1,5 @@
1
+ // Source: @domma-mail/core 0.18.0, packages/core/src/mail/priority.js.
2
+ // Update with domma-mail/scripts/sync-cms.mjs; edit the shared source.
1
3
  /**
2
4
  * How urgent a sender said a message was.
3
5
  *
@@ -0,0 +1,27 @@
1
+ // Source: @domma-mail/core 0.18.0, packages/core/src/mail/publicMailbox.js.
2
+ // Update with domma-mail/scripts/sync-cms.mjs; edit the shared source.
3
+ /** Standalone mailbox summary. Explicit fields keep credentials out of responses. */
4
+ export function publicMailbox(account) {
5
+ if (!account) return null;
6
+ return {
7
+ id: account.id,
8
+ label: account.label,
9
+ host: account.host,
10
+ port: account.port,
11
+ secure: account.secure,
12
+ username: account.username,
13
+ isDefault: account.isDefault === true,
14
+ auth: account.auth === 'oauth' ? 'oauth' : 'password',
15
+ ...(account.oauth ? {oauth: {
16
+ provider: account.oauth.provider, clientId: account.oauth.clientId,
17
+ tenant: account.oauth.tenant ?? null, status: account.oauth.status,
18
+ error: account.oauth.error ?? null,
19
+ hasClientSecret: Boolean(account.oauth.clientSecretSealed)
20
+ }} : {}),
21
+ syncFolders: Array.isArray(account.syncFolders) ? account.syncFolders : null,
22
+ pollIntervalMinutes: account.pollIntervalMinutes ?? null,
23
+ hasPassword: Boolean(account.passwordSealed),
24
+ createdAt: account.createdAt,
25
+ updatedAt: account.updatedAt
26
+ };
27
+ }