emailengine-app 2.79.4 → 2.79.6

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/lib/consts.js CHANGED
@@ -145,6 +145,17 @@ module.exports = {
145
145
  // carry is the separate, read-only `_authFailureDisabledAt`.
146
146
  AUTH_FAILURE_DISABLED_FIELD: '_authFailureDisabled',
147
147
 
148
+ // The `lastErrorState.description` the safety net stores when it parks an account, and the log
149
+ // line it writes at the same moment. User-visible copy: reword it freely, nothing matches on it.
150
+ AUTH_FAILURE_DISABLED_DESCRIPTION: 'IMAP was disabled for the account due to exceeding the authentication error threshold',
151
+
152
+ // Frozen copy of the description as every release up to 2.79.4 stored it. Releases before the
153
+ // marker above existed recorded a park as `imap.disabled` plus this text and nothing else, so
154
+ // this is the only signature those parks carry: the startup backfill and the state badge both
155
+ // match on it. It has to keep matching data written by past releases, which is why it is a
156
+ // separate constant from the live description rather than a reference to it.
157
+ AUTH_FAILURE_DISABLED_LEGACY_DESCRIPTION: 'IMAP was disabled for the account due to exceeding the authentication error threshold',
158
+
148
159
  REDIS_PREFIX: ((process.env.EENGINE_REDIS_PREFIX || '').toString().trim() + ':').replace(/^:/, ''),
149
160
 
150
161
  REDIS_BATCH_DELETE_SIZE: 1000,
@@ -70,6 +70,7 @@ const {
70
70
  MAX_INLINE_ATTACHMENT_SIZE,
71
71
  DEFAULT_MAX_IMAP_AUTH_FAILURE_TIME,
72
72
  AUTH_FAILURE_DISABLED_FIELD,
73
+ AUTH_FAILURE_DISABLED_DESCRIPTION,
73
74
  EMAIL_DELIVERY_ERROR_NOTIFY,
74
75
  EMAIL_SENT_NOTIFY
75
76
  } = require('../consts');
@@ -639,10 +640,31 @@ class BaseClient {
639
640
  // No IMAP configuration: an OAuth2 account. Only synthesize the flag when there is an
640
641
  // OAuth2 credential for the failures to be about, so an account still being created
641
642
  // cannot be marked disabled on its way in.
642
- const hasOAuth2 = await this.redis.hexists(accountKey, 'oauth2');
643
- if (!hasOAuth2) {
643
+ const oauth2Info = await this.redis.hget(accountKey, 'oauth2');
644
+ if (!oauth2Info) {
644
645
  return false;
645
646
  }
647
+
648
+ let oauth2Data;
649
+ try {
650
+ oauth2Data = JSON.parse(oauth2Info);
651
+ } catch (err) {
652
+ // an unreadable credential is not a delegation
653
+ }
654
+
655
+ if (oauth2Data?.auth?.delegatedUser && oauth2Data?.auth?.delegatedAccount) {
656
+ // A delegated account (an Outlook shared mailbox, say) has no credential of its
657
+ // own: the failures counted here are those of the account it borrows the token
658
+ // from, and re-authorizing that account would lift nothing here. Leave the park to
659
+ // the account that owns the credential, where re-authorization is the fix.
660
+ this.logger.debug({
661
+ msg: 'Skipped disabling a delegated account after authentication failures',
662
+ account: this.account,
663
+ delegatedAccount: oauth2Data.auth.delegatedAccount
664
+ });
665
+ return false;
666
+ }
667
+
646
668
  imapData = {};
647
669
  }
648
670
 
@@ -665,23 +687,40 @@ class BaseClient {
665
687
  accountKey,
666
688
  'lastErrorState',
667
689
  JSON.stringify({
668
- description: 'IMAP was disabled for the account due to exceeding the authentication error threshold',
690
+ description: AUTH_FAILURE_DISABLED_DESCRIPTION,
669
691
  response: data.response
670
692
  })
671
693
  );
672
- await disableTxn.exec();
694
+ const { error } = await disableTxn.exec();
695
+
696
+ if (error) {
697
+ // exec() reports a command-level failure in `error` rather than throwing it, so an
698
+ // unchecked call would announce a park that was never stored: the caller sends the
699
+ // "account was switched off" notification, the connection is torn down, and the flag
700
+ // the connection gates read is still absent, so the account reconnects and keeps
701
+ // hammering the provider. Say nothing happened and let the next failure retry, the same
702
+ // way clearAuthFailureDisable() treats a failed lift.
703
+ this.logger.error({ msg: 'Failed to disable IMAP for account', account: this.account, err: error });
704
+ return false;
705
+ }
673
706
 
674
707
  this.logger.warn({
675
- msg: 'IMAP was disabled for the account due to exceeding the authentication error threshold',
708
+ msg: AUTH_FAILURE_DISABLED_DESCRIPTION,
676
709
  errorEvent: event,
677
710
  firstError: firstError.toISOString(),
678
711
  timeThreshold: MAX_IMAP_AUTH_FAILURE_TIME,
679
712
  errorCount
680
713
  });
681
714
 
682
- // Close the connection after disabling
683
- setImmediate(() => {
684
- this.close();
715
+ // Close the connection after disabling. Nothing awaits this, and for the Gmail API and
716
+ // Graph clients close() is async and writes the account state, so a rejection here would
717
+ // otherwise reach the global handler and take the whole worker down with it.
718
+ setImmediate(async () => {
719
+ try {
720
+ await this.close();
721
+ } catch (err) {
722
+ this.logger.error({ msg: 'Failed to close the connection of a disabled account', account: this.account, err });
723
+ }
685
724
  });
686
725
 
687
726
  return true;
@@ -618,6 +618,12 @@ class GmailClient extends BaseClient {
618
618
  }
619
619
 
620
620
  async reconnect() {
621
+ // A closed instance can be revived here, as IMAPClient.reconnect(force) does: every timer
622
+ // and the watch setup return on `closed`, and init() does not reset it, so without this a
623
+ // reconnect after close() reported a connected account that never synced. The auth-failure
624
+ // safety net produces exactly that instance - the park closes the client but leaves it
625
+ // assigned, and switching the flag back off through PUT /v1/account reconnects it in place.
626
+ this.closed = false;
621
627
  return await this.init({ forceWatchRenewal: true });
622
628
  }
623
629
 
@@ -116,6 +116,31 @@ function notificationHeaderFields(configuredHeaders) {
116
116
  return Array.from(fetchHeaders);
117
117
  }
118
118
 
119
+ // Runs for every address of every message, so both patterns are built once
120
+ const HAS_WHITESPACE = /\s/;
121
+ // An addr-spec that carries its whitespace legally, inside a quoted local part
122
+ const QUOTED_LOCAL_ADDR = /^"(?:[^"\\]|\\[\s\S])*"@\S+$/;
123
+
124
+ /**
125
+ * Tells whether an address is usable as a mailbox.
126
+ *
127
+ * A server that failed to parse a malformed header does not always report the wreckage as
128
+ * an empty address - Gmail hands back "user@example.com user@example.com" when the header
129
+ * separated the two copies with a non-breaking space. Unquoted whitespace is not addr-spec,
130
+ * so a value carrying it is no more usable than an empty one, and the raw header is the
131
+ * better source. Whitespace inside a quoted local part is legal and stays usable.
132
+ *
133
+ * @param {String} address - Address to check
134
+ * @returns {Boolean} True if the address can be used as a mailbox
135
+ */
136
+ function isUsableAddress(address) {
137
+ if (!address) {
138
+ return false;
139
+ }
140
+
141
+ return !HAS_WHITESPACE.test(address) || QUOTED_LOCAL_ADDR.test(address);
142
+ }
143
+
119
144
  /**
120
145
  * Parses a raw address header into the address objects the API exposes.
121
146
  *
@@ -129,7 +154,7 @@ function parseAddressHeader(values) {
129
154
 
130
155
  try {
131
156
  let addressList = addressparser(values)
132
- .filter(address => !!address.address)
157
+ .filter(address => isUsableAddress(address.address))
133
158
  .map(address => {
134
159
  let name = address.name;
135
160
  try {
@@ -150,12 +175,11 @@ function parseAddressHeader(values) {
150
175
  /**
151
176
  * Picks the address list to expose for a header, preferring the server's ENVELOPE.
152
177
  *
153
- * An ENVELOPE list can come back holding no usable address at all: RFC 9051 7.5.2 group
154
- * markers carry a group name and nothing else, and a server that failed to parse a
155
- * malformed header reports the wreckage the same way, as a display name with an empty
156
- * address. The raw header is the better answer in that case, because addressparser sees
157
- * the original value and can still recover the recipient. Falling back on emptiness alone
158
- * was not enough - the broken list is not empty, just useless.
178
+ * An ENVELOPE list can come back holding no address anyone could use: RFC 9051 7.5.2 group
179
+ * markers carry a group name and nothing else, and a server that failed to parse a malformed
180
+ * header reports the wreckage in the shapes isUsableAddress() turns down. The raw header is
181
+ * the better answer then, because addressparser sees the original value and can still recover
182
+ * the recipient. A list has to be judged on what its entries hold, not on being non-empty.
159
183
  *
160
184
  * The header is parsed only when the ENVELOPE turns out to be unusable, which is rare.
161
185
  * Parsing all four address fields up front would be work discarded on every message.
@@ -166,7 +190,7 @@ function parseAddressHeader(values) {
166
190
  * @returns {Object[]|undefined} The list to expose, or undefined if neither source has one
167
191
  */
168
192
  function preferAddressList(envelopeList, headers, key) {
169
- if (envelopeList?.some(entry => entry.address)) {
193
+ if (envelopeList?.some(entry => isUsableAddress(entry.address))) {
170
194
  return envelopeList;
171
195
  }
172
196
 
@@ -483,6 +483,13 @@ class OutlookClient extends BaseClient {
483
483
  * Reconnect to the account (re-initialize)
484
484
  */
485
485
  async reconnect() {
486
+ // A closed instance can be revived here, as IMAPClient.reconnect(force) does: the
487
+ // subscription setup and the sync paths return on `closed`, and init() does not reset it,
488
+ // so without this a reconnect after close() reported a connected account that never
489
+ // received a notification. The auth-failure safety net produces exactly that instance - the
490
+ // park closes the client but leaves it assigned, and switching the flag back off through
491
+ // PUT /v1/account reconnects it in place.
492
+ this.closed = false;
486
493
  return await this.init();
487
494
  }
488
495
 
@@ -122,7 +122,7 @@ const ENUM_DESCRIPTIONS = {
122
122
  gateway: 'Manage SMTP gateways, which hold outbound SMTP credentials',
123
123
  events: 'Subscribe to the instance-wide change stream, which covers every account',
124
124
  diagnostics: 'Read statistics and service status',
125
- logs: 'Read the per-account connection log. Entries are the raw protocol trace, so they include folder names and message subjects'
125
+ logs: 'Read the per-account connection log. Entries include the protocol or API trace, so they include folder names and message subjects'
126
126
  },
127
127
 
128
128
  queueId: {
@@ -16,7 +16,7 @@ const tokens = require('../tokens');
16
16
  const { redis, documentsQueue } = require('../db');
17
17
  const getSecret = require('../get-secret');
18
18
  const capa = require('../capa');
19
- const { Account, authFailureDisabledAt } = require('../account');
19
+ const { Account, authFailureDisabledAt, isOperatorDisabled } = require('../account');
20
20
  const { Gateway } = require('../gateway');
21
21
  const { autodetectImapSettings, resolveAppPassword, getAppPassword } = require('../autodetect-imap-settings');
22
22
  const { atomicIncrement } = require('../redis-operations');
@@ -1912,7 +1912,12 @@ function init(args) {
1912
1912
 
1913
1913
  const values = Object.assign({}, flattenObjectKeys(accountData), {
1914
1914
  imap: true,
1915
- imap_disabled: (!accountData.imap && !accountData.oauth2) || (accountData.imap && accountData.imap.disabled),
1915
+ // The checkbox is the operator's own switch, so a park by the auth-failure safety
1916
+ // net does not pre-check it: the page alert promises that saving new credentials
1917
+ // turns syncing back on, and a pre-checked box would have made every such save an
1918
+ // explicit request to keep the account off. Unchecked, the connection fields are
1919
+ // shown and the save writes `disabled: false`, which lifts the park.
1920
+ imap_disabled: (!accountData.imap && !accountData.oauth2) || isOperatorDisabled(accountData),
1916
1921
  imap_tls_ignoreCertErrors: !!(accountData.imap && accountData.imap.tls && accountData.imap.tls.rejectUnauthorized === false),
1917
1922
  smtp: !!accountData.smtp,
1918
1923
  smtp_tls_ignoreCertErrors: !!(accountData.smtp && accountData.smtp.tls && accountData.smtp.tls.rejectUnauthorized === false),
@@ -19,7 +19,7 @@ const psl = require('psl');
19
19
  const settings = require('../settings');
20
20
  const { redis } = require('../db');
21
21
  const { toolGrants } = require('../mcp/tools');
22
- const { Account, accountsExist, accountSummary, authFailureDisabledAt } = require('../account');
22
+ const { Account, accountsExist, accountSummary, isAuthFailureDisabled } = require('../account');
23
23
  const { REDIS_PREFIX, DEFAULT_PAGE_SIZE } = require('../consts');
24
24
  const { oauth2ProviderData } = require('../oauth2-apps');
25
25
  const exampleDocumentsPayloads = require('../payload-examples-documents.json');
@@ -208,11 +208,11 @@ function formatAccountData(account, gt) {
208
208
  // An account the auth-failure safety net switched off reports the neutral "Not syncing", which
209
209
  // says nothing about why it stopped or that a human has to act. Override the label to say so.
210
210
  //
211
- // Keyed on the marker the safety net writes, not on `imap.disabled` plus a leftover error:
212
- // that flag is also the operator's send-only switch, so the old guess badged a deliberately
213
- // send-only account "Connection failed" if it had ever failed to connect, and stayed silent
214
- // about a parked account whose lastErrorState had been overwritten since.
215
- if (authFailureDisabledAt(account)) {
211
+ // Keyed on the marker the safety net writes, or on the exact signature the releases before the
212
+ // marker left behind, not on `imap.disabled` plus any leftover error: that flag is also the
213
+ // operator's send-only switch, so the old guess badged a deliberately send-only account
214
+ // "Connection failed" if it had ever failed to connect.
215
+ if (isAuthFailureDisabled(account)) {
216
216
  account.stateLabel = {
217
217
  type: 'error',
218
218
  name: 'Syncing switched off',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "emailengine-app",
3
- "version": "2.79.4",
3
+ "version": "2.79.6",
4
4
  "private": false,
5
5
  "productTitle": "EmailEngine",
6
6
  "description": "Email Sync Engine",
@@ -51,8 +51,8 @@
51
51
  },
52
52
  "homepage": "https://emailengine.app/",
53
53
  "dependencies": {
54
- "@bull-board/api": "9.4.0",
55
- "@bull-board/hapi": "9.4.0",
54
+ "@bull-board/api": "9.5.0",
55
+ "@bull-board/hapi": "9.5.0",
56
56
  "@elastic/elasticsearch": "8.15.3",
57
57
  "@hapi/accept": "6.0.3",
58
58
  "@hapi/bell": "13.1.0",
@@ -67,7 +67,7 @@
67
67
  "@postalsys/bounce-classifier": "3.0.0",
68
68
  "@postalsys/certs": "1.0.18",
69
69
  "@postalsys/ee-client": "1.7.0",
70
- "@postalsys/email-ai-tools": "1.13.19",
70
+ "@postalsys/email-ai-tools": "1.13.20",
71
71
  "@postalsys/email-content": "0.1.3",
72
72
  "@postalsys/email-text-tools": "2.4.14",
73
73
  "@postalsys/gettext": "4.1.1",
@@ -75,16 +75,16 @@
75
75
  "@postalsys/templates": "2.0.2",
76
76
  "@sentry/node": "10.71.0",
77
77
  "@simplewebauthn/browser": "13.3.0",
78
- "@simplewebauthn/server": "13.3.2",
78
+ "@simplewebauthn/server": "13.3.3",
79
79
  "@zone-eu/mailsplit": "5.4.15",
80
80
  "@zone-eu/wild-config": "1.7.6",
81
81
  "ace-builds": "1.44.0",
82
- "bullmq": "6.2.0",
82
+ "bullmq": "6.3.1",
83
83
  "compare-versions": "6.1.1",
84
84
  "dotenv": "17.4.2",
85
85
  "encoding-japanese": "2.2.0",
86
86
  "exponential-backoff": "3.1.3",
87
- "fast-xml-parser": "5.11.0",
87
+ "fast-xml-parser": "5.11.1",
88
88
  "gettext-parser": "7.0.1",
89
89
  "handlebars": "4.7.9",
90
90
  "hapi-auth-bearer-token": "8.0.0",
@@ -101,19 +101,19 @@
101
101
  "libbase64": "1.3.0",
102
102
  "libmime": "5.4.2",
103
103
  "libqp": "2.1.1",
104
- "mailparser": "3.9.16",
104
+ "mailparser": "3.9.17",
105
105
  "marked": "15.0.12",
106
106
  "minimist": "1.2.8",
107
107
  "murmurhash": "2.0.1",
108
108
  "nanoid": "3.3.18",
109
- "nodemailer": "9.0.5",
109
+ "nodemailer": "9.0.6",
110
110
  "pino": "10.3.1",
111
111
  "prom-client": "15.1.3",
112
112
  "psl": "1.15.0",
113
- "pubface": "1.1.6",
113
+ "pubface": "1.1.7",
114
114
  "punycode.js": "2.3.1",
115
115
  "qrcode": "1.5.4",
116
- "smtp-server": "3.19.3",
116
+ "smtp-server": "3.19.4",
117
117
  "socks": "2.8.9",
118
118
  "timezones-list": "3.1.0",
119
119
  "undici": "7.29.0"
@@ -128,11 +128,11 @@
128
128
  "acorn-walk": "8.3.5",
129
129
  "chai": "4.5.0",
130
130
  "eerawlog": "1.5.5",
131
- "eslint": "10.9.0",
131
+ "eslint": "10.9.1",
132
132
  "flyonui": "2.4.1",
133
133
  "pino-pretty": "13.1.3",
134
134
  "prettier": "3.9.6",
135
- "resedit": "3.0.2",
135
+ "resedit": "3.1.0",
136
136
  "spdx-satisfies": "6.0.0",
137
137
  "supertest": "7.2.2",
138
138
  "tailwindcss": "4.3.3",