imapflow 1.0.112 → 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,9 @@
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
+
3
7
  - 1.0.112 - 2022-10-16
4
8
 
5
9
  - Improved ID compatiblity with servers that allow ID only after login
@@ -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
  /**
@@ -331,9 +333,27 @@ class ImapFlow extends EventEmitter {
331
333
  });
332
334
  }
333
335
 
336
+ this.writeBytesCounter += chunk.length;
337
+
334
338
  this.writeSocket.write(chunk);
335
339
  }
336
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
+
337
357
  async send(data) {
338
358
  if (this.state === this.states.LOGOUT) {
339
359
  // already logged out
@@ -803,6 +823,7 @@ class ImapFlow extends EventEmitter {
803
823
 
804
824
  return resolve(true);
805
825
  });
826
+
806
827
  this.writeSocket = this.socket;
807
828
 
808
829
  this.setSocketHandlers();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "imapflow",
3
- "version": "1.0.112",
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.11.0",
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
  }