@nocobase/plugin-workflow-mailer 2.4.0-alpha.1 → 2.4.0-alpha.10
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/dist/cjs/addressparser/index.d.ts +59 -0
- package/dist/node_modules/nodemailer/dist/cjs/addressparser/index.js +790 -0
- package/dist/node_modules/nodemailer/dist/cjs/base64/index.d.ts +36 -0
- package/dist/node_modules/nodemailer/dist/cjs/base64/index.js +119 -0
- package/dist/node_modules/nodemailer/dist/cjs/dkim/index.d.ts +52 -0
- package/dist/node_modules/nodemailer/dist/cjs/dkim/index.js +228 -0
- package/dist/node_modules/nodemailer/dist/cjs/dkim/message-parser.d.ts +48 -0
- package/dist/node_modules/nodemailer/dist/cjs/dkim/message-parser.js +180 -0
- package/dist/node_modules/nodemailer/dist/cjs/dkim/relaxed-body.d.ts +36 -0
- package/dist/node_modules/nodemailer/dist/cjs/dkim/relaxed-body.js +148 -0
- package/dist/node_modules/nodemailer/dist/cjs/dkim/sign.d.ts +52 -0
- package/dist/node_modules/nodemailer/dist/cjs/dkim/sign.js +165 -0
- package/dist/node_modules/nodemailer/dist/cjs/errors.d.ts +96 -0
- package/dist/node_modules/nodemailer/dist/cjs/errors.js +70 -0
- package/dist/node_modules/nodemailer/dist/cjs/fetch/cookies.d.ts +107 -0
- package/dist/node_modules/nodemailer/dist/cjs/fetch/cookies.js +282 -0
- package/dist/node_modules/nodemailer/dist/cjs/fetch/index.d.ts +65 -0
- package/dist/node_modules/nodemailer/dist/cjs/fetch/index.js +384 -0
- package/dist/node_modules/nodemailer/dist/cjs/json-transport/index.d.ts +64 -0
- package/dist/node_modules/nodemailer/dist/cjs/json-transport/index.js +99 -0
- package/dist/node_modules/nodemailer/dist/cjs/mail-composer/index.d.ts +174 -0
- package/dist/node_modules/nodemailer/dist/cjs/mail-composer/index.js +613 -0
- package/dist/node_modules/nodemailer/dist/cjs/mailer/index.d.ts +237 -0
- package/dist/node_modules/nodemailer/dist/cjs/mailer/index.js +415 -0
- package/dist/node_modules/nodemailer/dist/cjs/mailer/mail-message.d.ts +97 -0
- package/dist/node_modules/nodemailer/dist/cjs/mailer/mail-message.js +342 -0
- package/dist/node_modules/nodemailer/dist/cjs/mime-funcs/index.d.ts +161 -0
- package/dist/node_modules/nodemailer/dist/cjs/mime-funcs/index.js +787 -0
- package/dist/node_modules/nodemailer/dist/cjs/mime-funcs/mime-types.d.ts +2 -0
- package/dist/node_modules/nodemailer/dist/cjs/mime-funcs/mime-types.js +2103 -0
- package/dist/node_modules/nodemailer/dist/cjs/mime-node/index.d.ts +333 -0
- package/dist/node_modules/nodemailer/dist/cjs/mime-node/index.js +1493 -0
- package/dist/node_modules/nodemailer/dist/cjs/mime-node/last-newline.d.ts +5 -0
- package/dist/node_modules/nodemailer/dist/cjs/mime-node/last-newline.js +32 -0
- package/dist/node_modules/nodemailer/dist/cjs/mime-node/le-unix.d.ts +9 -0
- package/dist/node_modules/nodemailer/dist/cjs/mime-node/le-unix.js +40 -0
- package/dist/node_modules/nodemailer/dist/cjs/mime-node/le-windows.d.ts +10 -0
- package/dist/node_modules/nodemailer/dist/cjs/mime-node/le-windows.js +47 -0
- package/dist/node_modules/nodemailer/dist/cjs/nodemailer.d.ts +124 -0
- package/dist/node_modules/nodemailer/dist/cjs/nodemailer.js +1 -0
- package/dist/node_modules/nodemailer/dist/cjs/package-info.d.ts +3 -0
- package/dist/node_modules/nodemailer/dist/cjs/package-info.js +7 -0
- package/dist/node_modules/nodemailer/dist/cjs/package.json +3 -0
- package/dist/node_modules/nodemailer/dist/cjs/punycode/index.d.ts +73 -0
- package/dist/node_modules/nodemailer/{lib → dist/cjs}/punycode/index.js +63 -112
- package/dist/node_modules/nodemailer/dist/cjs/qp/index.d.ts +32 -0
- package/dist/node_modules/nodemailer/dist/cjs/qp/index.js +207 -0
- package/dist/node_modules/nodemailer/dist/cjs/sendmail-transport/index.d.ts +69 -0
- package/dist/node_modules/nodemailer/dist/cjs/sendmail-transport/index.js +210 -0
- package/dist/node_modules/nodemailer/dist/cjs/ses-transport/index.d.ts +112 -0
- package/dist/node_modules/nodemailer/dist/cjs/ses-transport/index.js +252 -0
- package/dist/node_modules/nodemailer/dist/cjs/shared/index.d.ts +260 -0
- package/dist/node_modules/nodemailer/dist/cjs/shared/index.js +680 -0
- package/dist/node_modules/nodemailer/dist/cjs/shared/objects.d.ts +23 -0
- package/dist/node_modules/nodemailer/dist/cjs/shared/objects.js +43 -0
- package/dist/node_modules/nodemailer/dist/cjs/shared/url.d.ts +21 -0
- package/dist/node_modules/nodemailer/dist/cjs/shared/url.js +255 -0
- package/dist/node_modules/nodemailer/dist/cjs/smtp-connection/data-stream.d.ts +15 -0
- package/dist/node_modules/nodemailer/dist/cjs/smtp-connection/data-stream.js +108 -0
- package/dist/node_modules/nodemailer/dist/cjs/smtp-connection/http-proxy-client.d.ts +47 -0
- package/dist/node_modules/nodemailer/dist/cjs/smtp-connection/http-proxy-client.js +189 -0
- package/dist/node_modules/nodemailer/dist/cjs/smtp-connection/index.d.ts +416 -0
- package/dist/node_modules/nodemailer/dist/cjs/smtp-connection/index.js +1837 -0
- package/dist/node_modules/nodemailer/dist/cjs/smtp-pool/index.d.ts +133 -0
- package/dist/node_modules/nodemailer/dist/cjs/smtp-pool/index.js +569 -0
- package/dist/node_modules/nodemailer/dist/cjs/smtp-pool/pool-resource.d.ts +62 -0
- package/dist/node_modules/nodemailer/dist/cjs/smtp-pool/pool-resource.js +257 -0
- package/dist/node_modules/nodemailer/dist/cjs/smtp-transport/index.d.ts +156 -0
- package/dist/node_modules/nodemailer/dist/cjs/smtp-transport/index.js +371 -0
- package/dist/node_modules/nodemailer/dist/cjs/stream-transport/index.d.ts +65 -0
- package/dist/node_modules/nodemailer/dist/cjs/stream-transport/index.js +146 -0
- package/dist/node_modules/nodemailer/dist/cjs/well-known/index.d.ts +35 -0
- package/dist/node_modules/nodemailer/dist/cjs/well-known/index.js +41 -0
- package/dist/node_modules/nodemailer/dist/cjs/well-known/services.d.ts +2 -0
- package/dist/node_modules/nodemailer/dist/cjs/well-known/services.js +674 -0
- package/dist/node_modules/nodemailer/dist/cjs/xoauth2/index.d.ts +201 -0
- package/dist/node_modules/nodemailer/dist/cjs/xoauth2/index.js +426 -0
- package/dist/node_modules/nodemailer/dist/esm/addressparser/index.d.ts +59 -0
- package/dist/node_modules/nodemailer/dist/esm/addressparser/index.js +786 -0
- package/dist/node_modules/nodemailer/dist/esm/base64/index.d.ts +36 -0
- package/dist/node_modules/nodemailer/{lib → dist/esm}/base64/index.js +39 -68
- package/dist/node_modules/nodemailer/dist/esm/dkim/index.d.ts +52 -0
- package/dist/node_modules/nodemailer/{lib → dist/esm}/dkim/index.js +62 -92
- package/dist/node_modules/nodemailer/dist/esm/dkim/message-parser.d.ts +48 -0
- package/dist/node_modules/nodemailer/dist/esm/dkim/message-parser.js +176 -0
- package/dist/node_modules/nodemailer/dist/esm/dkim/relaxed-body.d.ts +36 -0
- package/dist/node_modules/nodemailer/dist/esm/dkim/relaxed-body.js +141 -0
- package/dist/node_modules/nodemailer/dist/esm/dkim/sign.d.ts +52 -0
- package/dist/node_modules/nodemailer/dist/esm/dkim/sign.js +125 -0
- package/dist/node_modules/nodemailer/dist/esm/errors.d.ts +96 -0
- package/dist/node_modules/nodemailer/dist/esm/errors.js +67 -0
- package/dist/node_modules/nodemailer/dist/esm/fetch/cookies.d.ts +107 -0
- package/dist/node_modules/nodemailer/dist/esm/fetch/cookies.js +242 -0
- package/dist/node_modules/nodemailer/dist/esm/fetch/index.d.ts +65 -0
- package/dist/node_modules/nodemailer/dist/esm/fetch/index.js +344 -0
- package/dist/node_modules/nodemailer/dist/esm/json-transport/index.d.ts +64 -0
- package/dist/node_modules/nodemailer/dist/esm/json-transport/index.js +62 -0
- package/dist/node_modules/nodemailer/dist/esm/mail-composer/index.d.ts +174 -0
- package/dist/node_modules/nodemailer/{lib → dist/esm}/mail-composer/index.js +283 -275
- package/dist/node_modules/nodemailer/dist/esm/mailer/index.d.ts +237 -0
- package/dist/node_modules/nodemailer/{lib → dist/esm}/mailer/index.js +151 -205
- package/dist/node_modules/nodemailer/dist/esm/mailer/mail-message.d.ts +97 -0
- package/dist/node_modules/nodemailer/{lib → dist/esm}/mailer/mail-message.js +111 -125
- package/dist/node_modules/nodemailer/dist/esm/mime-funcs/index.d.ts +161 -0
- package/dist/node_modules/nodemailer/dist/esm/mime-funcs/index.js +738 -0
- package/dist/node_modules/nodemailer/dist/esm/mime-funcs/mime-types.d.ts +2 -0
- package/dist/node_modules/nodemailer/{lib → dist/esm}/mime-funcs/mime-types.js +43 -49
- package/dist/node_modules/nodemailer/dist/esm/mime-node/index.d.ts +333 -0
- package/dist/node_modules/nodemailer/{lib → dist/esm}/mime-node/index.js +576 -437
- package/dist/node_modules/nodemailer/dist/esm/mime-node/last-newline.d.ts +5 -0
- package/dist/node_modules/nodemailer/{lib → dist/esm}/mime-node/last-newline.js +4 -10
- package/dist/node_modules/nodemailer/dist/esm/mime-node/le-unix.d.ts +9 -0
- package/dist/node_modules/nodemailer/{lib → dist/esm}/mime-node/le-unix.js +7 -15
- package/dist/node_modules/nodemailer/dist/esm/mime-node/le-windows.d.ts +10 -0
- package/dist/node_modules/nodemailer/{lib → dist/esm}/mime-node/le-windows.js +6 -16
- package/dist/node_modules/nodemailer/dist/esm/nodemailer.d.ts +124 -0
- package/dist/node_modules/nodemailer/dist/esm/nodemailer.js +166 -0
- package/dist/node_modules/nodemailer/dist/esm/package-info.d.ts +3 -0
- package/dist/node_modules/nodemailer/dist/esm/package-info.js +4 -0
- package/dist/node_modules/nodemailer/dist/esm/package.json +3 -0
- package/dist/node_modules/nodemailer/dist/esm/punycode/index.d.ts +73 -0
- package/dist/node_modules/nodemailer/dist/esm/punycode/index.js +405 -0
- package/dist/node_modules/nodemailer/dist/esm/qp/index.d.ts +32 -0
- package/dist/node_modules/nodemailer/{lib → dist/esm}/qp/index.js +59 -77
- package/dist/node_modules/nodemailer/dist/esm/sendmail-transport/index.d.ts +69 -0
- package/dist/node_modules/nodemailer/dist/esm/sendmail-transport/index.js +170 -0
- package/dist/node_modules/nodemailer/dist/esm/ses-transport/index.d.ts +112 -0
- package/dist/node_modules/nodemailer/dist/esm/ses-transport/index.js +212 -0
- package/dist/node_modules/nodemailer/dist/esm/shared/index.d.ts +260 -0
- package/dist/node_modules/nodemailer/dist/esm/shared/index.js +631 -0
- package/dist/node_modules/nodemailer/dist/esm/shared/objects.d.ts +23 -0
- package/dist/node_modules/nodemailer/dist/esm/shared/objects.js +38 -0
- package/dist/node_modules/nodemailer/dist/esm/shared/url.d.ts +21 -0
- package/dist/node_modules/nodemailer/dist/esm/shared/url.js +214 -0
- package/dist/node_modules/nodemailer/dist/esm/smtp-connection/data-stream.d.ts +15 -0
- package/dist/node_modules/nodemailer/dist/esm/smtp-connection/data-stream.js +103 -0
- package/dist/node_modules/nodemailer/dist/esm/smtp-connection/http-proxy-client.d.ts +47 -0
- package/dist/node_modules/nodemailer/dist/esm/smtp-connection/http-proxy-client.js +149 -0
- package/dist/node_modules/nodemailer/dist/esm/smtp-connection/index.d.ts +416 -0
- package/dist/node_modules/nodemailer/dist/esm/smtp-connection/index.js +1797 -0
- package/dist/node_modules/nodemailer/dist/esm/smtp-pool/index.d.ts +133 -0
- package/dist/node_modules/nodemailer/{lib → dist/esm}/smtp-pool/index.js +195 -314
- package/dist/node_modules/nodemailer/dist/esm/smtp-pool/pool-resource.d.ts +62 -0
- package/dist/node_modules/nodemailer/{lib → dist/esm}/smtp-pool/pool-resource.js +70 -107
- package/dist/node_modules/nodemailer/dist/esm/smtp-transport/index.d.ts +156 -0
- package/dist/node_modules/nodemailer/dist/esm/smtp-transport/index.js +331 -0
- package/dist/node_modules/nodemailer/dist/esm/stream-transport/index.d.ts +65 -0
- package/dist/node_modules/nodemailer/dist/esm/stream-transport/index.js +106 -0
- package/dist/node_modules/nodemailer/dist/esm/well-known/index.d.ts +35 -0
- package/dist/node_modules/nodemailer/{lib → dist/esm}/well-known/index.js +12 -23
- package/dist/node_modules/nodemailer/dist/esm/well-known/services.d.ts +2 -0
- package/dist/node_modules/nodemailer/dist/esm/well-known/services.js +671 -0
- package/dist/node_modules/nodemailer/dist/esm/xoauth2/index.d.ts +201 -0
- package/dist/node_modules/nodemailer/dist/esm/xoauth2/index.js +386 -0
- package/dist/node_modules/nodemailer/dist/well-known/services.json +640 -0
- package/dist/node_modules/nodemailer/package.json +1 -1
- package/package.json +4 -4
- package/dist/node_modules/nodemailer/.gitattributes +0 -6
- package/dist/node_modules/nodemailer/.ncurc.js +0 -7
- package/dist/node_modules/nodemailer/.prettierrc.js +0 -8
- package/dist/node_modules/nodemailer/lib/addressparser/index.js +0 -313
- package/dist/node_modules/nodemailer/lib/dkim/message-parser.js +0 -155
- package/dist/node_modules/nodemailer/lib/dkim/relaxed-body.js +0 -154
- package/dist/node_modules/nodemailer/lib/dkim/sign.js +0 -117
- package/dist/node_modules/nodemailer/lib/fetch/cookies.js +0 -281
- package/dist/node_modules/nodemailer/lib/fetch/index.js +0 -274
- package/dist/node_modules/nodemailer/lib/json-transport/index.js +0 -82
- package/dist/node_modules/nodemailer/lib/mime-funcs/index.js +0 -625
- package/dist/node_modules/nodemailer/lib/nodemailer.js +0 -1
- package/dist/node_modules/nodemailer/lib/sendmail-transport/index.js +0 -210
- package/dist/node_modules/nodemailer/lib/ses-transport/index.js +0 -349
- package/dist/node_modules/nodemailer/lib/shared/index.js +0 -688
- package/dist/node_modules/nodemailer/lib/smtp-connection/data-stream.js +0 -108
- package/dist/node_modules/nodemailer/lib/smtp-connection/http-proxy-client.js +0 -143
- package/dist/node_modules/nodemailer/lib/smtp-connection/index.js +0 -1825
- package/dist/node_modules/nodemailer/lib/smtp-transport/index.js +0 -416
- package/dist/node_modules/nodemailer/lib/stream-transport/index.js +0 -135
- package/dist/node_modules/nodemailer/lib/well-known/services.json +0 -343
- package/dist/node_modules/nodemailer/lib/xoauth2/index.js +0 -376
|
@@ -1,313 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Converts tokens for a single address into an address object
|
|
5
|
-
*
|
|
6
|
-
* @param {Array} tokens Tokens object
|
|
7
|
-
* @return {Object} Address object
|
|
8
|
-
*/
|
|
9
|
-
function _handleAddress(tokens) {
|
|
10
|
-
let token;
|
|
11
|
-
let isGroup = false;
|
|
12
|
-
let state = 'text';
|
|
13
|
-
let address;
|
|
14
|
-
let addresses = [];
|
|
15
|
-
let data = {
|
|
16
|
-
address: [],
|
|
17
|
-
comment: [],
|
|
18
|
-
group: [],
|
|
19
|
-
text: []
|
|
20
|
-
};
|
|
21
|
-
let i;
|
|
22
|
-
let len;
|
|
23
|
-
|
|
24
|
-
// Filter out <addresses>, (comments) and regular text
|
|
25
|
-
for (i = 0, len = tokens.length; i < len; i++) {
|
|
26
|
-
token = tokens[i];
|
|
27
|
-
if (token.type === 'operator') {
|
|
28
|
-
switch (token.value) {
|
|
29
|
-
case '<':
|
|
30
|
-
state = 'address';
|
|
31
|
-
break;
|
|
32
|
-
case '(':
|
|
33
|
-
state = 'comment';
|
|
34
|
-
break;
|
|
35
|
-
case ':':
|
|
36
|
-
state = 'group';
|
|
37
|
-
isGroup = true;
|
|
38
|
-
break;
|
|
39
|
-
default:
|
|
40
|
-
state = 'text';
|
|
41
|
-
}
|
|
42
|
-
} else if (token.value) {
|
|
43
|
-
if (state === 'address') {
|
|
44
|
-
// handle use case where unquoted name includes a "<"
|
|
45
|
-
// Apple Mail truncates everything between an unexpected < and an address
|
|
46
|
-
// and so will we
|
|
47
|
-
token.value = token.value.replace(/^[^<]*<\s*/, '');
|
|
48
|
-
}
|
|
49
|
-
data[state].push(token.value);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
// If there is no text but a comment, replace the two
|
|
54
|
-
if (!data.text.length && data.comment.length) {
|
|
55
|
-
data.text = data.comment;
|
|
56
|
-
data.comment = [];
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
if (isGroup) {
|
|
60
|
-
// http://tools.ietf.org/html/rfc2822#appendix-A.1.3
|
|
61
|
-
data.text = data.text.join(' ');
|
|
62
|
-
addresses.push({
|
|
63
|
-
name: data.text || (address && address.name),
|
|
64
|
-
group: data.group.length ? addressparser(data.group.join(',')) : []
|
|
65
|
-
});
|
|
66
|
-
} else {
|
|
67
|
-
// If no address was found, try to detect one from regular text
|
|
68
|
-
if (!data.address.length && data.text.length) {
|
|
69
|
-
for (i = data.text.length - 1; i >= 0; i--) {
|
|
70
|
-
if (data.text[i].match(/^[^@\s]+@[^@\s]+$/)) {
|
|
71
|
-
data.address = data.text.splice(i, 1);
|
|
72
|
-
break;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
let _regexHandler = function (address) {
|
|
77
|
-
if (!data.address.length) {
|
|
78
|
-
data.address = [address.trim()];
|
|
79
|
-
return ' ';
|
|
80
|
-
} else {
|
|
81
|
-
return address;
|
|
82
|
-
}
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
// still no address
|
|
86
|
-
if (!data.address.length) {
|
|
87
|
-
for (i = data.text.length - 1; i >= 0; i--) {
|
|
88
|
-
// fixed the regex to parse email address correctly when email address has more than one @
|
|
89
|
-
data.text[i] = data.text[i].replace(/\s*\b[^@\s]+@[^\s]+\b\s*/, _regexHandler).trim();
|
|
90
|
-
if (data.address.length) {
|
|
91
|
-
break;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
// If there's still is no text but a comment exixts, replace the two
|
|
98
|
-
if (!data.text.length && data.comment.length) {
|
|
99
|
-
data.text = data.comment;
|
|
100
|
-
data.comment = [];
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
// Keep only the first address occurence, push others to regular text
|
|
104
|
-
if (data.address.length > 1) {
|
|
105
|
-
data.text = data.text.concat(data.address.splice(1));
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
// Join values with spaces
|
|
109
|
-
data.text = data.text.join(' ');
|
|
110
|
-
data.address = data.address.join(' ');
|
|
111
|
-
|
|
112
|
-
if (!data.address && isGroup) {
|
|
113
|
-
return [];
|
|
114
|
-
} else {
|
|
115
|
-
address = {
|
|
116
|
-
address: data.address || data.text || '',
|
|
117
|
-
name: data.text || data.address || ''
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
if (address.address === address.name) {
|
|
121
|
-
if ((address.address || '').match(/@/)) {
|
|
122
|
-
address.name = '';
|
|
123
|
-
} else {
|
|
124
|
-
address.address = '';
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
addresses.push(address);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
return addresses;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* Creates a Tokenizer object for tokenizing address field strings
|
|
137
|
-
*
|
|
138
|
-
* @constructor
|
|
139
|
-
* @param {String} str Address field string
|
|
140
|
-
*/
|
|
141
|
-
class Tokenizer {
|
|
142
|
-
constructor(str) {
|
|
143
|
-
this.str = (str || '').toString();
|
|
144
|
-
this.operatorCurrent = '';
|
|
145
|
-
this.operatorExpecting = '';
|
|
146
|
-
this.node = null;
|
|
147
|
-
this.escaped = false;
|
|
148
|
-
|
|
149
|
-
this.list = [];
|
|
150
|
-
/**
|
|
151
|
-
* Operator tokens and which tokens are expected to end the sequence
|
|
152
|
-
*/
|
|
153
|
-
this.operators = {
|
|
154
|
-
'"': '"',
|
|
155
|
-
'(': ')',
|
|
156
|
-
'<': '>',
|
|
157
|
-
',': '',
|
|
158
|
-
':': ';',
|
|
159
|
-
// Semicolons are not a legal delimiter per the RFC2822 grammar other
|
|
160
|
-
// than for terminating a group, but they are also not valid for any
|
|
161
|
-
// other use in this context. Given that some mail clients have
|
|
162
|
-
// historically allowed the semicolon as a delimiter equivalent to the
|
|
163
|
-
// comma in their UI, it makes sense to treat them the same as a comma
|
|
164
|
-
// when used outside of a group.
|
|
165
|
-
';': ''
|
|
166
|
-
};
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
/**
|
|
170
|
-
* Tokenizes the original input string
|
|
171
|
-
*
|
|
172
|
-
* @return {Array} An array of operator|text tokens
|
|
173
|
-
*/
|
|
174
|
-
tokenize() {
|
|
175
|
-
let chr,
|
|
176
|
-
list = [];
|
|
177
|
-
for (let i = 0, len = this.str.length; i < len; i++) {
|
|
178
|
-
chr = this.str.charAt(i);
|
|
179
|
-
this.checkChar(chr);
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
this.list.forEach(node => {
|
|
183
|
-
node.value = (node.value || '').toString().trim();
|
|
184
|
-
if (node.value) {
|
|
185
|
-
list.push(node);
|
|
186
|
-
}
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
return list;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
/**
|
|
193
|
-
* Checks if a character is an operator or text and acts accordingly
|
|
194
|
-
*
|
|
195
|
-
* @param {String} chr Character from the address field
|
|
196
|
-
*/
|
|
197
|
-
checkChar(chr) {
|
|
198
|
-
if (this.escaped) {
|
|
199
|
-
// ignore next condition blocks
|
|
200
|
-
} else if (chr === this.operatorExpecting) {
|
|
201
|
-
this.node = {
|
|
202
|
-
type: 'operator',
|
|
203
|
-
value: chr
|
|
204
|
-
};
|
|
205
|
-
this.list.push(this.node);
|
|
206
|
-
this.node = null;
|
|
207
|
-
this.operatorExpecting = '';
|
|
208
|
-
this.escaped = false;
|
|
209
|
-
return;
|
|
210
|
-
} else if (!this.operatorExpecting && chr in this.operators) {
|
|
211
|
-
this.node = {
|
|
212
|
-
type: 'operator',
|
|
213
|
-
value: chr
|
|
214
|
-
};
|
|
215
|
-
this.list.push(this.node);
|
|
216
|
-
this.node = null;
|
|
217
|
-
this.operatorExpecting = this.operators[chr];
|
|
218
|
-
this.escaped = false;
|
|
219
|
-
return;
|
|
220
|
-
} else if (['"', "'"].includes(this.operatorExpecting) && chr === '\\') {
|
|
221
|
-
this.escaped = true;
|
|
222
|
-
return;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
if (!this.node) {
|
|
226
|
-
this.node = {
|
|
227
|
-
type: 'text',
|
|
228
|
-
value: ''
|
|
229
|
-
};
|
|
230
|
-
this.list.push(this.node);
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
if (chr === '\n') {
|
|
234
|
-
// Convert newlines to spaces. Carriage return is ignored as \r and \n usually
|
|
235
|
-
// go together anyway and there already is a WS for \n. Lone \r means something is fishy.
|
|
236
|
-
chr = ' ';
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
if (chr.charCodeAt(0) >= 0x21 || [' ', '\t'].includes(chr)) {
|
|
240
|
-
// skip command bytes
|
|
241
|
-
this.node.value += chr;
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
this.escaped = false;
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
/**
|
|
249
|
-
* Parses structured e-mail addresses from an address field
|
|
250
|
-
*
|
|
251
|
-
* Example:
|
|
252
|
-
*
|
|
253
|
-
* 'Name <address@domain>'
|
|
254
|
-
*
|
|
255
|
-
* will be converted to
|
|
256
|
-
*
|
|
257
|
-
* [{name: 'Name', address: 'address@domain'}]
|
|
258
|
-
*
|
|
259
|
-
* @param {String} str Address field
|
|
260
|
-
* @return {Array} An array of address objects
|
|
261
|
-
*/
|
|
262
|
-
function addressparser(str, options) {
|
|
263
|
-
options = options || {};
|
|
264
|
-
|
|
265
|
-
let tokenizer = new Tokenizer(str);
|
|
266
|
-
let tokens = tokenizer.tokenize();
|
|
267
|
-
|
|
268
|
-
let addresses = [];
|
|
269
|
-
let address = [];
|
|
270
|
-
let parsedAddresses = [];
|
|
271
|
-
|
|
272
|
-
tokens.forEach(token => {
|
|
273
|
-
if (token.type === 'operator' && (token.value === ',' || token.value === ';')) {
|
|
274
|
-
if (address.length) {
|
|
275
|
-
addresses.push(address);
|
|
276
|
-
}
|
|
277
|
-
address = [];
|
|
278
|
-
} else {
|
|
279
|
-
address.push(token);
|
|
280
|
-
}
|
|
281
|
-
});
|
|
282
|
-
|
|
283
|
-
if (address.length) {
|
|
284
|
-
addresses.push(address);
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
addresses.forEach(address => {
|
|
288
|
-
address = _handleAddress(address);
|
|
289
|
-
if (address.length) {
|
|
290
|
-
parsedAddresses = parsedAddresses.concat(address);
|
|
291
|
-
}
|
|
292
|
-
});
|
|
293
|
-
|
|
294
|
-
if (options.flatten) {
|
|
295
|
-
let addresses = [];
|
|
296
|
-
let walkAddressList = list => {
|
|
297
|
-
list.forEach(address => {
|
|
298
|
-
if (address.group) {
|
|
299
|
-
return walkAddressList(address.group);
|
|
300
|
-
} else {
|
|
301
|
-
addresses.push(address);
|
|
302
|
-
}
|
|
303
|
-
});
|
|
304
|
-
};
|
|
305
|
-
walkAddressList(parsedAddresses);
|
|
306
|
-
return addresses;
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
return parsedAddresses;
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
// expose to the world
|
|
313
|
-
module.exports = addressparser;
|
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const Transform = require('stream').Transform;
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* MessageParser instance is a transform stream that separates message headers
|
|
7
|
-
* from the rest of the body. Headers are emitted with the 'headers' event. Message
|
|
8
|
-
* body is passed on as the resulting stream.
|
|
9
|
-
*/
|
|
10
|
-
class MessageParser extends Transform {
|
|
11
|
-
constructor(options) {
|
|
12
|
-
super(options);
|
|
13
|
-
this.lastBytes = Buffer.alloc(4);
|
|
14
|
-
this.headersParsed = false;
|
|
15
|
-
this.headerBytes = 0;
|
|
16
|
-
this.headerChunks = [];
|
|
17
|
-
this.rawHeaders = false;
|
|
18
|
-
this.bodySize = 0;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Keeps count of the last 4 bytes in order to detect line breaks on chunk boundaries
|
|
23
|
-
*
|
|
24
|
-
* @param {Buffer} data Next data chunk from the stream
|
|
25
|
-
*/
|
|
26
|
-
updateLastBytes(data) {
|
|
27
|
-
let lblen = this.lastBytes.length;
|
|
28
|
-
let nblen = Math.min(data.length, lblen);
|
|
29
|
-
|
|
30
|
-
// shift existing bytes
|
|
31
|
-
for (let i = 0, len = lblen - nblen; i < len; i++) {
|
|
32
|
-
this.lastBytes[i] = this.lastBytes[i + nblen];
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// add new bytes
|
|
36
|
-
for (let i = 1; i <= nblen; i++) {
|
|
37
|
-
this.lastBytes[lblen - i] = data[data.length - i];
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Finds and removes message headers from the remaining body. We want to keep
|
|
43
|
-
* headers separated until final delivery to be able to modify these
|
|
44
|
-
*
|
|
45
|
-
* @param {Buffer} data Next chunk of data
|
|
46
|
-
* @return {Boolean} Returns true if headers are already found or false otherwise
|
|
47
|
-
*/
|
|
48
|
-
checkHeaders(data) {
|
|
49
|
-
if (this.headersParsed) {
|
|
50
|
-
return true;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
let lblen = this.lastBytes.length;
|
|
54
|
-
let headerPos = 0;
|
|
55
|
-
this.curLinePos = 0;
|
|
56
|
-
for (let i = 0, len = this.lastBytes.length + data.length; i < len; i++) {
|
|
57
|
-
let chr;
|
|
58
|
-
if (i < lblen) {
|
|
59
|
-
chr = this.lastBytes[i];
|
|
60
|
-
} else {
|
|
61
|
-
chr = data[i - lblen];
|
|
62
|
-
}
|
|
63
|
-
if (chr === 0x0a && i) {
|
|
64
|
-
let pr1 = i - 1 < lblen ? this.lastBytes[i - 1] : data[i - 1 - lblen];
|
|
65
|
-
let pr2 = i > 1 ? (i - 2 < lblen ? this.lastBytes[i - 2] : data[i - 2 - lblen]) : false;
|
|
66
|
-
if (pr1 === 0x0a) {
|
|
67
|
-
this.headersParsed = true;
|
|
68
|
-
headerPos = i - lblen + 1;
|
|
69
|
-
this.headerBytes += headerPos;
|
|
70
|
-
break;
|
|
71
|
-
} else if (pr1 === 0x0d && pr2 === 0x0a) {
|
|
72
|
-
this.headersParsed = true;
|
|
73
|
-
headerPos = i - lblen + 1;
|
|
74
|
-
this.headerBytes += headerPos;
|
|
75
|
-
break;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
if (this.headersParsed) {
|
|
81
|
-
this.headerChunks.push(data.slice(0, headerPos));
|
|
82
|
-
this.rawHeaders = Buffer.concat(this.headerChunks, this.headerBytes);
|
|
83
|
-
this.headerChunks = null;
|
|
84
|
-
this.emit('headers', this.parseHeaders());
|
|
85
|
-
if (data.length - 1 > headerPos) {
|
|
86
|
-
let chunk = data.slice(headerPos);
|
|
87
|
-
this.bodySize += chunk.length;
|
|
88
|
-
// this would be the first chunk of data sent downstream
|
|
89
|
-
setImmediate(() => this.push(chunk));
|
|
90
|
-
}
|
|
91
|
-
return false;
|
|
92
|
-
} else {
|
|
93
|
-
this.headerBytes += data.length;
|
|
94
|
-
this.headerChunks.push(data);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
// store last 4 bytes to catch header break
|
|
98
|
-
this.updateLastBytes(data);
|
|
99
|
-
|
|
100
|
-
return false;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
_transform(chunk, encoding, callback) {
|
|
104
|
-
if (!chunk || !chunk.length) {
|
|
105
|
-
return callback();
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
if (typeof chunk === 'string') {
|
|
109
|
-
chunk = Buffer.from(chunk, encoding);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
let headersFound;
|
|
113
|
-
|
|
114
|
-
try {
|
|
115
|
-
headersFound = this.checkHeaders(chunk);
|
|
116
|
-
} catch (E) {
|
|
117
|
-
return callback(E);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
if (headersFound) {
|
|
121
|
-
this.bodySize += chunk.length;
|
|
122
|
-
this.push(chunk);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
setImmediate(callback);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
_flush(callback) {
|
|
129
|
-
if (this.headerChunks) {
|
|
130
|
-
let chunk = Buffer.concat(this.headerChunks, this.headerBytes);
|
|
131
|
-
this.bodySize += chunk.length;
|
|
132
|
-
this.push(chunk);
|
|
133
|
-
this.headerChunks = null;
|
|
134
|
-
}
|
|
135
|
-
callback();
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
parseHeaders() {
|
|
139
|
-
let lines = (this.rawHeaders || '').toString().split(/\r?\n/);
|
|
140
|
-
for (let i = lines.length - 1; i > 0; i--) {
|
|
141
|
-
if (/^\s/.test(lines[i])) {
|
|
142
|
-
lines[i - 1] += '\n' + lines[i];
|
|
143
|
-
lines.splice(i, 1);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
return lines
|
|
147
|
-
.filter(line => line.trim())
|
|
148
|
-
.map(line => ({
|
|
149
|
-
key: line.substr(0, line.indexOf(':')).trim().toLowerCase(),
|
|
150
|
-
line
|
|
151
|
-
}));
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
module.exports = MessageParser;
|
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
// streams through a message body and calculates relaxed body hash
|
|
4
|
-
|
|
5
|
-
const Transform = require('stream').Transform;
|
|
6
|
-
const crypto = require('crypto');
|
|
7
|
-
|
|
8
|
-
class RelaxedBody extends Transform {
|
|
9
|
-
constructor(options) {
|
|
10
|
-
super();
|
|
11
|
-
options = options || {};
|
|
12
|
-
this.chunkBuffer = [];
|
|
13
|
-
this.chunkBufferLen = 0;
|
|
14
|
-
this.bodyHash = crypto.createHash(options.hashAlgo || 'sha1');
|
|
15
|
-
this.remainder = '';
|
|
16
|
-
this.byteLength = 0;
|
|
17
|
-
|
|
18
|
-
this.debug = options.debug;
|
|
19
|
-
this._debugBody = options.debug ? [] : false;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
updateHash(chunk) {
|
|
23
|
-
let bodyStr;
|
|
24
|
-
|
|
25
|
-
// find next remainder
|
|
26
|
-
let nextRemainder = '';
|
|
27
|
-
|
|
28
|
-
// This crux finds and removes the spaces from the last line and the newline characters after the last non-empty line
|
|
29
|
-
// If we get another chunk that does not match this description then we can restore the previously processed data
|
|
30
|
-
let state = 'file';
|
|
31
|
-
for (let i = chunk.length - 1; i >= 0; i--) {
|
|
32
|
-
let c = chunk[i];
|
|
33
|
-
|
|
34
|
-
if (state === 'file' && (c === 0x0a || c === 0x0d)) {
|
|
35
|
-
// do nothing, found \n or \r at the end of chunk, stil end of file
|
|
36
|
-
} else if (state === 'file' && (c === 0x09 || c === 0x20)) {
|
|
37
|
-
// switch to line ending mode, this is the last non-empty line
|
|
38
|
-
state = 'line';
|
|
39
|
-
} else if (state === 'line' && (c === 0x09 || c === 0x20)) {
|
|
40
|
-
// do nothing, found ' ' or \t at the end of line, keep processing the last non-empty line
|
|
41
|
-
} else if (state === 'file' || state === 'line') {
|
|
42
|
-
// non line/file ending character found, switch to body mode
|
|
43
|
-
state = 'body';
|
|
44
|
-
if (i === chunk.length - 1) {
|
|
45
|
-
// final char is not part of line end or file end, so do nothing
|
|
46
|
-
break;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
if (i === 0) {
|
|
51
|
-
// reached to the beginning of the chunk, check if it is still about the ending
|
|
52
|
-
// and if the remainder also matches
|
|
53
|
-
if (
|
|
54
|
-
(state === 'file' && (!this.remainder || /[\r\n]$/.test(this.remainder))) ||
|
|
55
|
-
(state === 'line' && (!this.remainder || /[ \t]$/.test(this.remainder)))
|
|
56
|
-
) {
|
|
57
|
-
// keep everything
|
|
58
|
-
this.remainder += chunk.toString('binary');
|
|
59
|
-
return;
|
|
60
|
-
} else if (state === 'line' || state === 'file') {
|
|
61
|
-
// process existing remainder as normal line but store the current chunk
|
|
62
|
-
nextRemainder = chunk.toString('binary');
|
|
63
|
-
chunk = false;
|
|
64
|
-
break;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
if (state !== 'body') {
|
|
69
|
-
continue;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
// reached first non ending byte
|
|
73
|
-
nextRemainder = chunk.slice(i + 1).toString('binary');
|
|
74
|
-
chunk = chunk.slice(0, i + 1);
|
|
75
|
-
break;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
let needsFixing = !!this.remainder;
|
|
79
|
-
if (chunk && !needsFixing) {
|
|
80
|
-
// check if we even need to change anything
|
|
81
|
-
for (let i = 0, len = chunk.length; i < len; i++) {
|
|
82
|
-
if (i && chunk[i] === 0x0a && chunk[i - 1] !== 0x0d) {
|
|
83
|
-
// missing \r before \n
|
|
84
|
-
needsFixing = true;
|
|
85
|
-
break;
|
|
86
|
-
} else if (i && chunk[i] === 0x0d && chunk[i - 1] === 0x20) {
|
|
87
|
-
// trailing WSP found
|
|
88
|
-
needsFixing = true;
|
|
89
|
-
break;
|
|
90
|
-
} else if (i && chunk[i] === 0x20 && chunk[i - 1] === 0x20) {
|
|
91
|
-
// multiple spaces found, needs to be replaced with just one
|
|
92
|
-
needsFixing = true;
|
|
93
|
-
break;
|
|
94
|
-
} else if (chunk[i] === 0x09) {
|
|
95
|
-
// TAB found, needs to be replaced with a space
|
|
96
|
-
needsFixing = true;
|
|
97
|
-
break;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
if (needsFixing) {
|
|
103
|
-
bodyStr = this.remainder + (chunk ? chunk.toString('binary') : '');
|
|
104
|
-
this.remainder = nextRemainder;
|
|
105
|
-
bodyStr = bodyStr
|
|
106
|
-
.replace(/\r?\n/g, '\n') // use js line endings
|
|
107
|
-
.replace(/[ \t]*$/gm, '') // remove line endings, rtrim
|
|
108
|
-
.replace(/[ \t]+/gm, ' ') // single spaces
|
|
109
|
-
.replace(/\n/g, '\r\n'); // restore rfc822 line endings
|
|
110
|
-
chunk = Buffer.from(bodyStr, 'binary');
|
|
111
|
-
} else if (nextRemainder) {
|
|
112
|
-
this.remainder = nextRemainder;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
if (this.debug) {
|
|
116
|
-
this._debugBody.push(chunk);
|
|
117
|
-
}
|
|
118
|
-
this.bodyHash.update(chunk);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
_transform(chunk, encoding, callback) {
|
|
122
|
-
if (!chunk || !chunk.length) {
|
|
123
|
-
return callback();
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
if (typeof chunk === 'string') {
|
|
127
|
-
chunk = Buffer.from(chunk, encoding);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
this.updateHash(chunk);
|
|
131
|
-
|
|
132
|
-
this.byteLength += chunk.length;
|
|
133
|
-
this.push(chunk);
|
|
134
|
-
callback();
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
_flush(callback) {
|
|
138
|
-
// generate final hash and emit it
|
|
139
|
-
if (/[\r\n]$/.test(this.remainder) && this.byteLength > 2) {
|
|
140
|
-
// add terminating line end
|
|
141
|
-
this.bodyHash.update(Buffer.from('\r\n'));
|
|
142
|
-
}
|
|
143
|
-
if (!this.byteLength) {
|
|
144
|
-
// emit empty line buffer to keep the stream flowing
|
|
145
|
-
this.push(Buffer.from('\r\n'));
|
|
146
|
-
// this.bodyHash.update(Buffer.from('\r\n'));
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
this.emit('hash', this.bodyHash.digest('base64'), this.debug ? Buffer.concat(this._debugBody) : false);
|
|
150
|
-
callback();
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
module.exports = RelaxedBody;
|