@nocobase/plugin-workflow-mailer 2.2.16 → 2.2.18
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/dist/externalVersion.js +6 -6
- package/dist/node_modules/joi/dist/joi-browser.min.js +1 -1
- package/dist/node_modules/joi/lib/index.js +1 -1
- package/dist/node_modules/joi/lib/messages.js +35 -6
- package/dist/node_modules/joi/lib/types/keys.js +18 -1
- package/dist/node_modules/joi/lib/types/link.js +18 -2
- package/dist/node_modules/joi/lib/types/string.js +2 -2
- package/dist/node_modules/joi/package.json +1 -1
- package/dist/node_modules/nodemailer/.ncurc.js +2 -0
- package/dist/node_modules/nodemailer/.prettierignore +8 -0
- package/dist/node_modules/nodemailer/.prettierrc +12 -0
- package/dist/node_modules/nodemailer/.prettierrc.js +2 -0
- package/dist/node_modules/nodemailer/.release-please-config.json +9 -0
- package/dist/node_modules/nodemailer/eslint.config.js +88 -0
- package/dist/node_modules/nodemailer/lib/addressparser/index.js +314 -71
- package/dist/node_modules/nodemailer/lib/base64/index.js +9 -13
- package/dist/node_modules/nodemailer/lib/dkim/index.js +17 -18
- package/dist/node_modules/nodemailer/lib/dkim/message-parser.js +12 -13
- package/dist/node_modules/nodemailer/lib/dkim/relaxed-body.js +3 -3
- package/dist/node_modules/nodemailer/lib/dkim/sign.js +22 -18
- package/dist/node_modules/nodemailer/lib/errors.js +59 -0
- package/dist/node_modules/nodemailer/lib/fetch/cookies.js +14 -19
- package/dist/node_modules/nodemailer/lib/fetch/index.js +164 -27
- package/dist/node_modules/nodemailer/lib/json-transport/index.js +4 -4
- package/dist/node_modules/nodemailer/lib/mail-composer/index.js +229 -155
- package/dist/node_modules/nodemailer/lib/mailer/index.js +106 -54
- package/dist/node_modules/nodemailer/lib/mailer/mail-message.js +106 -68
- package/dist/node_modules/nodemailer/lib/mime-funcs/index.js +105 -59
- package/dist/node_modules/nodemailer/lib/mime-funcs/mime-types.js +21 -14
- package/dist/node_modules/nodemailer/lib/mime-node/index.js +389 -137
- package/dist/node_modules/nodemailer/lib/mime-node/last-newline.js +1 -1
- package/dist/node_modules/nodemailer/lib/mime-node/le-unix.js +4 -7
- package/dist/node_modules/nodemailer/lib/mime-node/le-windows.js +1 -4
- package/dist/node_modules/nodemailer/lib/nodemailer.js +1 -1
- package/dist/node_modules/nodemailer/lib/punycode/index.js +1 -1
- package/dist/node_modules/nodemailer/lib/qp/index.js +33 -22
- package/dist/node_modules/nodemailer/lib/sendmail-transport/index.js +54 -44
- package/dist/node_modules/nodemailer/lib/ses-transport/index.js +110 -193
- package/dist/node_modules/nodemailer/lib/shared/index.js +299 -240
- package/dist/node_modules/nodemailer/lib/shared/objects.js +42 -0
- package/dist/node_modules/nodemailer/lib/shared/url.js +151 -0
- package/dist/node_modules/nodemailer/lib/smtp-connection/data-stream.js +3 -6
- package/dist/node_modules/nodemailer/lib/smtp-connection/http-proxy-client.js +50 -19
- package/dist/node_modules/nodemailer/lib/smtp-connection/index.js +415 -223
- package/dist/node_modules/nodemailer/lib/smtp-pool/index.js +27 -34
- package/dist/node_modules/nodemailer/lib/smtp-pool/pool-resource.js +19 -16
- package/dist/node_modules/nodemailer/lib/smtp-transport/index.js +66 -53
- package/dist/node_modules/nodemailer/lib/stream-transport/index.js +16 -7
- package/dist/node_modules/nodemailer/lib/well-known/index.js +7 -7
- package/dist/node_modules/nodemailer/lib/well-known/services.json +328 -38
- package/dist/node_modules/nodemailer/lib/xoauth2/index.js +105 -33
- package/dist/node_modules/nodemailer/package.json +1 -1
- package/package.json +4 -4
|
@@ -6,13 +6,14 @@
|
|
|
6
6
|
const MessageParser = require('./message-parser');
|
|
7
7
|
const RelaxedBody = require('./relaxed-body');
|
|
8
8
|
const sign = require('./sign');
|
|
9
|
-
const PassThrough = require('stream')
|
|
9
|
+
const { PassThrough } = require('stream');
|
|
10
10
|
const fs = require('fs');
|
|
11
11
|
const path = require('path');
|
|
12
12
|
const crypto = require('crypto');
|
|
13
|
+
const { copyOwnKeys } = require('../shared/objects');
|
|
13
14
|
|
|
14
15
|
const DKIM_ALGO = 'sha256';
|
|
15
|
-
const MAX_MESSAGE_SIZE =
|
|
16
|
+
const MAX_MESSAGE_SIZE = 2 * 1024 * 1024; // buffer messages larger than this to disk
|
|
16
17
|
|
|
17
18
|
/*
|
|
18
19
|
// Usage:
|
|
@@ -42,7 +43,9 @@ class DKIMSigner {
|
|
|
42
43
|
this.chunks = [];
|
|
43
44
|
this.chunklen = 0;
|
|
44
45
|
this.readPos = 0;
|
|
45
|
-
this.cachePath = this.cacheDir
|
|
46
|
+
this.cachePath = this.cacheDir
|
|
47
|
+
? path.join(this.cacheDir, 'message.' + Date.now() + '-' + crypto.randomBytes(14).toString('hex'))
|
|
48
|
+
: false;
|
|
46
49
|
this.cache = false;
|
|
47
50
|
|
|
48
51
|
this.headers = false;
|
|
@@ -94,7 +97,7 @@ class DKIMSigner {
|
|
|
94
97
|
}
|
|
95
98
|
return this.createReadCache();
|
|
96
99
|
}
|
|
97
|
-
|
|
100
|
+
const chunk = this.chunks[this.readPos++];
|
|
98
101
|
if (this.output.write(chunk) === false) {
|
|
99
102
|
return this.output.once('drain', () => {
|
|
100
103
|
this.sendNextChunk();
|
|
@@ -105,13 +108,13 @@ class DKIMSigner {
|
|
|
105
108
|
|
|
106
109
|
sendSignedOutput() {
|
|
107
110
|
let keyPos = 0;
|
|
108
|
-
|
|
111
|
+
const signNextKey = () => {
|
|
109
112
|
if (keyPos >= this.keys.length) {
|
|
110
113
|
this.output.write(this.parser.rawHeaders);
|
|
111
114
|
return setImmediate(() => this.sendNextChunk());
|
|
112
115
|
}
|
|
113
|
-
|
|
114
|
-
|
|
116
|
+
const key = this.keys[keyPos++];
|
|
117
|
+
const dkimField = sign(this.headers, this.hashAlgo, this.bodyHash, {
|
|
115
118
|
domainName: key.domainName,
|
|
116
119
|
keySelector: key.keySelector,
|
|
117
120
|
privateKey: key.privateKey,
|
|
@@ -209,7 +212,7 @@ class DKIM {
|
|
|
209
212
|
}
|
|
210
213
|
|
|
211
214
|
sign(input, extraOptions) {
|
|
212
|
-
|
|
215
|
+
const output = new PassThrough();
|
|
213
216
|
let inputStream = input;
|
|
214
217
|
let writeValue = false;
|
|
215
218
|
|
|
@@ -223,18 +226,14 @@ class DKIM {
|
|
|
223
226
|
|
|
224
227
|
let options = this.options;
|
|
225
228
|
if (extraOptions && Object.keys(extraOptions).length) {
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
});
|
|
230
|
-
|
|
231
|
-
if (!(key in options)) {
|
|
232
|
-
options[key] = extraOptions[key];
|
|
233
|
-
}
|
|
234
|
-
});
|
|
229
|
+
// extraOptions is mail.data._dkim, caller supplied message data. An own
|
|
230
|
+
// "__proto__" key there would let every option this signer reads and the
|
|
231
|
+
// transport did not set, such as skipFields, answer from the caller
|
|
232
|
+
options = copyOwnKeys({}, extraOptions);
|
|
233
|
+
copyOwnKeys(options, this.options);
|
|
235
234
|
}
|
|
236
235
|
|
|
237
|
-
|
|
236
|
+
const signer = new DKIMSigner(options, this.keys, inputStream, output);
|
|
238
237
|
setImmediate(() => {
|
|
239
238
|
signer.signStream();
|
|
240
239
|
if (writeValue) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const Transform = require('stream')
|
|
3
|
+
const { Transform } = require('stream');
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* MessageParser instance is a transform stream that separates message headers
|
|
@@ -24,8 +24,8 @@ class MessageParser extends Transform {
|
|
|
24
24
|
* @param {Buffer} data Next data chunk from the stream
|
|
25
25
|
*/
|
|
26
26
|
updateLastBytes(data) {
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
const lblen = this.lastBytes.length;
|
|
28
|
+
const nblen = Math.min(data.length, lblen);
|
|
29
29
|
|
|
30
30
|
// shift existing bytes
|
|
31
31
|
for (let i = 0, len = lblen - nblen; i < len; i++) {
|
|
@@ -50,9 +50,8 @@ class MessageParser extends Transform {
|
|
|
50
50
|
return true;
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
|
|
53
|
+
const lblen = this.lastBytes.length;
|
|
54
54
|
let headerPos = 0;
|
|
55
|
-
this.curLinePos = 0;
|
|
56
55
|
for (let i = 0, len = this.lastBytes.length + data.length; i < len; i++) {
|
|
57
56
|
let chr;
|
|
58
57
|
if (i < lblen) {
|
|
@@ -61,8 +60,8 @@ class MessageParser extends Transform {
|
|
|
61
60
|
chr = data[i - lblen];
|
|
62
61
|
}
|
|
63
62
|
if (chr === 0x0a && i) {
|
|
64
|
-
|
|
65
|
-
|
|
63
|
+
const pr1 = i - 1 < lblen ? this.lastBytes[i - 1] : data[i - 1 - lblen];
|
|
64
|
+
const pr2 = i > 1 ? (i - 2 < lblen ? this.lastBytes[i - 2] : data[i - 2 - lblen]) : false;
|
|
66
65
|
if (pr1 === 0x0a) {
|
|
67
66
|
this.headersParsed = true;
|
|
68
67
|
headerPos = i - lblen + 1;
|
|
@@ -83,17 +82,17 @@ class MessageParser extends Transform {
|
|
|
83
82
|
this.headerChunks = null;
|
|
84
83
|
this.emit('headers', this.parseHeaders());
|
|
85
84
|
if (data.length - 1 > headerPos) {
|
|
86
|
-
|
|
85
|
+
const chunk = data.slice(headerPos);
|
|
87
86
|
this.bodySize += chunk.length;
|
|
88
87
|
// this would be the first chunk of data sent downstream
|
|
89
88
|
setImmediate(() => this.push(chunk));
|
|
90
89
|
}
|
|
91
90
|
return false;
|
|
92
|
-
} else {
|
|
93
|
-
this.headerBytes += data.length;
|
|
94
|
-
this.headerChunks.push(data);
|
|
95
91
|
}
|
|
96
92
|
|
|
93
|
+
this.headerBytes += data.length;
|
|
94
|
+
this.headerChunks.push(data);
|
|
95
|
+
|
|
97
96
|
// store last 4 bytes to catch header break
|
|
98
97
|
this.updateLastBytes(data);
|
|
99
98
|
|
|
@@ -127,7 +126,7 @@ class MessageParser extends Transform {
|
|
|
127
126
|
|
|
128
127
|
_flush(callback) {
|
|
129
128
|
if (this.headerChunks) {
|
|
130
|
-
|
|
129
|
+
const chunk = Buffer.concat(this.headerChunks, this.headerBytes);
|
|
131
130
|
this.bodySize += chunk.length;
|
|
132
131
|
this.push(chunk);
|
|
133
132
|
this.headerChunks = null;
|
|
@@ -136,7 +135,7 @@ class MessageParser extends Transform {
|
|
|
136
135
|
}
|
|
137
136
|
|
|
138
137
|
parseHeaders() {
|
|
139
|
-
|
|
138
|
+
const lines = (this.rawHeaders || '').toString().split(/\r?\n/);
|
|
140
139
|
for (let i = lines.length - 1; i > 0; i--) {
|
|
141
140
|
if (/^\s/.test(lines[i])) {
|
|
142
141
|
lines[i - 1] += '\n' + lines[i];
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
// streams through a message body and calculates relaxed body hash
|
|
4
4
|
|
|
5
|
-
const Transform = require('stream')
|
|
5
|
+
const { Transform } = require('stream');
|
|
6
6
|
const crypto = require('crypto');
|
|
7
7
|
|
|
8
8
|
class RelaxedBody extends Transform {
|
|
@@ -11,7 +11,7 @@ class RelaxedBody extends Transform {
|
|
|
11
11
|
options = options || {};
|
|
12
12
|
this.chunkBuffer = [];
|
|
13
13
|
this.chunkBufferLen = 0;
|
|
14
|
-
this.bodyHash = crypto.createHash(options.hashAlgo || '
|
|
14
|
+
this.bodyHash = crypto.createHash(options.hashAlgo || 'sha256');
|
|
15
15
|
this.remainder = '';
|
|
16
16
|
this.byteLength = 0;
|
|
17
17
|
|
|
@@ -29,7 +29,7 @@ class RelaxedBody extends Transform {
|
|
|
29
29
|
// If we get another chunk that does not match this description then we can restore the previously processed data
|
|
30
30
|
let state = 'file';
|
|
31
31
|
for (let i = chunk.length - 1; i >= 0; i--) {
|
|
32
|
-
|
|
32
|
+
const c = chunk[i];
|
|
33
33
|
|
|
34
34
|
if (state === 'file' && (c === 0x0a || c === 0x0d)) {
|
|
35
35
|
// do nothing, found \n or \r at the end of chunk, stil end of file
|
|
@@ -20,7 +20,7 @@ module.exports = (headers, hashAlgo, bodyHash, options) => {
|
|
|
20
20
|
options = options || {};
|
|
21
21
|
|
|
22
22
|
// all listed fields from RFC4871 #5.5
|
|
23
|
-
|
|
23
|
+
const defaultFieldNames =
|
|
24
24
|
'From:Sender:Reply-To:Subject:Date:Message-ID:To:' +
|
|
25
25
|
'Cc:MIME-Version:Content-Type:Content-Transfer-Encoding:Content-ID:' +
|
|
26
26
|
'Content-Description:Resent-Date:Resent-From:Resent-Sender:' +
|
|
@@ -28,20 +28,19 @@ module.exports = (headers, hashAlgo, bodyHash, options) => {
|
|
|
28
28
|
'List-Id:List-Help:List-Unsubscribe:List-Subscribe:List-Post:' +
|
|
29
29
|
'List-Owner:List-Archive';
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
const fieldNames = options.headerFieldNames || defaultFieldNames;
|
|
32
32
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
let signer, signature;
|
|
33
|
+
const canonicalizedHeaderData = relaxedHeaders(headers, fieldNames, options.skipFields);
|
|
34
|
+
const dkimHeader = generateDKIMHeader(options.domainName, options.keySelector, canonicalizedHeaderData.fieldNames, hashAlgo, bodyHash);
|
|
37
35
|
|
|
38
36
|
canonicalizedHeaderData.headers += 'dkim-signature:' + relaxedHeaderLine(dkimHeader);
|
|
39
37
|
|
|
40
|
-
signer = crypto.createSign(('rsa-' + hashAlgo).toUpperCase());
|
|
38
|
+
const signer = crypto.createSign(('rsa-' + hashAlgo).toUpperCase());
|
|
41
39
|
signer.update(canonicalizedHeaderData.headers);
|
|
40
|
+
let signature;
|
|
42
41
|
try {
|
|
43
42
|
signature = signer.sign(options.privateKey, 'base64');
|
|
44
|
-
} catch (
|
|
43
|
+
} catch (_E) {
|
|
45
44
|
return false;
|
|
46
45
|
}
|
|
47
46
|
|
|
@@ -51,24 +50,29 @@ module.exports = (headers, hashAlgo, bodyHash, options) => {
|
|
|
51
50
|
module.exports.relaxedHeaders = relaxedHeaders;
|
|
52
51
|
|
|
53
52
|
function generateDKIMHeader(domainName, keySelector, fieldNames, hashAlgo, bodyHash) {
|
|
54
|
-
|
|
53
|
+
// the caller supplied tag values are interpolated straight into the tag list, and none of
|
|
54
|
+
// them has any way to carry a control char, DEL, or one of the delimiters that would close
|
|
55
|
+
// the value and open a tag of its own
|
|
56
|
+
const cleanTagValue = value => (value || '').toString().replace(/[\x00-\x1f\x7f;=]/g, '');
|
|
57
|
+
|
|
58
|
+
const dkim = [
|
|
55
59
|
'v=1',
|
|
56
60
|
'a=rsa-' + hashAlgo,
|
|
57
61
|
'c=relaxed/relaxed',
|
|
58
|
-
'd=' + punycode.toASCII(domainName),
|
|
62
|
+
'd=' + punycode.toASCII(cleanTagValue(domainName)),
|
|
59
63
|
'q=dns/txt',
|
|
60
|
-
's=' + keySelector,
|
|
64
|
+
's=' + cleanTagValue(keySelector),
|
|
61
65
|
'bh=' + bodyHash,
|
|
62
|
-
'h=' + fieldNames
|
|
66
|
+
'h=' + cleanTagValue(fieldNames)
|
|
63
67
|
].join('; ');
|
|
64
68
|
|
|
65
69
|
return mimeFuncs.foldLines('DKIM-Signature: ' + dkim, 76) + ';\r\n b=';
|
|
66
70
|
}
|
|
67
71
|
|
|
68
72
|
function relaxedHeaders(headers, fieldNames, skipFields) {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
73
|
+
const includedFields = new Set();
|
|
74
|
+
const skip = new Set();
|
|
75
|
+
const headerFields = new Map();
|
|
72
76
|
|
|
73
77
|
(skipFields || '')
|
|
74
78
|
.toLowerCase()
|
|
@@ -86,15 +90,15 @@ function relaxedHeaders(headers, fieldNames, skipFields) {
|
|
|
86
90
|
});
|
|
87
91
|
|
|
88
92
|
for (let i = headers.length - 1; i >= 0; i--) {
|
|
89
|
-
|
|
93
|
+
const line = headers[i];
|
|
90
94
|
// only include the first value from bottom to top
|
|
91
95
|
if (includedFields.has(line.key) && !headerFields.has(line.key)) {
|
|
92
96
|
headerFields.set(line.key, relaxedHeaderLine(line.line));
|
|
93
97
|
}
|
|
94
98
|
}
|
|
95
99
|
|
|
96
|
-
|
|
97
|
-
|
|
100
|
+
const headersList = [];
|
|
101
|
+
const fields = [];
|
|
98
102
|
includedFields.forEach(field => {
|
|
99
103
|
if (headerFields.has(field)) {
|
|
100
104
|
fields.push(field);
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Nodemailer Error Codes
|
|
5
|
+
*
|
|
6
|
+
* Centralized error code definitions for consistent error handling.
|
|
7
|
+
*
|
|
8
|
+
* Usage:
|
|
9
|
+
* const errors = require('./errors');
|
|
10
|
+
* let err = new Error('Connection closed');
|
|
11
|
+
* err.code = errors.ECONNECTION;
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Error code descriptions for documentation and debugging
|
|
16
|
+
*/
|
|
17
|
+
const ERROR_CODES = {
|
|
18
|
+
// Connection errors
|
|
19
|
+
ECONNECTION: 'Connection closed unexpectedly',
|
|
20
|
+
ETIMEDOUT: 'Connection or operation timed out',
|
|
21
|
+
ESOCKET: 'Socket-level error',
|
|
22
|
+
EDNS: 'DNS resolution failed',
|
|
23
|
+
|
|
24
|
+
// TLS/Security errors
|
|
25
|
+
ETLS: 'TLS handshake or STARTTLS failed',
|
|
26
|
+
EREQUIRETLS: 'REQUIRETLS not supported by server (RFC 8689)',
|
|
27
|
+
|
|
28
|
+
// Protocol errors
|
|
29
|
+
EPROTOCOL: 'Invalid SMTP server response',
|
|
30
|
+
EENVELOPE: 'Invalid mail envelope (sender or recipients)',
|
|
31
|
+
EMESSAGE: 'Message delivery error',
|
|
32
|
+
ESTREAM: 'Stream processing error',
|
|
33
|
+
|
|
34
|
+
// Authentication errors
|
|
35
|
+
EAUTH: 'Authentication failed',
|
|
36
|
+
ENOAUTH: 'Authentication credentials not provided',
|
|
37
|
+
EOAUTH2: 'OAuth2 token generation or refresh error',
|
|
38
|
+
|
|
39
|
+
// Resource errors
|
|
40
|
+
EMAXLIMIT: 'Pool resource limit reached (max messages per connection)',
|
|
41
|
+
EMAXRECIPIENTS: 'Recipient count exceeds maxRecipients',
|
|
42
|
+
|
|
43
|
+
// Transport-specific errors
|
|
44
|
+
ESENDMAIL: 'Sendmail command error',
|
|
45
|
+
ESES: 'AWS SES transport error',
|
|
46
|
+
|
|
47
|
+
// Configuration and access errors
|
|
48
|
+
ECONFIG: 'Invalid configuration',
|
|
49
|
+
EPROXY: 'Proxy connection error',
|
|
50
|
+
EFILEACCESS: 'File access rejected (disableFileAccess is set)',
|
|
51
|
+
EURLACCESS: 'URL access rejected (disableUrlAccess is set)',
|
|
52
|
+
EFETCH: 'HTTP fetch error'
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
// Export error codes as string constants and the full definitions object
|
|
56
|
+
module.exports = { ERROR_CODES };
|
|
57
|
+
for (const code of Object.keys(ERROR_CODES)) {
|
|
58
|
+
module.exports[code] = code;
|
|
59
|
+
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
// module to handle cookies
|
|
4
4
|
|
|
5
|
-
const urllib = require('url');
|
|
5
|
+
const urllib = require('../shared/url');
|
|
6
6
|
|
|
7
7
|
const SESSION_TIMEOUT = 1800; // 30 min
|
|
8
8
|
|
|
@@ -25,8 +25,8 @@ class Cookies {
|
|
|
25
25
|
* @param {String} url Current URL
|
|
26
26
|
*/
|
|
27
27
|
set(cookieStr, url) {
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
const urlparts = urllib.parse(url || '');
|
|
29
|
+
const cookie = this.parse(cookieStr);
|
|
30
30
|
let domain;
|
|
31
31
|
|
|
32
32
|
if (cookie.domain) {
|
|
@@ -76,15 +76,13 @@ class Cookies {
|
|
|
76
76
|
* @returns {Array} An array of cookie objects
|
|
77
77
|
*/
|
|
78
78
|
list(url) {
|
|
79
|
-
|
|
80
|
-
let i;
|
|
81
|
-
let cookie;
|
|
79
|
+
const result = [];
|
|
82
80
|
|
|
83
|
-
for (i = this.cookies.length - 1; i >= 0; i--) {
|
|
84
|
-
cookie = this.cookies[i];
|
|
81
|
+
for (let i = this.cookies.length - 1; i >= 0; i--) {
|
|
82
|
+
const cookie = this.cookies[i];
|
|
85
83
|
|
|
86
84
|
if (this.isExpired(cookie)) {
|
|
87
|
-
this.cookies.splice(i,
|
|
85
|
+
this.cookies.splice(i, 1);
|
|
88
86
|
continue;
|
|
89
87
|
}
|
|
90
88
|
|
|
@@ -103,14 +101,14 @@ class Cookies {
|
|
|
103
101
|
* @returns {Object} Cookie object
|
|
104
102
|
*/
|
|
105
103
|
parse(cookieStr) {
|
|
106
|
-
|
|
104
|
+
const cookie = {};
|
|
107
105
|
|
|
108
106
|
(cookieStr || '')
|
|
109
107
|
.toString()
|
|
110
108
|
.split(';')
|
|
111
109
|
.forEach(cookiePart => {
|
|
112
|
-
|
|
113
|
-
|
|
110
|
+
const valueParts = cookiePart.split('=');
|
|
111
|
+
const key = valueParts.shift().trim().toLowerCase();
|
|
114
112
|
let value = valueParts.join('=').trim();
|
|
115
113
|
let domain;
|
|
116
114
|
|
|
@@ -171,7 +169,7 @@ class Cookies {
|
|
|
171
169
|
* @returns {Boolean} true if cookie is valid for specifiec URL
|
|
172
170
|
*/
|
|
173
171
|
match(cookie, url) {
|
|
174
|
-
|
|
172
|
+
const urlparts = urllib.parse(url || '');
|
|
175
173
|
|
|
176
174
|
// check if hostname matches
|
|
177
175
|
// .foo.com also matches subdomains, foo.com does not
|
|
@@ -183,7 +181,7 @@ class Cookies {
|
|
|
183
181
|
}
|
|
184
182
|
|
|
185
183
|
// check if path matches
|
|
186
|
-
|
|
184
|
+
const path = this.getPath(urlparts.pathname);
|
|
187
185
|
if (path.substr(0, cookie.path.length) !== cookie.path) {
|
|
188
186
|
return false;
|
|
189
187
|
}
|
|
@@ -202,16 +200,13 @@ class Cookies {
|
|
|
202
200
|
* @param {Object} cookie Cookie value to be stored
|
|
203
201
|
*/
|
|
204
202
|
add(cookie) {
|
|
205
|
-
let i;
|
|
206
|
-
let len;
|
|
207
|
-
|
|
208
203
|
// nothing to do here
|
|
209
204
|
if (!cookie || !cookie.name) {
|
|
210
205
|
return false;
|
|
211
206
|
}
|
|
212
207
|
|
|
213
208
|
// overwrite if has same params
|
|
214
|
-
for (i = 0, len = this.cookies.length; i < len; i++) {
|
|
209
|
+
for (let i = 0, len = this.cookies.length; i < len; i++) {
|
|
215
210
|
if (this.compare(this.cookies[i], cookie)) {
|
|
216
211
|
// check if the cookie needs to be removed instead
|
|
217
212
|
if (this.isExpired(cookie)) {
|
|
@@ -240,7 +235,7 @@ class Cookies {
|
|
|
240
235
|
* @returns {Boolean} True, if the cookies are the same
|
|
241
236
|
*/
|
|
242
237
|
compare(a, b) {
|
|
243
|
-
return a.name === b.name && a.path === b.path && a.domain === b.domain && a.secure === b.secure && a.httponly ===
|
|
238
|
+
return a.name === b.name && a.path === b.path && a.domain === b.domain && a.secure === b.secure && a.httponly === b.httponly;
|
|
244
239
|
}
|
|
245
240
|
|
|
246
241
|
/**
|