An on-device, SQLCipher-encrypted full-text index the app can retrieve from to
feed an LLM ("prompt against"), for the Electron desktop shell only.
Shape: no persistent background worker and no resident credential. Indexing is
a normal request-scoped API route, triggered by the renderer's EXISTING live
JMAP push connection - so it reacts to each delivery/change rather than polling.
- lib/mail-index/binding.ts guarded require of the optional native binding
- lib/mail-index/paths.ts the VNCMAIL_DESKTOP_STORE_DIR gate + hashed paths
- lib/mail-index/store.ts schema, upsert, FTS5 search, encryption assertion
- lib/mail-index/extract.ts PURE JMAP-object -> document extractors
- lib/mail-index/jmap.ts minimal stateless server-side JMAP client
- lib/mail-index/key.ts per-job key fetch over the inherited fd
- lib/mail-index/reindex.ts the job + slot->account resolution
- electron/key-service.ts safeStorage wrap/unwrap, served over fd 3
- app/api/offline/reindex POST, event-driven + catch-up
- app/api/offline/search GET, the retrieval surface (hits + contextBlock)
- lib/mail-index-client.ts renderer client; StateChange -> index call
- components/settings/local-index-settings.tsx status + manual catch-up
Decisions worth knowing:
* `@signalapp/sqlcipher` is an OPTIONAL dependency with a guarded runtime
require. It publishes six N-API prebuilds and NO build sources, and both
Dockerfiles are node:24-alpine (musl, no matching prebuild) - as a hard
dependency it would break the production image and the integration fixture's
webmail container, neither of which wants this feature.
* Credentials come from the existing per-slot encrypted `jmap_stalwart_ctx`
cookie via lib/stalwart/credentials.ts - the same helper /api/settings and
/api/push/preview already use. It carries a ready-made header for basic AND
bearer accounts, so the indexer never touches the OAuth refresh-token cookie;
a server-side refresh would rotate a token into a response nobody reads and
silently log the user out.
* The encryption key crosses main -> server over an INHERITED FILE DESCRIPTOR,
never an environment variable: env is readable by any process running as the
same OS user, which would defeat using the OS keychain at all. Fetched per
job and zeroed after, so there is no long-lived key copy.
* safeStorage's Linux `basic_text` backend (no keyring) is treated as refusal,
not degradation - it "encrypts" with a hardcoded public password, which would
look like an encrypted mailbox while providing nothing.
getSelectedStorageBackend() is Linux-only and platform-guarded.
* Every store open asserts `PRAGMA cipher_version` returns a non-empty STRING,
not merely a row: a non-cipher binding returns ZERO ROWS, so a row-count check
would pass vacuously while writing the mailbox to disk in cleartext.
* Files are indexed by name/path/date/size only - NOT by extracted content.
Text extraction from arbitrary PDFs/office documents is a separate problem.
* Account-scoped composite keys `(jmap_account_id, content_type, id)` are kept
even though there is one file per account: one login exposes delegated/shared
JMAP accounts too, and JMAP ids are unique only within an account.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
80 lines
3.1 KiB
TypeScript
80 lines
3.1 KiB
TypeScript
import type { NextConfig } from "next";
|
|
import createNextIntlPlugin from "next-intl/plugin";
|
|
import { execSync } from "child_process";
|
|
import { readFileSync } from "fs";
|
|
import { join } from "path";
|
|
|
|
// Prefer an explicit build arg (passed in by CI / Docker, where .git is
|
|
// excluded from the build context) and fall back to `git rev-parse` for
|
|
// local builds.
|
|
let gitCommitHash = process.env.GIT_COMMIT?.trim() || "";
|
|
if (!gitCommitHash) {
|
|
try {
|
|
gitCommitHash = execSync("git rev-parse --short HEAD").toString().trim();
|
|
} catch {
|
|
gitCommitHash = "unknown";
|
|
}
|
|
}
|
|
// Normalise full 40-char SHAs (e.g. ${{ github.sha }}) to the short form.
|
|
if (/^[0-9a-f]{40}$/i.test(gitCommitHash)) {
|
|
gitCommitHash = gitCommitHash.slice(0, 7);
|
|
}
|
|
|
|
let appVersion = "0.0.0";
|
|
try {
|
|
appVersion = readFileSync(join(import.meta.dirname, "VERSION"), "utf-8").trim();
|
|
} catch {
|
|
// VERSION file not found
|
|
}
|
|
|
|
// Subpath deployment, e.g. NEXT_PUBLIC_BASE_PATH=/webmail. Read at build time
|
|
// because Next.js bakes basePath into emitted asset URLs and route metadata.
|
|
// Trailing slash is stripped; an empty/missing value disables the feature.
|
|
const rawBasePath = process.env.NEXT_PUBLIC_BASE_PATH?.trim() ?? "";
|
|
const basePath = rawBasePath.replace(/\/+$/, "");
|
|
if (basePath && !basePath.startsWith("/")) {
|
|
throw new Error(
|
|
`NEXT_PUBLIC_BASE_PATH must start with "/" (got: ${JSON.stringify(rawBasePath)})`
|
|
);
|
|
}
|
|
|
|
const nextConfig: NextConfig = {
|
|
output: "standalone",
|
|
// 127.0.0.1 alongside the existing LAN entry: electron/main.ts always
|
|
// loads its window at 127.0.0.1 (see ELECTRON_LOAD_URL and
|
|
// startStandaloneServer()), so dev-mode Electron runs (only used by
|
|
// integration/tests/11-electron-notification.spec.ts today) need it in
|
|
// this allowlist the same way any other cross-origin dev client would.
|
|
allowedDevOrigins: ["192.168.1.51", "127.0.0.1"],
|
|
basePath: basePath || undefined,
|
|
// esbuild ships native binaries + a README the bundler can't parse; load
|
|
// it from node_modules at runtime instead of trying to bundle it. Used by
|
|
// PLUGIN_DEV_DIR's on-the-fly bundler.
|
|
//
|
|
// @signalapp/sqlcipher is a native N-API addon resolved at runtime by
|
|
// node-gyp-build (a directory scan of prebuilds/), which a bundler cannot
|
|
// follow. It is also an OPTIONAL dependency - absent on musl/Alpine, where
|
|
// both Dockerfiles build - so it must never be a hard build-time import.
|
|
// lib/mail-index/binding.ts guards the require; this keeps webpack from
|
|
// trying to resolve it at all.
|
|
serverExternalPackages: ["esbuild", "@signalapp/sqlcipher"],
|
|
// Sibling repos checked out under ./repos/ are unrelated source trees that
|
|
// Turbopack's NFT can otherwise rope into the trace when dynamic fs calls
|
|
// confuse it. Keeps the build from ballooning memory tracing dead code.
|
|
outputFileTracingExcludes: {
|
|
"*": ["./repos/**/*"],
|
|
},
|
|
turbopack: {
|
|
root: import.meta.dirname,
|
|
},
|
|
env: {
|
|
NEXT_PUBLIC_GIT_COMMIT: gitCommitHash,
|
|
NEXT_PUBLIC_APP_VERSION: appVersion,
|
|
NEXT_PUBLIC_BASE_PATH: basePath,
|
|
NEXT_PUBLIC_DEV_MOCK_JMAP: process.env.DEV_MOCK_JMAP ?? "",
|
|
},
|
|
};
|
|
|
|
const withNextIntl = createNextIntlPlugin();
|
|
export default withNextIntl(nextConfig);
|