@nocobase/app-plugin-mail 1.0.0-beta.13 → 1.0.0-beta.14
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.
- package/CHANGELOG.md +22 -0
- package/README.md +8 -0
- package/dist/database/migrations/.manifest.json +4 -0
- package/dist/database/migrations/202610250001_mail_imap_message_locations.d.ts +4 -0
- package/dist/database/migrations/202610250001_mail_imap_message_locations.d.ts.map +1 -0
- package/dist/database/migrations/202610250001_mail_imap_message_locations.js +297 -0
- package/dist/database/migrations/202610250001_mail_imap_message_locations.js.map +1 -0
- package/dist/server/adapters/imap-smtp/adapter.d.ts +60 -3
- package/dist/server/adapters/imap-smtp/adapter.d.ts.map +1 -1
- package/dist/server/adapters/imap-smtp/adapter.js +774 -83
- package/dist/server/adapters/imap-smtp/adapter.js.map +1 -1
- package/dist/server/adapters/imap-smtp/constants.d.ts +6 -0
- package/dist/server/adapters/imap-smtp/constants.d.ts.map +1 -1
- package/dist/server/adapters/imap-smtp/constants.js +6 -0
- package/dist/server/adapters/imap-smtp/constants.js.map +1 -1
- package/dist/server/adapters/imap-smtp/content.d.ts +11 -0
- package/dist/server/adapters/imap-smtp/content.d.ts.map +1 -1
- package/dist/server/adapters/imap-smtp/content.js +82 -3
- package/dist/server/adapters/imap-smtp/content.js.map +1 -1
- package/dist/server/adapters/imap-smtp/definition.d.ts +7 -0
- package/dist/server/adapters/imap-smtp/definition.d.ts.map +1 -1
- package/dist/server/adapters/imap-smtp/definition.js +19 -11
- package/dist/server/adapters/imap-smtp/definition.js.map +1 -1
- package/dist/server/adapters/imap-smtp/locators.d.ts +7 -0
- package/dist/server/adapters/imap-smtp/locators.d.ts.map +1 -1
- package/dist/server/adapters/imap-smtp/locators.js +53 -3
- package/dist/server/adapters/imap-smtp/locators.js.map +1 -1
- package/dist/server/adapters/imap-smtp/types.d.ts +87 -0
- package/dist/server/adapters/imap-smtp/types.d.ts.map +1 -1
- package/dist/server/operations/message-mutations.d.ts.map +1 -1
- package/dist/server/operations/message-mutations.js +57 -5
- package/dist/server/operations/message-mutations.js.map +1 -1
- package/dist/server/operations/sync-mailbox.d.ts.map +1 -1
- package/dist/server/operations/sync-mailbox.js +26 -10
- package/dist/server/operations/sync-mailbox.js.map +1 -1
- package/dist/server/providers/mail-builtins.d.ts.map +1 -1
- package/dist/server/providers/mail-builtins.js +6 -2
- package/dist/server/providers/mail-builtins.js.map +1 -1
- package/dist/server/store/attachments.d.ts.map +1 -1
- package/dist/server/store/attachments.js +3 -0
- package/dist/server/store/attachments.js.map +1 -1
- package/dist/server/store/message-writes.d.ts +24 -1
- package/dist/server/store/message-writes.d.ts.map +1 -1
- package/dist/server/store/message-writes.js +357 -1
- package/dist/server/store/message-writes.js.map +1 -1
- package/dist/server/store/messages.d.ts.map +1 -1
- package/dist/server/store/messages.js +11 -3
- package/dist/server/store/messages.js.map +1 -1
- package/dist/server/store/rows.d.ts +20 -0
- package/dist/server/store/rows.d.ts.map +1 -1
- package/dist/server/store/sync.d.ts +7 -1
- package/dist/server/store/sync.d.ts.map +1 -1
- package/dist/server/store/sync.js +333 -7
- package/dist/server/store/sync.js.map +1 -1
- package/package.json +14 -13
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
# @nocobase/app-plugin-mail
|
|
2
2
|
|
|
3
|
+
## 1.0.0-beta.14
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- dcd45ed: Give IMAP messages a reliable identity and track every remote copy. A message is identified by the server's OBJECTID `EMAILID`, then Gmail's `X-GM-MSGID`, then an RFC `Message-ID` proven by byte-identical MIME, and otherwise by its folder, UIDVALIDITY and UID. Each copy is stored in the new `mailMessageImapLocations` collection; read state, star state and folders are derived from the verified copies, flag changes and permanent deletion apply to every copy (permanent deletion now requires UIDPLUS), and a message without copies is removed only when a sync run completes after two matching full verification passes. Migration `202610250001_mail_imap_message_locations` upgrades existing IMAP locator messages and remote draft mirrors offline, preserving their identities, UUIDs and business data while backfilling locator sources and recorded positions. It does not contact mail servers or invent positions for local drafts, SMTP-accepted RFC records or other providers. Unsafe locators and conflicting tuple ownership fail preflight before structural changes; populated destructive rollback remains prohibited. UID, UIDVALIDITY, identity source and location status bounds are validated by application writes; this migration does not install database CHECK constraints, so direct database writes can bypass those bounds.
|
|
8
|
+
|
|
9
|
+
Keep opaque remote attachment IDs out of local upload UUID queries so localized drafts can read their remote attachments on PostgreSQL while preserving upload ownership and expiration checks.
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 1993feb: Add user-event as a mail plugin test dependency.
|
|
14
|
+
- Updated dependencies [69e212c]
|
|
15
|
+
- Updated dependencies [943a9a8]
|
|
16
|
+
- Updated dependencies [943a9a8]
|
|
17
|
+
- Updated dependencies [1cd749c]
|
|
18
|
+
- Updated dependencies [bdb0581]
|
|
19
|
+
- Updated dependencies [9b946f4]
|
|
20
|
+
- @nocobase/app-server@2.0.0-beta.7
|
|
21
|
+
- @nocobase/db@1.0.0-beta.20
|
|
22
|
+
- @nocobase/app-plugin-authentication@2.0.0-beta.9
|
|
23
|
+
- @nocobase/app-plugin-authorization@1.0.0-beta.27
|
|
24
|
+
|
|
3
25
|
## 1.0.0-beta.13
|
|
4
26
|
|
|
5
27
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -86,4 +86,12 @@ pnpm --filter @nocobase/app-plugin-mail test
|
|
|
86
86
|
pnpm --filter @nocobase/app-plugin-mail build
|
|
87
87
|
```
|
|
88
88
|
|
|
89
|
+
## IMAP location upgrade
|
|
90
|
+
|
|
91
|
+
Migration `202610250001_mail_imap_message_locations` supports existing mail data. It preserves legacy `imap:` identities and business UUIDs, decodes their recorded folder, UIDVALIDITY and UID locally, and adds `locator` identity sources and account-scoped locations. Localized remote drafts use their `providerDraftMessageId` mirror, including scheduled drafts. Locations initially retain the recorded read/star state and received time as a valid snapshot; subsequent IMAP reads and mutations still verify the remote generation and UID. The migration does not contact a mail server, discover native identities, merge messages, reset synchronization, or rewrite message content, attachments, notes or draft submissions.
|
|
92
|
+
|
|
93
|
+
Pure local drafts, non-IMAP accounts and SMTP-accepted RFC Message-ID records without a recorded remote tuple remain unchanged. Such SMTP records do not acquire remote addressing merely by upgrading. Malformed legacy locators, out-of-range or missing tuple values, unrepresentable identities and competing message UUIDs for one account's tuple fail precise preflight before schema changes; the migration never guesses a generation, truncates an identity or drops a conflicting record.
|
|
94
|
+
|
|
95
|
+
Use the maintenance window described above: stop application writes and all Mail workers, back up the database, run the application's `nocobase db apply`, verify sources, positions and representative existing-message operations, then restart. This is an offline upgrade. Historical migration checksums and existing key/subscription lengths remain unchanged, and this upgrade requires no checksum repair. Rollback refuses when mail business data exists because dropping locations or reverting the expanded header field would be destructive; this rollback restriction does not prevent populated upgrades.
|
|
96
|
+
|
|
89
97
|
User-facing and application-integration documentation is maintained in the NocoBase documentation site rather than duplicated in this package README.
|
|
@@ -20,6 +20,10 @@
|
|
|
20
20
|
"202610090001_mail_create_message_participants.js": {
|
|
21
21
|
"sourceChecksum": "8cbc894973a532c79aacb638cce4a687d316e1ba7f0043a7ed7d13b268b61155",
|
|
22
22
|
"artifactChecksum": "95c122dbda4b5c273d0da0d795b4e895cce5b6b16c460fe1187b6180ef5d3137"
|
|
23
|
+
},
|
|
24
|
+
"202610250001_mail_imap_message_locations.js": {
|
|
25
|
+
"sourceChecksum": "f6acd8d5eb6f70a99bf725b33930720f4510d5da11d7744d1e26c2125526854a",
|
|
26
|
+
"artifactChecksum": "aeeb60baab0f81a8ffa1e0a1d6be91e2aa14da56851d590494a595943803d0c8"
|
|
23
27
|
}
|
|
24
28
|
}
|
|
25
29
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"202610250001_mail_imap_message_locations.d.ts","sourceRoot":"","sources":["../../../database/migrations/202610250001_mail_imap_message_locations.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,KAAK,mBAAmB,EAEzB,MAAM,cAAc,CAAC;AAoKtB,QAAA,MAAM,SAAS,EAAE,mBA8Lf,CAAC;AAEH,eAAe,SAAS,CAAC"}
|
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { defineMigration, } from '@nocobase/db';
|
|
3
|
+
// Rollback cannot discard mail business data or its location ownership.
|
|
4
|
+
const MESSAGE_TABLES = [
|
|
5
|
+
'mailMessages',
|
|
6
|
+
'mailMessageFolders',
|
|
7
|
+
'mailMessageLabels',
|
|
8
|
+
'mailMessageParticipants',
|
|
9
|
+
'mailSyncTombstones',
|
|
10
|
+
'mailDraftStates',
|
|
11
|
+
'mailSubmissions',
|
|
12
|
+
'mailOutboundAttachments',
|
|
13
|
+
'mailSyncStates',
|
|
14
|
+
'mailSyncRuns',
|
|
15
|
+
'mailOutbox',
|
|
16
|
+
'mailPushPending',
|
|
17
|
+
'mailAccountRemovals',
|
|
18
|
+
];
|
|
19
|
+
async function assertNoMessages(query, action) {
|
|
20
|
+
for (const table of MESSAGE_TABLES) {
|
|
21
|
+
const row = await query.selectFrom(table).selectAll().limit(1).execute();
|
|
22
|
+
if (row.length > 0)
|
|
23
|
+
throw new Error(`Cannot ${action} IMAP message locations while ${table} contains data. Rollback would lose mail business data.`);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function legacyCopy(message) {
|
|
27
|
+
const mirror = message.providerMessageId.startsWith('local-draft:');
|
|
28
|
+
const identity = mirror
|
|
29
|
+
? message.providerDraftMessageId
|
|
30
|
+
: message.providerMessageId;
|
|
31
|
+
// SMTP accepted RFC IDs and local-only drafts have no recorded remote tuple.
|
|
32
|
+
if (!identity?.startsWith('imap:'))
|
|
33
|
+
return undefined;
|
|
34
|
+
const fail = (reason) => {
|
|
35
|
+
throw new Error(`Cannot upgrade legacy IMAP message ${message.id}: ${reason}.`);
|
|
36
|
+
};
|
|
37
|
+
if (!message.ownerId)
|
|
38
|
+
fail('missing owning account');
|
|
39
|
+
if (message.providerType !== 'imap-smtp')
|
|
40
|
+
return undefined;
|
|
41
|
+
if (identity.length > 500)
|
|
42
|
+
fail('locator exceeds identity capacity');
|
|
43
|
+
let parsed;
|
|
44
|
+
try {
|
|
45
|
+
const encoded = identity.slice(5);
|
|
46
|
+
const bytes = Buffer.from(encoded, 'base64url');
|
|
47
|
+
if (!encoded || bytes.toString('base64url') !== encoded)
|
|
48
|
+
return fail('invalid locator encoding');
|
|
49
|
+
if (!Buffer.from(bytes.toString('utf8'), 'utf8').equals(bytes))
|
|
50
|
+
return fail('invalid locator encoding');
|
|
51
|
+
const value = JSON.parse(bytes.toString('utf8'));
|
|
52
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
53
|
+
return fail('invalid locator object');
|
|
54
|
+
parsed = value;
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
return fail('invalid locator encoding');
|
|
58
|
+
}
|
|
59
|
+
const { folder, uidValidity, uid } = parsed;
|
|
60
|
+
if (typeof folder !== 'string' ||
|
|
61
|
+
!folder.length ||
|
|
62
|
+
folder.length > 500 ||
|
|
63
|
+
folder.includes('\0'))
|
|
64
|
+
return fail('invalid folder path');
|
|
65
|
+
if (typeof uidValidity !== 'string' ||
|
|
66
|
+
!/^[1-9]\d{0,9}$/.test(uidValidity) ||
|
|
67
|
+
BigInt(uidValidity) > 4294967295n)
|
|
68
|
+
return fail('invalid UIDVALIDITY');
|
|
69
|
+
if (typeof uid !== 'number' ||
|
|
70
|
+
!Number.isSafeInteger(uid) ||
|
|
71
|
+
uid < 1 ||
|
|
72
|
+
uid > 4294967295)
|
|
73
|
+
return fail('invalid UID');
|
|
74
|
+
return {
|
|
75
|
+
message,
|
|
76
|
+
sourceField: mirror ? 'providerDraftMessageIdSource' : 'imapIdSource',
|
|
77
|
+
folder,
|
|
78
|
+
uidValidity,
|
|
79
|
+
uid,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
/** Two bounded scans: preflight before DDL, then copy only recorded local facts. */
|
|
83
|
+
async function legacyCopies(query, visit) {
|
|
84
|
+
let last;
|
|
85
|
+
for (;;) {
|
|
86
|
+
let selection = query
|
|
87
|
+
.selectFrom('mailMessages')
|
|
88
|
+
.leftJoin('mailAccounts', 'mailAccounts.id', 'mailMessages.accountId')
|
|
89
|
+
.select([
|
|
90
|
+
'mailMessages.id',
|
|
91
|
+
'mailMessages.accountId',
|
|
92
|
+
'mailAccounts.id as ownerId',
|
|
93
|
+
'mailAccounts.providerType',
|
|
94
|
+
'mailMessages.providerMessageId',
|
|
95
|
+
'mailMessages.providerDraftMessageId',
|
|
96
|
+
'mailMessages.read',
|
|
97
|
+
'mailMessages.starred',
|
|
98
|
+
'mailMessages.receivedAt',
|
|
99
|
+
'mailMessages.createdAt',
|
|
100
|
+
'mailMessages.updatedAt',
|
|
101
|
+
])
|
|
102
|
+
.orderBy('mailMessages.accountId')
|
|
103
|
+
.orderBy('mailMessages.id')
|
|
104
|
+
.limit(100);
|
|
105
|
+
if (last) {
|
|
106
|
+
const cursor = last;
|
|
107
|
+
selection = selection.where((builder) => builder.or([
|
|
108
|
+
builder('mailMessages.accountId', '>', cursor.accountId),
|
|
109
|
+
builder.and([
|
|
110
|
+
builder('mailMessages.accountId', '=', cursor.accountId),
|
|
111
|
+
builder('mailMessages.id', '>', cursor.id),
|
|
112
|
+
]),
|
|
113
|
+
]));
|
|
114
|
+
}
|
|
115
|
+
const rows = await selection.execute();
|
|
116
|
+
if (!rows.length)
|
|
117
|
+
return;
|
|
118
|
+
await visit(rows.flatMap((row) => {
|
|
119
|
+
const copy = legacyCopy(row);
|
|
120
|
+
return copy ? [copy] : [];
|
|
121
|
+
}));
|
|
122
|
+
last = rows.at(-1);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
const migration = defineMigration({
|
|
126
|
+
name: '202610250001_mail_imap_message_locations',
|
|
127
|
+
async up({ builder, query, connection }) {
|
|
128
|
+
let accountId;
|
|
129
|
+
const owners = new Map();
|
|
130
|
+
await legacyCopies(query, async (copies) => {
|
|
131
|
+
for (const copy of copies) {
|
|
132
|
+
if (accountId !== copy.message.accountId) {
|
|
133
|
+
owners.clear();
|
|
134
|
+
accountId = copy.message.accountId;
|
|
135
|
+
}
|
|
136
|
+
const tuple = JSON.stringify([copy.folder, copy.uidValidity, copy.uid]);
|
|
137
|
+
const owner = owners.get(tuple);
|
|
138
|
+
if (owner && owner !== copy.message.id)
|
|
139
|
+
throw new Error(`Cannot upgrade legacy IMAP message ${copy.message.id}: tuple belongs to message ${owner}.`);
|
|
140
|
+
owners.set(tuple, copy.message.id);
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
// SQLite rebuilds a table when changing its column type. Detach only the
|
|
144
|
+
// incoming Mail foreign keys so that dropping that table cannot cascade.
|
|
145
|
+
// The migration transaction restores both schema and data on any failure.
|
|
146
|
+
const incoming = [
|
|
147
|
+
[
|
|
148
|
+
'mailMessageFolders',
|
|
149
|
+
'fk_mail_message_folders_message_id_mail_messages',
|
|
150
|
+
'messageId',
|
|
151
|
+
'mailMessages',
|
|
152
|
+
],
|
|
153
|
+
[
|
|
154
|
+
'mailMessageLabels',
|
|
155
|
+
'fk_mail_message_labels_message_id_mail_messages',
|
|
156
|
+
'messageId',
|
|
157
|
+
'mailMessages',
|
|
158
|
+
],
|
|
159
|
+
// Restore both label constraints in their original order as well.
|
|
160
|
+
[
|
|
161
|
+
'mailMessageLabels',
|
|
162
|
+
'fk_mail_message_labels_label_id_mail_labels',
|
|
163
|
+
'labelId',
|
|
164
|
+
'mailLabels',
|
|
165
|
+
],
|
|
166
|
+
[
|
|
167
|
+
'mailMessageParticipants',
|
|
168
|
+
'fk_mail_message_participants_message_id_mail_messages',
|
|
169
|
+
'messageId',
|
|
170
|
+
'mailMessages',
|
|
171
|
+
],
|
|
172
|
+
];
|
|
173
|
+
const detach = connection.dialect === 'sqlite' &&
|
|
174
|
+
(await query.selectFrom('mailMessages').select('id').limit(1).execute())
|
|
175
|
+
.length > 0;
|
|
176
|
+
if (detach) {
|
|
177
|
+
for (const [table, name] of incoming) {
|
|
178
|
+
await builder.alterCollection(table, (collection) => collection.dropConstraint(name));
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
await builder.alterCollection('mailMessages', (collection) => {
|
|
182
|
+
collection.string('imapIdSource', { length: 20 });
|
|
183
|
+
collection.string('providerDraftMessageIdSource', { length: 20 });
|
|
184
|
+
collection.uuid('imapOrphanRunId');
|
|
185
|
+
// A complete RFC Message-ID header can exceed the previous 1000 characters.
|
|
186
|
+
collection.alterField('internetMessageId', {
|
|
187
|
+
type: 'text',
|
|
188
|
+
db: connection.dialect === 'mysql' ? { nativeType: 'longtext' } : {},
|
|
189
|
+
});
|
|
190
|
+
// Target of the locations' account-scoped foreign key.
|
|
191
|
+
collection.unique(['accountId', 'id'], {
|
|
192
|
+
name: 'mail_messages_account_id_unique',
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
if (detach) {
|
|
196
|
+
for (const [table, name, field, target] of incoming) {
|
|
197
|
+
await builder.alterCollection(table, (collection) => collection.foreignKey(field, {
|
|
198
|
+
name,
|
|
199
|
+
references: { collection: target, fields: ['id'] },
|
|
200
|
+
onDelete: 'cascade',
|
|
201
|
+
}));
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
await builder.createCollection('mailMessageImapLocations', (collection) => {
|
|
205
|
+
collection.uuid('id').primary();
|
|
206
|
+
collection.uuid('accountId', { nullable: false });
|
|
207
|
+
collection.uuid('messageId', { nullable: false });
|
|
208
|
+
collection.string('providerFolderId', { length: 500, nullable: false });
|
|
209
|
+
// Canonical decimal UIDVALIDITY, 1 to 4294967295.
|
|
210
|
+
collection.string('uidValidity', { length: 10, nullable: false });
|
|
211
|
+
// Signed 64-bit holds every uint32 UID on every dialect.
|
|
212
|
+
collection.bigInt('uid', { nullable: false });
|
|
213
|
+
collection.string('status', { length: 10, nullable: false });
|
|
214
|
+
collection.string('invalidationReason', { length: 40 });
|
|
215
|
+
collection.boolean('read', { nullable: false, defaultValue: false });
|
|
216
|
+
collection.boolean('starred', { nullable: false, defaultValue: false });
|
|
217
|
+
collection.datetimeTz('receivedAt');
|
|
218
|
+
collection.datetimeTz('createdAt', { nullable: false });
|
|
219
|
+
collection.datetimeTz('updatedAt', { nullable: false });
|
|
220
|
+
collection.unique(['accountId', 'providerFolderId', 'uidValidity', 'uid'], {
|
|
221
|
+
name: 'mail_imap_locations_tuple_unique',
|
|
222
|
+
});
|
|
223
|
+
collection.index(['accountId', 'messageId'], {
|
|
224
|
+
name: 'mail_imap_locations_message_idx',
|
|
225
|
+
});
|
|
226
|
+
// One cascade path only: the owning message already belongs to the account.
|
|
227
|
+
collection.foreignKey(['accountId', 'messageId'], {
|
|
228
|
+
name: 'mail_imap_locations_message_fk',
|
|
229
|
+
references: {
|
|
230
|
+
collection: 'mailMessages',
|
|
231
|
+
fields: ['accountId', 'id'],
|
|
232
|
+
},
|
|
233
|
+
onDelete: 'cascade',
|
|
234
|
+
});
|
|
235
|
+
});
|
|
236
|
+
const now = new Date().toISOString();
|
|
237
|
+
await legacyCopies(query, async (copies) => {
|
|
238
|
+
if (!copies.length)
|
|
239
|
+
return;
|
|
240
|
+
await query
|
|
241
|
+
.insertInto('mailMessageImapLocations')
|
|
242
|
+
.values(copies.map((copy) => ({
|
|
243
|
+
id: randomUUID(),
|
|
244
|
+
accountId: copy.message.accountId,
|
|
245
|
+
messageId: copy.message.id,
|
|
246
|
+
providerFolderId: copy.folder,
|
|
247
|
+
uidValidity: copy.uidValidity,
|
|
248
|
+
uid: copy.uid,
|
|
249
|
+
status: 'valid',
|
|
250
|
+
invalidationReason: null,
|
|
251
|
+
read: copy.message.read,
|
|
252
|
+
starred: copy.message.starred,
|
|
253
|
+
receivedAt: copy.message.receivedAt,
|
|
254
|
+
createdAt: copy.message.createdAt ?? now,
|
|
255
|
+
updatedAt: copy.message.updatedAt ?? now,
|
|
256
|
+
})))
|
|
257
|
+
.execute();
|
|
258
|
+
for (const field of [
|
|
259
|
+
'imapIdSource',
|
|
260
|
+
'providerDraftMessageIdSource',
|
|
261
|
+
]) {
|
|
262
|
+
const ids = copies
|
|
263
|
+
.filter((copy) => copy.sourceField === field)
|
|
264
|
+
.map((copy) => copy.message.id);
|
|
265
|
+
if (ids.length)
|
|
266
|
+
await query
|
|
267
|
+
.updateTable('mailMessages')
|
|
268
|
+
.set({ [field]: 'locator' })
|
|
269
|
+
.where('id', 'in', ids)
|
|
270
|
+
.execute();
|
|
271
|
+
}
|
|
272
|
+
});
|
|
273
|
+
},
|
|
274
|
+
async down({ builder, query }) {
|
|
275
|
+
// Restoring the 1000-character Message-ID column must not cut stored values.
|
|
276
|
+
await assertNoMessages(query, 'remove');
|
|
277
|
+
if ((await query
|
|
278
|
+
.selectFrom('mailMessageImapLocations')
|
|
279
|
+
.selectAll()
|
|
280
|
+
.limit(1)
|
|
281
|
+
.execute()).length)
|
|
282
|
+
throw new Error('Cannot remove IMAP message locations while location business data exists.');
|
|
283
|
+
await builder.dropCollection('mailMessageImapLocations');
|
|
284
|
+
await builder.alterCollection('mailMessages', (collection) => {
|
|
285
|
+
collection.dropConstraint('mail_messages_account_id_unique');
|
|
286
|
+
collection.alterField('internetMessageId', {
|
|
287
|
+
type: 'string',
|
|
288
|
+
length: 1000,
|
|
289
|
+
db: {},
|
|
290
|
+
});
|
|
291
|
+
collection.dropFields('imapIdSource', 'providerDraftMessageIdSource', 'imapOrphanRunId');
|
|
292
|
+
});
|
|
293
|
+
},
|
|
294
|
+
});
|
|
295
|
+
export default migration;
|
|
296
|
+
//# sourceMappingURL=202610250001_mail_imap_message_locations.js.map
|
|
297
|
+
// @nocobase/task-manifest v1
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"202610250001_mail_imap_message_locations.js","sourceRoot":"","sources":["../../../database/migrations/202610250001_mail_imap_message_locations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EACL,eAA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AAC,mBAAmB,EAAE;gBACzC,IAAI,EAAE,QAAQ;gBACd,MAAM,EAAE,IAAI;gBACZ,EAAE,EAAE,EAAE;aACP,CAAC,CAAC;YACH,UAAU,CAAC,UAAU,CACnB,cAAc,EACd,8BAA8B,EAC9B,iBAAiB,CAClB,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;CACF,CAAC,CAAC;AAEH,eAAe,SAAS,CAAC"}
|
|
@@ -1,16 +1,43 @@
|
|
|
1
|
+
import { ImapFlow } from 'imapflow';
|
|
1
2
|
import type { MailAttachmentContent, MailProviderResult, MailSyncCursor } from '../../../shared/mail.js';
|
|
2
3
|
import type { MailProviderAdapter, MailProviderAccount, MailProviderContext, MailProviderFolderPage, MailProviderListChangesInput, MailProviderListFoldersInput, MailProviderListMessagesInput, MailProviderMessagePage, MailProviderSendInput, MailProviderSendResult, NormalizedMailMessage } from '../../contracts/provider.js';
|
|
3
|
-
import type { ImapSmtpCredential } from './types.js';
|
|
4
|
+
import type { ImapOperationSnapshot, ImapLocationPersistence, ImapSmtpCredential } from './types.js';
|
|
5
|
+
import type { MailSyncStepCommit } from '../../contracts/persistence.js';
|
|
6
|
+
import type { MailSyncRun } from '../../../shared/mail.js';
|
|
4
7
|
import type { ImapSmtpMailProviderConfig } from './config.js';
|
|
8
|
+
import { createImapClient, createSmtpTransport } from './connection.js';
|
|
5
9
|
export declare class ImapSmtpAdapter implements MailProviderAdapter {
|
|
10
|
+
private readonly context;
|
|
6
11
|
private readonly config;
|
|
12
|
+
private readonly account;
|
|
7
13
|
private readonly credential;
|
|
14
|
+
private readonly locations?;
|
|
15
|
+
private readonly protocol;
|
|
16
|
+
private readonly operation?;
|
|
8
17
|
readonly identity: MailProviderAccount['provider'];
|
|
9
18
|
readonly capabilities: MailProviderAdapter['capabilities'];
|
|
10
19
|
private readonly folderTypes;
|
|
11
20
|
private imapClient?;
|
|
12
21
|
private readonly smtpTransport;
|
|
13
|
-
|
|
22
|
+
private copies;
|
|
23
|
+
private changes;
|
|
24
|
+
private cleanup;
|
|
25
|
+
private verificationIncomplete;
|
|
26
|
+
private readonly verificationCopies;
|
|
27
|
+
private readonly syncRun?;
|
|
28
|
+
private rawBudget;
|
|
29
|
+
private readonly rawCache;
|
|
30
|
+
constructor(context: MailProviderContext, config: ImapSmtpMailProviderConfig, account: MailProviderAccount, credential: ImapSmtpCredential, locations?: ImapLocationPersistence | undefined, run?: MailSyncRun, protocol?: {
|
|
31
|
+
readonly imap: typeof createImapClient;
|
|
32
|
+
readonly smtp: typeof createSmtpTransport;
|
|
33
|
+
readonly expungeUid: typeof expungeUid;
|
|
34
|
+
}, operation?: ImapOperationSnapshot | undefined);
|
|
35
|
+
forSync(run: MailSyncRun): ImapSmtpAdapter;
|
|
36
|
+
forMessage(messageId: string, providerMessageId: string, operation: 'flags' | 'delete'): Promise<ImapSmtpAdapter>;
|
|
37
|
+
/** True when this instance records message copies in the account's location table. */
|
|
38
|
+
get persistsLocations(): boolean;
|
|
39
|
+
/** Commit a sync step together with the location evidence this instance gathered for it. */
|
|
40
|
+
commitSyncStep(input: MailSyncStepCommit): Promise<MailSyncRun>;
|
|
14
41
|
listFolders(input: MailProviderListFoldersInput): Promise<MailProviderResult<MailProviderFolderPage>>;
|
|
15
42
|
getCurrentSyncCursor(signal?: AbortSignal): Promise<MailProviderResult<MailSyncCursor>>;
|
|
16
43
|
listMessages(input: MailProviderListMessagesInput): Promise<MailProviderResult<MailProviderMessagePage>>;
|
|
@@ -21,13 +48,14 @@ export declare class ImapSmtpAdapter implements MailProviderAdapter {
|
|
|
21
48
|
readonly hasMore: boolean;
|
|
22
49
|
}>>;
|
|
23
50
|
getMessage(providerMessageId: string, signal?: AbortSignal): Promise<MailProviderResult<NormalizedMailMessage>>;
|
|
24
|
-
getAttachment(
|
|
51
|
+
getAttachment(providerMessageId: string, providerAttachmentId: string, signal?: AbortSignal): Promise<MailProviderResult<MailAttachmentContent>>;
|
|
25
52
|
sendMessage(input: MailProviderSendInput): Promise<MailProviderSendResult>;
|
|
26
53
|
setRead(providerMessageId: string, read: boolean, signal?: AbortSignal): Promise<MailProviderResult<void>>;
|
|
27
54
|
setStarred(providerMessageId: string, starred: boolean, signal?: AbortSignal): Promise<MailProviderResult<void>>;
|
|
28
55
|
deleteMessage(providerMessageId: string, permanently: boolean, signal?: AbortSignal): Promise<MailProviderResult<void>>;
|
|
29
56
|
close(): Promise<void>;
|
|
30
57
|
private updateFlags;
|
|
58
|
+
private closeImap;
|
|
31
59
|
private imap;
|
|
32
60
|
private listMailboxes;
|
|
33
61
|
private selectableMailboxes;
|
|
@@ -35,6 +63,35 @@ export declare class ImapSmtpAdapter implements MailProviderAdapter {
|
|
|
35
63
|
private selectedFolderState;
|
|
36
64
|
private normalizeFolder;
|
|
37
65
|
private fetchMessages;
|
|
66
|
+
private beginStep;
|
|
67
|
+
/**
|
|
68
|
+
* Choose each copy's identity: its persisted location first, then the
|
|
69
|
+
* server's native ID, then an RFC Message-ID proven by identical MIME bytes,
|
|
70
|
+
* and otherwise the copy's own location.
|
|
71
|
+
*/
|
|
72
|
+
private assignIdentities;
|
|
73
|
+
private nativeSource;
|
|
74
|
+
/** Compare a new copy with a verified copy already stored under this RFC Message-ID. */
|
|
75
|
+
private matchesStoredCopy;
|
|
76
|
+
private sameRawCopies;
|
|
77
|
+
/** Complete raw MIME of one copy within the per-message and per-step budgets. */
|
|
78
|
+
private rawCopy;
|
|
79
|
+
/**
|
|
80
|
+
* Select a stored copy and confirm it is still the same message. Returns
|
|
81
|
+
* undefined for a changed generation, a missing UID or another identity.
|
|
82
|
+
*/
|
|
83
|
+
private openCopy;
|
|
84
|
+
private copyChanged;
|
|
85
|
+
/** Change one flag on every verified copy, committing each confirmed copy on its own. */
|
|
86
|
+
private updateCopyFlags;
|
|
87
|
+
/**
|
|
88
|
+
* One complete pass over every selectable folder. It reconciles stored
|
|
89
|
+
* copies, and two matching passes in a row authorize orphan cleanup.
|
|
90
|
+
*/
|
|
91
|
+
private verifyFolders;
|
|
38
92
|
private normalizeMessage;
|
|
39
93
|
}
|
|
94
|
+
/** ImapFlow 2.2.10's command primitive keeps the verb explicitly scoped to a UID. */
|
|
95
|
+
declare function expungeUid(client: ImapFlow, uid: number): Promise<void>;
|
|
96
|
+
export {};
|
|
40
97
|
//# sourceMappingURL=adapter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../../../server/adapters/imap-smtp/adapter.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../../../server/adapters/imap-smtp/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAMT,MAAM,UAAU,CAAC;AAiBlB,OAAO,KAAK,EACV,qBAAqB,EAErB,kBAAkB,EAClB,cAAc,EACf,MAAM,yBAAyB,CAAC;AACjC,OAAO,KAAK,EACV,mBAAmB,EACnB,mBAAmB,EACnB,mBAAmB,EACnB,sBAAsB,EACtB,4BAA4B,EAC5B,4BAA4B,EAC5B,6BAA6B,EAC7B,uBAAuB,EACvB,qBAAqB,EACrB,sBAAsB,EAEtB,qBAAqB,EACtB,MAAM,6BAA6B,CAAC;AAErC,OAAO,KAAK,EAIV,qBAAqB,EAErB,uBAAuB,EAEvB,kBAAkB,EAKnB,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AACzE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,aAAa,CAAC;AAW9D,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAkCxE,qBAAa,eAAgB,YAAW,mBAAmB;IAqBvD,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,OAAO;I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