imapflow 1.0.111 → 1.0.113

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,13 @@
1
1
  # CHANGELOG
2
2
 
3
+ - 1.0.113 - 2022-10-21
4
+
5
+ - Added `stats()` method to get the count of bytes sent and received
6
+
7
+ - 1.0.112 - 2022-10-16
8
+
9
+ - Improved ID compatiblity with servers that allow ID only after login
10
+
3
11
  - 1.0.111 - 2022-10-13
4
12
 
5
13
  - Added new connection options
@@ -32,6 +32,8 @@ class ImapStream extends Transform {
32
32
  cid: this.cid
33
33
  });
34
34
 
35
+ this.readBytesCounter = 0;
36
+
35
37
  this.state = LINE;
36
38
  this.literalWaiting = 0;
37
39
  this.inputBuffer = []; // lines
@@ -197,6 +199,12 @@ class ImapStream extends Transform {
197
199
  chunk = Buffer.from(chunk, encoding);
198
200
  }
199
201
 
202
+ if (!chunk || !chunk.length) {
203
+ return next();
204
+ }
205
+
206
+ this.readBytesCounter += chunk.length;
207
+
200
208
  if (this.options.logRaw) {
201
209
  this.log.trace({
202
210
  src: 's',
package/lib/imap-flow.js CHANGED
@@ -207,6 +207,8 @@ class ImapFlow extends EventEmitter {
207
207
  this.requestQueue = [];
208
208
  this.currentRequest = false;
209
209
 
210
+ this.writeBytesCounter = 0;
211
+
210
212
  this.commandParts = [];
211
213
 
212
214
  /**
@@ -268,6 +270,8 @@ class ImapFlow extends EventEmitter {
268
270
  this.currentLock = false;
269
271
  this.locks = [];
270
272
 
273
+ this.idRequested = false;
274
+
271
275
  this.maxIdleTime = this.options.maxIdleTime || false;
272
276
 
273
277
  this.disableBinary = !!this.options.disableBinary;
@@ -329,9 +333,27 @@ class ImapFlow extends EventEmitter {
329
333
  });
330
334
  }
331
335
 
336
+ this.writeBytesCounter += chunk.length;
337
+
332
338
  this.writeSocket.write(chunk);
333
339
  }
334
340
 
341
+ stats(reset) {
342
+ let result = {
343
+ sent: this.writeBytesCounter || 0,
344
+ received: (this.streamer && this.streamer.readBytesCounter) || 0
345
+ };
346
+
347
+ if (reset) {
348
+ this.writeBytesCounter = 0;
349
+ if (this.streamer) {
350
+ this.streamer.readBytesCounter = 0;
351
+ }
352
+ }
353
+
354
+ return result;
355
+ }
356
+
335
357
  async send(data) {
336
358
  if (this.state === this.states.LOGOUT) {
337
359
  // already logged out
@@ -613,7 +635,10 @@ class ImapFlow extends EventEmitter {
613
635
 
614
636
  async startSession() {
615
637
  await this.run('CAPABILITY');
616
- await this.run('ID', this.clientInfo);
638
+
639
+ if (this.capabilities.has('ID')) {
640
+ this.idRequested = await this.run('ID', this.clientInfo);
641
+ }
617
642
 
618
643
  // try to use STARTTLS is possible
619
644
  if (!this.secureConnection) {
@@ -626,6 +651,11 @@ class ImapFlow extends EventEmitter {
626
651
  return await this.logout();
627
652
  }
628
653
 
654
+ if (!this.idRequested && this.capabilities.has('ID')) {
655
+ // re-request ID after LOGIN
656
+ this.idRequested = await this.run('ID', this.clientInfo);
657
+ }
658
+
629
659
  // Make sure we have namespace set. This should also throw if Exchange actually failed authentication
630
660
  let nsResponse = await this.run('NAMESPACE');
631
661
  if (nsResponse && nsResponse.error && nsResponse.status === 'BAD' && /User is authenticated but not connected/i.test(nsResponse.text)) {
@@ -793,6 +823,7 @@ class ImapFlow extends EventEmitter {
793
823
 
794
824
  return resolve(true);
795
825
  });
826
+
796
827
  this.writeSocket = this.socket;
797
828
 
798
829
  this.setSocketHandlers();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "imapflow",
3
- "version": "1.0.111",
3
+ "version": "1.0.113",
4
4
  "description": "IMAP Client for Node",
5
5
  "main": "./lib/imap-flow.js",
6
6
  "scripts": {
@@ -31,7 +31,7 @@
31
31
  "@babel/eslint-plugin": "7.19.1",
32
32
  "@babel/plugin-syntax-class-properties": "7.12.13",
33
33
  "@babel/preset-env": "7.19.4",
34
- "@types/node": "18.8.5",
34
+ "@types/node": "18.11.3",
35
35
  "braintree-jsdoc-template": "3.3.0",
36
36
  "eslint": "8.25.0",
37
37
  "eslint-config-nodemailer": "1.2.0",
@@ -52,7 +52,7 @@
52
52
  "libqp": "1.1.0",
53
53
  "mailsplit": "5.3.2",
54
54
  "nodemailer": "6.8.0",
55
- "pino": "8.6.1",
55
+ "pino": "8.7.0",
56
56
  "socks": "2.7.1"
57
57
  }
58
58
  }