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,130 @@
1
+ // Source: @domma-mail/core 0.18.0, packages/core/src/mail/accountRoutes.js.
2
+ // Update with domma-mail/scripts/sync-cms.mjs; edit the shared source.
3
+ import {MailKeyError} from './secretProvider.js';
4
+
5
+ /** Existing account routes with explicit ownership, transport and host-policy adapters. */
6
+ export function registerAccountRoutes(fastify, {accounts, pool, authenticate, guardHost, forgetBadge = () => {}, onDelete} = {}) {
7
+ if (!accounts || !pool || typeof authenticate !== 'function' || typeof guardHost !== 'function') {
8
+ throw new Error('Account routes require storage, authentication, transport and a host policy.');
9
+ }
10
+ const userId = request => request.user?.id ?? request.user?.sub ?? null;
11
+ const testLimit = {config: {rateLimit: {max: 10, timeWindow: '1 minute'}}};
12
+ /** GET /accounts - every mailbox this user owns, without passwords. */
13
+ fastify.get('/accounts', {preHandler: [authenticate]}, async (request, reply) => {
14
+ const uid = userId(request);
15
+ if (!uid) return reply.code(401).send({error: 'Authentication required.'});
16
+ return {accounts: (await accounts.listAccounts(uid)).map(accounts.toPublic)};
17
+ });
18
+
19
+ /** POST /accounts - add a mailbox. */
20
+ fastify.post('/accounts', {preHandler: [authenticate]}, async (request, reply) => {
21
+ const uid = userId(request);
22
+ if (!uid) return reply.code(401).send({error: 'Authentication required.'});
23
+
24
+ const result = accounts.validate(request.body ?? {}, null);
25
+ if (!result.ok) return reply.code(400).send({error: result.error});
26
+ const where = await guardHost(result.value.host, result.value.port);
27
+ if (!where.ok) return reply.code(400).send({error: where.error});
28
+
29
+ const saved = await accounts.saveAccount(uid, null, result.value);
30
+ forgetBadge(uid);
31
+ return {account: accounts.toPublic(saved)};
32
+ });
33
+
34
+ /** PUT /accounts/:id - update one. A blank password keeps the stored one. */
35
+ fastify.put('/accounts/:id', {preHandler: [authenticate]}, async (request, reply) => {
36
+ const uid = userId(request);
37
+ if (!uid) return reply.code(401).send({error: 'Authentication required.'});
38
+
39
+ const existing = await accounts.getAccount(uid, request.params.id);
40
+ if (!existing) return reply.code(404).send({error: 'That mailbox does not exist.'});
41
+
42
+ const result = accounts.validate(request.body ?? {}, existing);
43
+ if (!result.ok) return reply.code(400).send({error: result.error});
44
+ // A signed-in mailbox's servers are the provider's and cannot be edited here.
45
+ const where = result.value.oauth ? {ok: true} : await guardHost(result.value.host, result.value.port);
46
+ if (!where.ok) return reply.code(400).send({error: where.error});
47
+
48
+ const saved = await accounts.saveAccount(uid, request.params.id, result.value);
49
+ // The pooled connection was opened with the old details.
50
+ pool.release(`${uid}:${request.params.id}`);
51
+ forgetBadge(uid);
52
+ return {account: accounts.toPublic(saved)};
53
+ });
54
+
55
+ /** PUT /accounts/:id/default - make it the default mailbox ({isDefault: false} clears it). */
56
+ fastify.put('/accounts/:id/default', {preHandler: [authenticate]}, async (request, reply) => {
57
+ const uid = userId(request);
58
+ if (!uid) return reply.code(401).send({error: 'Authentication required.'});
59
+
60
+ const saved = await accounts.setDefaultAccount(uid, request.params.id, request.body?.isDefault !== false);
61
+ if (!saved) return reply.code(404).send({error: 'That mailbox does not exist.'});
62
+ return {account: accounts.toPublic(saved)};
63
+ });
64
+
65
+ /** DELETE /accounts/:id - forget a mailbox and its password. */
66
+ fastify.delete('/accounts/:id', {preHandler: [authenticate]}, async (request, reply) => {
67
+ const uid = userId(request);
68
+ if (!uid) return reply.code(401).send({error: 'Authentication required.'});
69
+
70
+ pool.release(`${uid}:${request.params.id}`);
71
+ const existing = await accounts.getAccount(uid, request.params.id);
72
+ const deleted = await accounts.deleteAccount(uid, request.params.id);
73
+ if (!deleted) return reply.code(404).send({error: 'That mailbox does not exist.'});
74
+ forgetBadge(uid);
75
+ // A signed-in mailbox hands its sign-in back where the provider allows
76
+ // it (Google). Best-effort and after the delete: forgetting it here
77
+ // must not wait on, or fail because of, the provider.
78
+ if (typeof onDelete === 'function') Promise.resolve().then(() => onDelete(existing)).catch(() => {});
79
+ return {deleted: true};
80
+ });
81
+
82
+ /**
83
+ * POST /accounts/test - try details without saving them.
84
+ *
85
+ * Accepts a body so a mailbox can be tested before it is saved. When the
86
+ * password field is blank and `id` names an existing mailbox, the stored
87
+ * password is used - otherwise editing a hostname would mean retyping it.
88
+ */
89
+ fastify.post('/accounts/test', {preHandler: [authenticate], ...testLimit}, async (request, reply) => {
90
+ const uid = userId(request);
91
+ if (!uid) return reply.code(401).send({error: 'Authentication required.'});
92
+
93
+ const body = request.body ?? {};
94
+ const existing = body.id ? await accounts.getAccount(uid, body.id) : null;
95
+ if (body.id && !existing) return reply.code(404).send({error: 'That mailbox does not exist.'});
96
+
97
+ const result = accounts.validate(body, existing);
98
+ if (!result.ok) return reply.code(400).send({error: result.error});
99
+ // A signed-in mailbox is tested as stored: the provider's own server,
100
+ // its token renewed if need be. Nothing typed is involved.
101
+ if (result.value.oauth) {
102
+ try {
103
+ return await pool.test(accounts.toConnection(existing));
104
+ } catch (err) {
105
+ if (err instanceof MailKeyError) return {ok: false, error: err.message};
106
+ throw err;
107
+ }
108
+ }
109
+ const where = await guardHost(result.value.host, result.value.port);
110
+ if (!where.ok) return reply.code(400).send({error: where.error});
111
+
112
+ let pass = result.value.password;
113
+ if (!pass) {
114
+ try {
115
+ pass = accounts.toConnection(existing).auth.pass;
116
+ } catch (err) {
117
+ if (err instanceof MailKeyError) return reply.code(409).send({error: err.message});
118
+ throw err;
119
+ }
120
+ }
121
+
122
+ return pool.test({
123
+ host: result.value.host,
124
+ port: result.value.port,
125
+ secure: result.value.secure,
126
+ auth: {user: result.value.username, pass}
127
+ });
128
+ });
129
+
130
+ }