imapflow 1.0.156 → 1.0.158

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 CHANGED
@@ -1,5 +1,19 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.0.158](https://github.com/postalsys/imapflow/compare/v1.0.157...v1.0.158) (2024-03-19)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * **locking:** log extra information about locks ([9790ec5](https://github.com/postalsys/imapflow/commit/9790ec575f405820d05dd4777987a88e0a4e819d))
9
+
10
+ ## [1.0.157](https://github.com/postalsys/imapflow/compare/v1.0.156...v1.0.157) (2024-03-19)
11
+
12
+
13
+ ### Bug Fixes
14
+
15
+ * **logs:** Log mailbox lock description ([ce87cf5](https://github.com/postalsys/imapflow/commit/ce87cf5a256ddc324624893a1c17992475fafeb3))
16
+
3
17
  ## [1.0.156](https://github.com/postalsys/imapflow/compare/v1.0.155...v1.0.156) (2024-03-07)
4
18
 
5
19
 
@@ -21,7 +21,7 @@ async function runIdle(connection) {
21
21
  src: 'c',
22
22
  msg: `DONE`,
23
23
  comment: `breaking IDLE`,
24
- lockId: connection.currentLockId,
24
+ lockId: connection.currentLock?.lockId,
25
25
  path: connection.mailbox && connection.mailbox.path
26
26
  });
27
27
  connection.write('DONE');
@@ -44,7 +44,7 @@ async function runIdle(connection) {
44
44
 
45
45
  connection.log.trace({
46
46
  msg: 'Requesting IDLE break',
47
- lockId: connection.currentLockId,
47
+ lockId: connection.currentLock?.lockId,
48
48
  path: connection.mailbox && connection.mailbox.path,
49
49
  queued: preCheckWaitQueue.length,
50
50
  doneRequested,
@@ -74,7 +74,7 @@ async function runIdle(connection) {
74
74
  if (typeof connection.preCheck === 'function') {
75
75
  connection.log.trace({
76
76
  msg: 'Clearing pre-check function',
77
- lockId: connection.currentLockId,
77
+ lockId: connection.currentLock?.lockId,
78
78
  path: connection.mailbox && connection.mailbox.path,
79
79
  queued: preCheckWaitQueue.length,
80
80
  doneRequested,
package/lib/imap-flow.js CHANGED
@@ -211,7 +211,7 @@ class ImapFlow extends EventEmitter {
211
211
  this.state = this.states.NOT_AUTHENTICATED;
212
212
 
213
213
  this.lockCounter = 0;
214
- this.currentLockId = 0;
214
+ this.currentLock = false;
215
215
 
216
216
  this.tagCounter = 0;
217
217
  this.requestTagMap = new Map();
@@ -1313,7 +1313,7 @@ class ImapFlow extends EventEmitter {
1313
1313
 
1314
1314
  await new Promise((resolve, reject) => {
1315
1315
  this.connectTimeout = setTimeout(() => {
1316
- let err = new Error('Failed to established connection in required time');
1316
+ let err = new Error('Failed to establish connection in required time');
1317
1317
  err.code = 'CONNECT_TIMEOUT';
1318
1318
  err.details = {
1319
1319
  connectionTimeout: this.options.connectionTimeout || CONNECT_TIMEOUT
@@ -2840,26 +2840,51 @@ class ImapFlow extends EventEmitter {
2840
2840
 
2841
2841
  async processLocks(force) {
2842
2842
  if (!force && this.processingLock) {
2843
+ this.log.trace({
2844
+ msg: 'Mailbox locking queued',
2845
+ path: this.mailbox && this.mailbox.path,
2846
+ pending: this.locks.length,
2847
+ idling: this.idling,
2848
+ activeLock: this.currentLock
2849
+ ? {
2850
+ lockId: this.currentLock.lockId,
2851
+ ...(this.currentLock.options?.description && { description: this.currentLock.options?.description })
2852
+ }
2853
+ : null
2854
+ });
2843
2855
  return;
2844
2856
  }
2857
+
2845
2858
  if (!this.locks.length) {
2846
2859
  this.processingLock = false;
2860
+ this.log.trace({
2861
+ msg: 'Mailbox locking queue processed',
2862
+ idling: this.idling
2863
+ });
2847
2864
  return;
2848
2865
  }
2866
+
2849
2867
  this.processingLock = true;
2850
2868
 
2851
2869
  const release = () => {
2852
- if (this.currentLockId) {
2853
- this.log.trace({ msg: 'Mailbox lock released', lockId: this.currentLockId, path: this.mailbox && this.mailbox.path });
2854
- this.currentLockId = 0;
2870
+ if (this.currentLock) {
2871
+ this.log.trace({
2872
+ msg: 'Mailbox lock released',
2873
+ lockId: this.currentLock.lockId,
2874
+ path: this.mailbox && this.mailbox.path,
2875
+ pending: this.locks.length,
2876
+ idling: this.idling
2877
+ });
2878
+ this.currentLock = false;
2855
2879
  }
2856
2880
  this.processLocks(true).catch(err => this.log.error({ err, cid: this.id }));
2857
2881
  };
2858
2882
 
2859
- const { resolve, reject, path, options, lockId } = this.locks.shift();
2883
+ const lock = this.locks.shift();
2884
+ const { resolve, reject, path, options, lockId } = lock;
2860
2885
 
2861
2886
  if (!this.usable || this.socket.destroyed) {
2862
- this.log.trace({ msg: 'Failed to acquire mailbox lock', path, lockId });
2887
+ this.log.trace({ msg: 'Failed to acquire mailbox lock', path, lockId, idling: this.idling });
2863
2888
  // reject all
2864
2889
  let error = new Error('Connection not available');
2865
2890
  error.code = 'NoConnection';
@@ -2869,15 +2894,27 @@ class ImapFlow extends EventEmitter {
2869
2894
 
2870
2895
  if (this.mailbox && this.mailbox.path === path && !!this.mailbox.readOnly === !!options.readOnly) {
2871
2896
  // nothing to do here, already selected
2872
- this.log.trace({ msg: 'Mailbox lock acquired', path, lockId });
2873
- this.currentLockId = lockId;
2897
+ this.log.trace({
2898
+ msg: 'Mailbox lock acquired [existing]',
2899
+ path,
2900
+ lockId,
2901
+ idling: this.idling,
2902
+ ...(options.description && { description: options.description })
2903
+ });
2904
+ this.currentLock = lock;
2874
2905
  return resolve({ path, release });
2875
2906
  } else {
2876
2907
  try {
2877
2908
  // Try to open. Throws if mailbox does not exists or can't open
2878
2909
  await this.mailboxOpen(path, options);
2879
- this.log.trace({ msg: 'Lock acquired', path, lockId });
2880
- this.currentLockId = lockId;
2910
+ this.log.trace({
2911
+ msg: 'Mailbox lock acquired [selected]',
2912
+ path,
2913
+ lockId,
2914
+ idling: this.idling,
2915
+ ...(options.description && { description: options.description })
2916
+ });
2917
+ this.currentLock = lock;
2881
2918
  return resolve({ path, release });
2882
2919
  } catch (err) {
2883
2920
  if (err.responseStatus === 'NO') {
@@ -2891,7 +2928,14 @@ class ImapFlow extends EventEmitter {
2891
2928
  }
2892
2929
  }
2893
2930
 
2894
- this.log.trace({ msg: 'Failed to acquire mailbox lock', path, lockId });
2931
+ this.log.trace({
2932
+ msg: 'Failed to acquire mailbox lock',
2933
+ path,
2934
+ lockId,
2935
+ idling: this.idling,
2936
+ ...(options.description && { description: options.description }),
2937
+ err
2938
+ });
2895
2939
  reject(err);
2896
2940
  await this.processLocks(true);
2897
2941
  }
@@ -2925,7 +2969,18 @@ class ImapFlow extends EventEmitter {
2925
2969
  path = normalizePath(this, path);
2926
2970
 
2927
2971
  let lockId = ++this.lockCounter;
2928
- this.log.trace({ msg: 'Requesting lock', path, lockId });
2972
+ this.log.trace({
2973
+ msg: 'Requesting lock',
2974
+ path,
2975
+ lockId,
2976
+ ...(options.description && { description: options.description }),
2977
+ activeLock: this.currentLock
2978
+ ? {
2979
+ lockId: this.currentLock.lockId,
2980
+ ...(this.currentLock.options?.description && { description: this.currentLock.options?.description })
2981
+ }
2982
+ : null
2983
+ });
2929
2984
 
2930
2985
  return await new Promise((resolve, reject) => {
2931
2986
  this.locks.push({ resolve, reject, path, options, lockId });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "imapflow",
3
- "version": "1.0.156",
3
+ "version": "1.0.158",
4
4
  "description": "IMAP Client for Node",
5
5
  "main": "./lib/imap-flow.js",
6
6
  "scripts": {
@@ -32,7 +32,7 @@
32
32
  "@babel/eslint-plugin": "7.23.5",
33
33
  "@babel/plugin-syntax-class-properties": "7.12.13",
34
34
  "@babel/preset-env": "7.24.0",
35
- "@types/node": "20.11.24",
35
+ "@types/node": "20.11.29",
36
36
  "eslint": "8.57.0",
37
37
  "eslint-config-nodemailer": "1.2.0",
38
38
  "eslint-config-prettier": "9.1.0",
@@ -52,7 +52,7 @@
52
52
  "libmime": "5.3.4",
53
53
  "libqp": "2.1.0",
54
54
  "mailsplit": "5.4.0",
55
- "nodemailer": "6.9.11",
55
+ "nodemailer": "6.9.12",
56
56
  "pino": "8.19.0",
57
57
  "socks": "2.8.1"
58
58
  }