|
@@ -1,5 +1,6 @@
|
|
|
import assert from 'node:assert/strict';
|
|
import assert from 'node:assert/strict';
|
|
|
import { mkdtempSync } from 'node:fs';
|
|
import { mkdtempSync } from 'node:fs';
|
|
|
|
|
+import { DatabaseSync } from 'node:sqlite';
|
|
|
import os from 'node:os';
|
|
import os from 'node:os';
|
|
|
import path from 'node:path';
|
|
import path from 'node:path';
|
|
|
import { test } from 'node:test';
|
|
import { test } from 'node:test';
|
|
@@ -10,6 +11,7 @@ import {
|
|
|
getInboundMailboxProtocolMessage,
|
|
getInboundMailboxProtocolMessage,
|
|
|
getInboundMessage,
|
|
getInboundMessage,
|
|
|
hasImportedInboundMessage,
|
|
hasImportedInboundMessage,
|
|
|
|
|
+ importedInboundMessageLookupSql,
|
|
|
initDatabase,
|
|
initDatabase,
|
|
|
listInboundMailboxProtocolMessages,
|
|
listInboundMailboxProtocolMessages,
|
|
|
searchInboundMessages,
|
|
searchInboundMessages,
|
|
@@ -70,7 +72,8 @@ test('imports Vesta mailbox hashes without plaintext and upgrades after successf
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
test('imports raw Maildir bytes, flags, timestamps and skips the same source key', () => {
|
|
test('imports raw Maildir bytes, flags, timestamps and skips the same source key', () => {
|
|
|
- initDatabase(tempDataDir(), 'import-test-secret');
|
|
|
|
|
|
|
+ const dataDir = tempDataDir();
|
|
|
|
|
+ initDatabase(dataDir, 'import-test-secret');
|
|
|
const user = seedAdminUser({ username: 'admin', email: 'admin@example.test', password: 'admin-password' });
|
|
const user = seedAdminUser({ username: 'admin', email: 'admin@example.test', password: 'admin-password' });
|
|
|
createTestDomain(user.id, 'mail.example');
|
|
createTestDomain(user.id, 'mail.example');
|
|
|
const mailbox = upsertImportedInboundMailbox(user.id, {
|
|
const mailbox = upsertImportedInboundMailbox(user.id, {
|
|
@@ -100,6 +103,19 @@ test('imports raw Maildir bytes, flags, timestamps and skips the same source key
|
|
|
assert.equal(second.message.id, first.message.id);
|
|
assert.equal(second.message.id, first.message.id);
|
|
|
assert.equal(hasImportedInboundMessage(payload.importSource, payload.sourceKey), true);
|
|
assert.equal(hasImportedInboundMessage(payload.importSource, payload.sourceKey), true);
|
|
|
|
|
|
|
|
|
|
+ const database = new DatabaseSync(path.join(dataDir, 'mailhub.sqlite'), { readOnly: true });
|
|
|
|
|
+ try {
|
|
|
|
|
+ const detail = database
|
|
|
|
|
+ .prepare(`EXPLAIN QUERY PLAN ${importedInboundMessageLookupSql}`)
|
|
|
|
|
+ .all(payload.importSource, payload.sourceKey)
|
|
|
|
|
+ .map((row) => row.detail)
|
|
|
|
|
+ .join('\n');
|
|
|
|
|
+ assert.match(detail, /SEARCH inbound_messages USING COVERING INDEX idx_inbound_messages_import_source_key/);
|
|
|
|
|
+ assert.doesNotMatch(detail, /\bSCAN inbound_messages\b/);
|
|
|
|
|
+ } finally {
|
|
|
|
|
+ database.close();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
const message = getInboundMessage(user.id, first.message.id);
|
|
const message = getInboundMessage(user.id, first.message.id);
|
|
|
assert.equal(message.rawMessage, rawMessageBytes.toString('utf8'));
|
|
assert.equal(message.rawMessage, rawMessageBytes.toString('utf8'));
|
|
|
assert.equal(message.read, true);
|
|
assert.equal(message.read, true);
|