From 8200d1e4783a782fb2651170d0e251d390ac484a Mon Sep 17 00:00:00 2001 From: Wayne <5291640+ringoinca@users.noreply.github.com> Date: Fri, 17 Oct 2025 23:25:12 +0200 Subject: [PATCH] Add `ALL_INCLUSIVE_ARCHIVE` environment variable to disable jun filtering --- .env.example | 2 ++ docs/user-guides/installation.md | 17 +++++++++-------- packages/backend/src/config/app.ts | 1 + packages/backend/src/services/JobsService.ts | 2 +- .../ingestion-connectors/ImapConnector.ts | 15 ++++++++------- 5 files changed, 21 insertions(+), 16 deletions(-) diff --git a/.env.example b/.env.example index 35297b5..4f2b2c4 100644 --- a/.env.example +++ b/.env.example @@ -11,6 +11,8 @@ APP_URL=http://localhost:3000 ORIGIN=$APP_URL # The frequency of continuous email syncing. Default is every minutes, but you can change it to another value based on your needs. SYNC_FREQUENCY='* * * * *' +# Set to 'true' to include Junk and Trash folders in the email archive. Defaults to false. +ALL_INCLUSIVE_ARCHIVE=false # --- Docker Compose Service Configuration --- # These variables are used by docker-compose.yml to configure the services. Leave them unchanged if you use Docker services for Postgresql, Valkey (Redis) and Meilisearch. If you decide to use your own instances of these services, you can substitute them with your own connection credentials. diff --git a/docs/user-guides/installation.md b/docs/user-guides/installation.md index e1c70ef..1b66c1a 100644 --- a/docs/user-guides/installation.md +++ b/docs/user-guides/installation.md @@ -90,14 +90,15 @@ Here is a complete list of environment variables available for configuration: #### Application Settings -| Variable | Description | Default Value | -| ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------------------- | -| `NODE_ENV` | The application environment. | `development` | -| `PORT_BACKEND` | The port for the backend service. | `4000` | -| `PORT_FRONTEND` | The port for the frontend service. | `3000` | -| `APP_URL` | The public-facing URL of your application. This is used by the backend to configure CORS. | `http://localhost:3000` | -| `ORIGIN` | Used by the SvelteKit Node adapter to determine the server's public-facing URL. It should always be set to the value of `APP_URL` (e.g., `ORIGIN=$APP_URL`). | `http://localhost:3000` | -| `SYNC_FREQUENCY` | The frequency of continuous email syncing. See [cron syntax](https://crontab.guru/) for more details. | `* * * * *` | +| Variable | Description | Default Value | +| ----------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------------------- | +| `NODE_ENV` | The application environment. | `development` | +| `PORT_BACKEND` | The port for the backend service. | `4000` | +| `PORT_FRONTEND` | The port for the frontend service. | `3000` | +| `APP_URL` | The public-facing URL of your application. This is used by the backend to configure CORS. | `http://localhost:3000` | +| `ORIGIN` | Used by the SvelteKit Node adapter to determine the server's public-facing URL. It should always be set to the value of `APP_URL` (e.g., `ORIGIN=$APP_URL`). | `http://localhost:3000` | +| `SYNC_FREQUENCY` | The frequency of continuous email syncing. See [cron syntax](https://crontab.guru/) for more details. | `* * * * *` | +| `ALL_INCLUSIVE_ARCHIVE` | Set to `true` to include all emails, including Junk and Trash folders, in the email archive. | `false` | #### Docker Compose Service Configuration diff --git a/packages/backend/src/config/app.ts b/packages/backend/src/config/app.ts index 32bc760..df58659 100644 --- a/packages/backend/src/config/app.ts +++ b/packages/backend/src/config/app.ts @@ -7,4 +7,5 @@ export const app = { isDemo: process.env.IS_DEMO === 'true', syncFrequency: process.env.SYNC_FREQUENCY || '* * * * *', //default to 1 minute enableDeletion: process.env.ENABLE_DELETION === 'true', + allInclusiveArchive: process.env.ALL_INCLUSIVE_ARCHIVE === 'true', }; diff --git a/packages/backend/src/services/JobsService.ts b/packages/backend/src/services/JobsService.ts index b696d91..19d8eab 100644 --- a/packages/backend/src/services/JobsService.ts +++ b/packages/backend/src/services/JobsService.ts @@ -101,7 +101,7 @@ export class JobsService { stacktrace: job.stacktrace, returnValue: job.returnvalue, ingestionSourceId: job.data.ingestionSourceId, - error: state === 'failed' ? job.failedReason : undefined, + error: state === 'failed' ? job.stacktrace : undefined, }; } } diff --git a/packages/backend/src/services/ingestion-connectors/ImapConnector.ts b/packages/backend/src/services/ingestion-connectors/ImapConnector.ts index 2fbd024..c75fb67 100644 --- a/packages/backend/src/services/ingestion-connectors/ImapConnector.ts +++ b/packages/backend/src/services/ingestion-connectors/ImapConnector.ts @@ -8,6 +8,7 @@ import type { import type { IEmailConnector } from '../EmailProviderFactory'; import { ImapFlow } from 'imapflow'; import { simpleParser, ParsedMail, Attachment, AddressObject, Headers } from 'mailparser'; +import { config } from '../../config' import { logger } from '../../config/logger'; import { getThreadId } from './helpers/utils'; @@ -154,23 +155,23 @@ export class ImapConnector implements IEmailConnector { const mailboxes = await this.withRetry(async () => await this.client.list()); const processableMailboxes = mailboxes.filter((mailbox) => { - // filter out junk/spam and all mail emails + if (config.app.allInclusiveArchive) { + return true; + } + // filter out junk/spam mail emails if (mailbox.specialUse) { const specialUse = mailbox.specialUse.toLowerCase(); if ( specialUse === '\\junk' || - // specialUse === '\\trash' || // trash emails are usually user-deleted emails. Should be included in the archive. - specialUse === '\\all' + specialUse === '\\trash' ) { return false; } } // Fallback to checking flags if ( - mailbox.flags.has('\\Noselect') || - // mailbox.flags.has('\\Trash') || // trash emails are usually user-deleted emails. Should be included in the archive. - mailbox.flags.has('\\Junk') || - mailbox.flags.has('\\All') + mailbox.flags.has('\\Trash') || + mailbox.flags.has('\\Junk') ) { return false; }