@nocobase/plugin-workflow-mailer 2.4.0-alpha.1 → 2.4.0-alpha.11

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.
Files changed (187) hide show
  1. package/dist/externalVersion.js +6 -6
  2. package/dist/node_modules/joi/dist/joi-browser.min.js +1 -1
  3. package/dist/node_modules/joi/lib/index.js +1 -1
  4. package/dist/node_modules/joi/lib/messages.js +35 -6
  5. package/dist/node_modules/joi/lib/types/keys.js +18 -1
  6. package/dist/node_modules/joi/lib/types/link.js +18 -2
  7. package/dist/node_modules/joi/lib/types/string.js +2 -2
  8. package/dist/node_modules/joi/package.json +1 -1
  9. package/dist/node_modules/nodemailer/dist/cjs/addressparser/index.d.ts +59 -0
  10. package/dist/node_modules/nodemailer/dist/cjs/addressparser/index.js +790 -0
  11. package/dist/node_modules/nodemailer/dist/cjs/base64/index.d.ts +36 -0
  12. package/dist/node_modules/nodemailer/dist/cjs/base64/index.js +119 -0
  13. package/dist/node_modules/nodemailer/dist/cjs/dkim/index.d.ts +52 -0
  14. package/dist/node_modules/nodemailer/dist/cjs/dkim/index.js +228 -0
  15. package/dist/node_modules/nodemailer/dist/cjs/dkim/message-parser.d.ts +48 -0
  16. package/dist/node_modules/nodemailer/dist/cjs/dkim/message-parser.js +180 -0
  17. package/dist/node_modules/nodemailer/dist/cjs/dkim/relaxed-body.d.ts +36 -0
  18. package/dist/node_modules/nodemailer/dist/cjs/dkim/relaxed-body.js +148 -0
  19. package/dist/node_modules/nodemailer/dist/cjs/dkim/sign.d.ts +52 -0
  20. package/dist/node_modules/nodemailer/dist/cjs/dkim/sign.js +165 -0
  21. package/dist/node_modules/nodemailer/dist/cjs/errors.d.ts +96 -0
  22. package/dist/node_modules/nodemailer/dist/cjs/errors.js +70 -0
  23. package/dist/node_modules/nodemailer/dist/cjs/fetch/cookies.d.ts +107 -0
  24. package/dist/node_modules/nodemailer/dist/cjs/fetch/cookies.js +282 -0
  25. package/dist/node_modules/nodemailer/dist/cjs/fetch/index.d.ts +65 -0
  26. package/dist/node_modules/nodemailer/dist/cjs/fetch/index.js +384 -0
  27. package/dist/node_modules/nodemailer/dist/cjs/json-transport/index.d.ts +64 -0
  28. package/dist/node_modules/nodemailer/dist/cjs/json-transport/index.js +99 -0
  29. package/dist/node_modules/nodemailer/dist/cjs/mail-composer/index.d.ts +174 -0
  30. package/dist/node_modules/nodemailer/dist/cjs/mail-composer/index.js +613 -0
  31. package/dist/node_modules/nodemailer/dist/cjs/mailer/index.d.ts +237 -0
  32. package/dist/node_modules/nodemailer/dist/cjs/mailer/index.js +415 -0
  33. package/dist/node_modules/nodemailer/dist/cjs/mailer/mail-message.d.ts +97 -0
  34. package/dist/node_modules/nodemailer/dist/cjs/mailer/mail-message.js +342 -0
  35. package/dist/node_modules/nodemailer/dist/cjs/mime-funcs/index.d.ts +161 -0
  36. package/dist/node_modules/nodemailer/dist/cjs/mime-funcs/index.js +787 -0
  37. package/dist/node_modules/nodemailer/dist/cjs/mime-funcs/mime-types.d.ts +2 -0
  38. package/dist/node_modules/nodemailer/dist/cjs/mime-funcs/mime-types.js +2103 -0
  39. package/dist/node_modules/nodemailer/dist/cjs/mime-node/index.d.ts +333 -0
  40. package/dist/node_modules/nodemailer/dist/cjs/mime-node/index.js +1493 -0
  41. package/dist/node_modules/nodemailer/dist/cjs/mime-node/last-newline.d.ts +5 -0
  42. package/dist/node_modules/nodemailer/dist/cjs/mime-node/last-newline.js +32 -0
  43. package/dist/node_modules/nodemailer/dist/cjs/mime-node/le-unix.d.ts +9 -0
  44. package/dist/node_modules/nodemailer/dist/cjs/mime-node/le-unix.js +40 -0
  45. package/dist/node_modules/nodemailer/dist/cjs/mime-node/le-windows.d.ts +10 -0
  46. package/dist/node_modules/nodemailer/dist/cjs/mime-node/le-windows.js +47 -0
  47. package/dist/node_modules/nodemailer/dist/cjs/nodemailer.d.ts +124 -0
  48. package/dist/node_modules/nodemailer/dist/cjs/nodemailer.js +1 -0
  49. package/dist/node_modules/nodemailer/dist/cjs/package-info.d.ts +3 -0
  50. package/dist/node_modules/nodemailer/dist/cjs/package-info.js +7 -0
  51. package/dist/node_modules/nodemailer/dist/cjs/package.json +3 -0
  52. package/dist/node_modules/nodemailer/dist/cjs/punycode/index.d.ts +73 -0
  53. package/dist/node_modules/nodemailer/{lib → dist/cjs}/punycode/index.js +63 -112
  54. package/dist/node_modules/nodemailer/dist/cjs/qp/index.d.ts +32 -0
  55. package/dist/node_modules/nodemailer/dist/cjs/qp/index.js +207 -0
  56. package/dist/node_modules/nodemailer/dist/cjs/sendmail-transport/index.d.ts +69 -0
  57. package/dist/node_modules/nodemailer/dist/cjs/sendmail-transport/index.js +210 -0
  58. package/dist/node_modules/nodemailer/dist/cjs/ses-transport/index.d.ts +112 -0
  59. package/dist/node_modules/nodemailer/dist/cjs/ses-transport/index.js +252 -0
  60. package/dist/node_modules/nodemailer/dist/cjs/shared/index.d.ts +260 -0
  61. package/dist/node_modules/nodemailer/dist/cjs/shared/index.js +680 -0
  62. package/dist/node_modules/nodemailer/dist/cjs/shared/objects.d.ts +23 -0
  63. package/dist/node_modules/nodemailer/dist/cjs/shared/objects.js +43 -0
  64. package/dist/node_modules/nodemailer/dist/cjs/shared/url.d.ts +21 -0
  65. package/dist/node_modules/nodemailer/dist/cjs/shared/url.js +255 -0
  66. package/dist/node_modules/nodemailer/dist/cjs/smtp-connection/data-stream.d.ts +15 -0
  67. package/dist/node_modules/nodemailer/dist/cjs/smtp-connection/data-stream.js +108 -0
  68. package/dist/node_modules/nodemailer/dist/cjs/smtp-connection/http-proxy-client.d.ts +47 -0
  69. package/dist/node_modules/nodemailer/dist/cjs/smtp-connection/http-proxy-client.js +189 -0
  70. package/dist/node_modules/nodemailer/dist/cjs/smtp-connection/index.d.ts +416 -0
  71. package/dist/node_modules/nodemailer/dist/cjs/smtp-connection/index.js +1837 -0
  72. package/dist/node_modules/nodemailer/dist/cjs/smtp-pool/index.d.ts +133 -0
  73. package/dist/node_modules/nodemailer/dist/cjs/smtp-pool/index.js +569 -0
  74. package/dist/node_modules/nodemailer/dist/cjs/smtp-pool/pool-resource.d.ts +62 -0
  75. package/dist/node_modules/nodemailer/dist/cjs/smtp-pool/pool-resource.js +257 -0
  76. package/dist/node_modules/nodemailer/dist/cjs/smtp-transport/index.d.ts +156 -0
  77. package/dist/node_modules/nodemailer/dist/cjs/smtp-transport/index.js +371 -0
  78. package/dist/node_modules/nodemailer/dist/cjs/stream-transport/index.d.ts +65 -0
  79. package/dist/node_modules/nodemailer/dist/cjs/stream-transport/index.js +146 -0
  80. package/dist/node_modules/nodemailer/dist/cjs/well-known/index.d.ts +35 -0
  81. package/dist/node_modules/nodemailer/dist/cjs/well-known/index.js +41 -0
  82. package/dist/node_modules/nodemailer/dist/cjs/well-known/services.d.ts +2 -0
  83. package/dist/node_modules/nodemailer/dist/cjs/well-known/services.js +674 -0
  84. package/dist/node_modules/nodemailer/dist/cjs/xoauth2/index.d.ts +201 -0
  85. package/dist/node_modules/nodemailer/dist/cjs/xoauth2/index.js +426 -0
  86. package/dist/node_modules/nodemailer/dist/esm/addressparser/index.d.ts +59 -0
  87. package/dist/node_modules/nodemailer/dist/esm/addressparser/index.js +786 -0
  88. package/dist/node_modules/nodemailer/dist/esm/base64/index.d.ts +36 -0
  89. package/dist/node_modules/nodemailer/{lib → dist/esm}/base64/index.js +39 -68
  90. package/dist/node_modules/nodemailer/dist/esm/dkim/index.d.ts +52 -0
  91. package/dist/node_modules/nodemailer/{lib → dist/esm}/dkim/index.js +62 -92
  92. package/dist/node_modules/nodemailer/dist/esm/dkim/message-parser.d.ts +48 -0
  93. package/dist/node_modules/nodemailer/dist/esm/dkim/message-parser.js +176 -0
  94. package/dist/node_modules/nodemailer/dist/esm/dkim/relaxed-body.d.ts +36 -0
  95. package/dist/node_modules/nodemailer/dist/esm/dkim/relaxed-body.js +141 -0
  96. package/dist/node_modules/nodemailer/dist/esm/dkim/sign.d.ts +52 -0
  97. package/dist/node_modules/nodemailer/dist/esm/dkim/sign.js +125 -0
  98. package/dist/node_modules/nodemailer/dist/esm/errors.d.ts +96 -0
  99. package/dist/node_modules/nodemailer/dist/esm/errors.js +67 -0
  100. package/dist/node_modules/nodemailer/dist/esm/fetch/cookies.d.ts +107 -0
  101. package/dist/node_modules/nodemailer/dist/esm/fetch/cookies.js +242 -0
  102. package/dist/node_modules/nodemailer/dist/esm/fetch/index.d.ts +65 -0
  103. package/dist/node_modules/nodemailer/dist/esm/fetch/index.js +344 -0
  104. package/dist/node_modules/nodemailer/dist/esm/json-transport/index.d.ts +64 -0
  105. package/dist/node_modules/nodemailer/dist/esm/json-transport/index.js +62 -0
  106. package/dist/node_modules/nodemailer/dist/esm/mail-composer/index.d.ts +174 -0
  107. package/dist/node_modules/nodemailer/{lib → dist/esm}/mail-composer/index.js +283 -275
  108. package/dist/node_modules/nodemailer/dist/esm/mailer/index.d.ts +237 -0
  109. package/dist/node_modules/nodemailer/{lib → dist/esm}/mailer/index.js +151 -205
  110. package/dist/node_modules/nodemailer/dist/esm/mailer/mail-message.d.ts +97 -0
  111. package/dist/node_modules/nodemailer/{lib → dist/esm}/mailer/mail-message.js +111 -125
  112. package/dist/node_modules/nodemailer/dist/esm/mime-funcs/index.d.ts +161 -0
  113. package/dist/node_modules/nodemailer/dist/esm/mime-funcs/index.js +738 -0
  114. package/dist/node_modules/nodemailer/dist/esm/mime-funcs/mime-types.d.ts +2 -0
  115. package/dist/node_modules/nodemailer/{lib → dist/esm}/mime-funcs/mime-types.js +43 -49
  116. package/dist/node_modules/nodemailer/dist/esm/mime-node/index.d.ts +333 -0
  117. package/dist/node_modules/nodemailer/{lib → dist/esm}/mime-node/index.js +576 -437
  118. package/dist/node_modules/nodemailer/dist/esm/mime-node/last-newline.d.ts +5 -0
  119. package/dist/node_modules/nodemailer/{lib → dist/esm}/mime-node/last-newline.js +4 -10
  120. package/dist/node_modules/nodemailer/dist/esm/mime-node/le-unix.d.ts +9 -0
  121. package/dist/node_modules/nodemailer/{lib → dist/esm}/mime-node/le-unix.js +7 -15
  122. package/dist/node_modules/nodemailer/dist/esm/mime-node/le-windows.d.ts +10 -0
  123. package/dist/node_modules/nodemailer/{lib → dist/esm}/mime-node/le-windows.js +6 -16
  124. package/dist/node_modules/nodemailer/dist/esm/nodemailer.d.ts +124 -0
  125. package/dist/node_modules/nodemailer/dist/esm/nodemailer.js +166 -0
  126. package/dist/node_modules/nodemailer/dist/esm/package-info.d.ts +3 -0
  127. package/dist/node_modules/nodemailer/dist/esm/package-info.js +4 -0
  128. package/dist/node_modules/nodemailer/dist/esm/package.json +3 -0
  129. package/dist/node_modules/nodemailer/dist/esm/punycode/index.d.ts +73 -0
  130. package/dist/node_modules/nodemailer/dist/esm/punycode/index.js +405 -0
  131. package/dist/node_modules/nodemailer/dist/esm/qp/index.d.ts +32 -0
  132. package/dist/node_modules/nodemailer/{lib → dist/esm}/qp/index.js +59 -77
  133. package/dist/node_modules/nodemailer/dist/esm/sendmail-transport/index.d.ts +69 -0
  134. package/dist/node_modules/nodemailer/dist/esm/sendmail-transport/index.js +170 -0
  135. package/dist/node_modules/nodemailer/dist/esm/ses-transport/index.d.ts +112 -0
  136. package/dist/node_modules/nodemailer/dist/esm/ses-transport/index.js +212 -0
  137. package/dist/node_modules/nodemailer/dist/esm/shared/index.d.ts +260 -0
  138. package/dist/node_modules/nodemailer/dist/esm/shared/index.js +631 -0
  139. package/dist/node_modules/nodemailer/dist/esm/shared/objects.d.ts +23 -0
  140. package/dist/node_modules/nodemailer/dist/esm/shared/objects.js +38 -0
  141. package/dist/node_modules/nodemailer/dist/esm/shared/url.d.ts +21 -0
  142. package/dist/node_modules/nodemailer/dist/esm/shared/url.js +214 -0
  143. package/dist/node_modules/nodemailer/dist/esm/smtp-connection/data-stream.d.ts +15 -0
  144. package/dist/node_modules/nodemailer/dist/esm/smtp-connection/data-stream.js +103 -0
  145. package/dist/node_modules/nodemailer/dist/esm/smtp-connection/http-proxy-client.d.ts +47 -0
  146. package/dist/node_modules/nodemailer/dist/esm/smtp-connection/http-proxy-client.js +149 -0
  147. package/dist/node_modules/nodemailer/dist/esm/smtp-connection/index.d.ts +416 -0
  148. package/dist/node_modules/nodemailer/dist/esm/smtp-connection/index.js +1797 -0
  149. package/dist/node_modules/nodemailer/dist/esm/smtp-pool/index.d.ts +133 -0
  150. package/dist/node_modules/nodemailer/{lib → dist/esm}/smtp-pool/index.js +195 -314
  151. package/dist/node_modules/nodemailer/dist/esm/smtp-pool/pool-resource.d.ts +62 -0
  152. package/dist/node_modules/nodemailer/{lib → dist/esm}/smtp-pool/pool-resource.js +70 -107
  153. package/dist/node_modules/nodemailer/dist/esm/smtp-transport/index.d.ts +156 -0
  154. package/dist/node_modules/nodemailer/dist/esm/smtp-transport/index.js +331 -0
  155. package/dist/node_modules/nodemailer/dist/esm/stream-transport/index.d.ts +65 -0
  156. package/dist/node_modules/nodemailer/dist/esm/stream-transport/index.js +106 -0
  157. package/dist/node_modules/nodemailer/dist/esm/well-known/index.d.ts +35 -0
  158. package/dist/node_modules/nodemailer/{lib → dist/esm}/well-known/index.js +12 -23
  159. package/dist/node_modules/nodemailer/dist/esm/well-known/services.d.ts +2 -0
  160. package/dist/node_modules/nodemailer/dist/esm/well-known/services.js +671 -0
  161. package/dist/node_modules/nodemailer/dist/esm/xoauth2/index.d.ts +201 -0
  162. package/dist/node_modules/nodemailer/dist/esm/xoauth2/index.js +386 -0
  163. package/dist/node_modules/nodemailer/dist/well-known/services.json +640 -0
  164. package/dist/node_modules/nodemailer/package.json +1 -1
  165. package/package.json +4 -4
  166. package/dist/node_modules/nodemailer/.gitattributes +0 -6
  167. package/dist/node_modules/nodemailer/.ncurc.js +0 -7
  168. package/dist/node_modules/nodemailer/.prettierrc.js +0 -8
  169. package/dist/node_modules/nodemailer/lib/addressparser/index.js +0 -313
  170. package/dist/node_modules/nodemailer/lib/dkim/message-parser.js +0 -155
  171. package/dist/node_modules/nodemailer/lib/dkim/relaxed-body.js +0 -154
  172. package/dist/node_modules/nodemailer/lib/dkim/sign.js +0 -117
  173. package/dist/node_modules/nodemailer/lib/fetch/cookies.js +0 -281
  174. package/dist/node_modules/nodemailer/lib/fetch/index.js +0 -274
  175. package/dist/node_modules/nodemailer/lib/json-transport/index.js +0 -82
  176. package/dist/node_modules/nodemailer/lib/mime-funcs/index.js +0 -625
  177. package/dist/node_modules/nodemailer/lib/nodemailer.js +0 -1
  178. package/dist/node_modules/nodemailer/lib/sendmail-transport/index.js +0 -210
  179. package/dist/node_modules/nodemailer/lib/ses-transport/index.js +0 -349
  180. package/dist/node_modules/nodemailer/lib/shared/index.js +0 -688
  181. package/dist/node_modules/nodemailer/lib/smtp-connection/data-stream.js +0 -108
  182. package/dist/node_modules/nodemailer/lib/smtp-connection/http-proxy-client.js +0 -143
  183. package/dist/node_modules/nodemailer/lib/smtp-connection/index.js +0 -1825
  184. package/dist/node_modules/nodemailer/lib/smtp-transport/index.js +0 -416
  185. package/dist/node_modules/nodemailer/lib/stream-transport/index.js +0 -135
  186. package/dist/node_modules/nodemailer/lib/well-known/services.json +0 -343
  187. package/dist/node_modules/nodemailer/lib/xoauth2/index.js +0 -376
@@ -0,0 +1,36 @@
1
+ import { Transform } from 'node:stream';
2
+ /**
3
+ * Encodes a Buffer into a base64 encoded string
4
+ *
5
+ * @param buffer Buffer to convert
6
+ * @returns base64 encoded string
7
+ */
8
+ export declare function encode(buffer: Buffer | string): string;
9
+ /**
10
+ * Adds soft line breaks to a base64 string
11
+ *
12
+ * @param str base64 encoded string that might need line wrapping
13
+ * @param [lineLength=76] Maximum allowed length for a line
14
+ * @returns Soft-wrapped base64 encoded string
15
+ */
16
+ export declare function wrap(str: string, lineLength?: number | false): string;
17
+ /**
18
+ * Options for the base64 encoder stream
19
+ */
20
+ export interface EncoderOptions {
21
+ /** Maximum length for lines, set to false to disable wrapping */
22
+ lineLength?: number | false | undefined;
23
+ }
24
+ /**
25
+ * Creates a transform stream for encoding data to base64 encoding
26
+ *
27
+ * @constructor
28
+ * @param options Stream options
29
+ * @param [options.lineLength=76] Maximum length for lines, set to false to disable wrapping
30
+ */
31
+ export declare class Encoder extends Transform {
32
+ options: EncoderOptions;
33
+ inputBytes: number;
34
+ outputBytes: number;
35
+ constructor(options?: EncoderOptions);
36
+ }
@@ -1,142 +1,113 @@
1
- 'use strict';
2
-
3
- const Transform = require('stream').Transform;
4
-
1
+ import { Transform } from 'node:stream';
5
2
  /**
6
3
  * Encodes a Buffer into a base64 encoded string
7
4
  *
8
- * @param {Buffer} buffer Buffer to convert
9
- * @returns {String} base64 encoded string
5
+ * @param buffer Buffer to convert
6
+ * @returns base64 encoded string
10
7
  */
11
- function encode(buffer) {
8
+ export function encode(buffer) {
12
9
  if (typeof buffer === 'string') {
13
10
  buffer = Buffer.from(buffer, 'utf-8');
14
11
  }
15
-
16
12
  return buffer.toString('base64');
17
13
  }
18
-
19
14
  /**
20
15
  * Adds soft line breaks to a base64 string
21
16
  *
22
- * @param {String} str base64 encoded string that might need line wrapping
23
- * @param {Number} [lineLength=76] Maximum allowed length for a line
24
- * @returns {String} Soft-wrapped base64 encoded string
17
+ * @param str base64 encoded string that might need line wrapping
18
+ * @param [lineLength=76] Maximum allowed length for a line
19
+ * @returns Soft-wrapped base64 encoded string
25
20
  */
26
- function wrap(str, lineLength) {
21
+ export function wrap(str, lineLength) {
27
22
  str = (str || '').toString();
28
- lineLength = lineLength || 76;
29
-
23
+ // a negative length would step backwards through the input and never finish
24
+ lineLength = Math.max(Number(lineLength) || 76, 1);
30
25
  if (str.length <= lineLength) {
31
26
  return str;
32
27
  }
33
-
34
- let result = [];
28
+ const result = [];
35
29
  let pos = 0;
36
- let chunkLength = lineLength * 1024;
30
+ const chunkLength = lineLength * 1024;
31
+ const wrapRegex = new RegExp('.{' + lineLength + '}', 'g');
37
32
  while (pos < str.length) {
38
- let wrappedLines = str
39
- .substr(pos, chunkLength)
40
- .replace(new RegExp('.{' + lineLength + '}', 'g'), '$&\r\n')
41
- .trim();
33
+ const wrappedLines = str.substr(pos, chunkLength).replace(wrapRegex, '$&\r\n').trim();
42
34
  result.push(wrappedLines);
43
35
  pos += chunkLength;
44
36
  }
45
-
46
37
  return result.join('\r\n').trim();
47
38
  }
48
-
49
39
  /**
50
40
  * Creates a transform stream for encoding data to base64 encoding
51
41
  *
52
42
  * @constructor
53
- * @param {Object} options Stream options
54
- * @param {Number} [options.lineLength=76] Maximum length for lines, set to false to disable wrapping
43
+ * @param options Stream options
44
+ * @param [options.lineLength=76] Maximum length for lines, set to false to disable wrapping
55
45
  */
56
- class Encoder extends Transform {
46
+ export class Encoder extends Transform {
57
47
  constructor(options) {
58
48
  super();
59
- // init Transform
60
49
  this.options = options || {};
61
-
62
50
  if (this.options.lineLength !== false) {
63
51
  this.options.lineLength = this.options.lineLength || 76;
64
52
  }
65
-
66
53
  this._curLine = '';
67
54
  this._remainingBytes = false;
68
-
69
55
  this.inputBytes = 0;
70
56
  this.outputBytes = 0;
71
57
  }
72
-
58
+ /** @internal */
73
59
  _transform(chunk, encoding, done) {
74
- if (encoding !== 'buffer') {
75
- chunk = Buffer.from(chunk, encoding);
60
+ let buf = encoding !== 'buffer' ? Buffer.from(chunk, encoding) : chunk;
61
+ if (!buf || !buf.length) {
62
+ setImmediate(done);
63
+ return;
76
64
  }
77
-
78
- if (!chunk || !chunk.length) {
79
- return setImmediate(done);
80
- }
81
-
82
- this.inputBytes += chunk.length;
83
-
65
+ this.inputBytes += buf.length;
84
66
  if (this._remainingBytes && this._remainingBytes.length) {
85
- chunk = Buffer.concat([this._remainingBytes, chunk], this._remainingBytes.length + chunk.length);
67
+ buf = Buffer.concat([this._remainingBytes, buf], this._remainingBytes.length + buf.length);
86
68
  this._remainingBytes = false;
87
69
  }
88
-
89
- if (chunk.length % 3) {
90
- this._remainingBytes = chunk.slice(chunk.length - (chunk.length % 3));
91
- chunk = chunk.slice(0, chunk.length - (chunk.length % 3));
92
- } else {
70
+ if (buf.length % 3) {
71
+ this._remainingBytes = buf.slice(buf.length - (buf.length % 3));
72
+ buf = buf.slice(0, buf.length - (buf.length % 3));
73
+ }
74
+ else {
93
75
  this._remainingBytes = false;
94
76
  }
95
-
96
- let b64 = this._curLine + encode(chunk);
97
-
77
+ let b64 = this._curLine + encode(buf);
98
78
  if (this.options.lineLength) {
99
79
  b64 = wrap(b64, this.options.lineLength);
100
-
101
80
  // remove last line as it is still most probably incomplete
102
- let lastLF = b64.lastIndexOf('\n');
81
+ const lastLF = b64.lastIndexOf('\n');
103
82
  if (lastLF < 0) {
104
83
  this._curLine = b64;
105
84
  b64 = '';
106
- } else if (lastLF === b64.length - 1) {
85
+ }
86
+ else if (lastLF === b64.length - 1) {
107
87
  this._curLine = '';
108
- } else {
109
- this._curLine = b64.substr(lastLF + 1);
110
- b64 = b64.substr(0, lastLF + 1);
88
+ }
89
+ else {
90
+ this._curLine = b64.substring(lastLF + 1);
91
+ b64 = b64.substring(0, lastLF + 1);
111
92
  }
112
93
  }
113
-
114
94
  if (b64) {
115
95
  this.outputBytes += b64.length;
116
96
  this.push(Buffer.from(b64, 'ascii'));
117
97
  }
118
-
119
98
  setImmediate(done);
120
99
  }
121
-
100
+ /** @internal */
122
101
  _flush(done) {
123
102
  if (this._remainingBytes && this._remainingBytes.length) {
124
103
  this._curLine += encode(this._remainingBytes);
125
104
  }
126
-
127
105
  if (this._curLine) {
128
106
  this._curLine = wrap(this._curLine, this.options.lineLength);
129
107
  this.outputBytes += this._curLine.length;
130
- this.push(this._curLine, 'ascii');
108
+ this.push(Buffer.from(this._curLine, 'ascii'));
131
109
  this._curLine = '';
132
110
  }
133
111
  done();
134
112
  }
135
113
  }
136
-
137
- // expose to the world
138
- module.exports = {
139
- encode,
140
- wrap,
141
- Encoder
142
- };
@@ -0,0 +1,52 @@
1
+ import { type DKIMKey, type DKIMPrivateKey, type DKIMSignOptions } from './sign.js';
2
+ import { PassThrough, type Readable } from 'node:stream';
3
+ /**
4
+ * A single DKIM signing key
5
+ */
6
+ export type { DKIMKey, DKIMPrivateKey, DKIMSignOptions };
7
+ /**
8
+ * Options for the DKIM signer
9
+ */
10
+ export interface DKIMOptions extends DKIMSignOptions {
11
+ /** One or more signing keys, used instead of the domainName, keySelector and privateKey options */
12
+ keys?: DKIMKey | DKIMKey[] | undefined;
13
+ /** Directory for buffering large message bodies to disk, no buffering when not set */
14
+ cacheDir?: string | false | undefined;
15
+ /** Body size in bytes from which the body is buffered to cacheDir, defaults to 10 MB */
16
+ cacheTreshold?: number | undefined;
17
+ /** Hash algorithm for the body hash and the signature, defaults to sha256 */
18
+ hashAlgo?: string | undefined;
19
+ }
20
+ /**
21
+ * The signed message as returned by DKIM#sign
22
+ */
23
+ export interface DKIMSignedStream extends PassThrough {
24
+ /** true if the message body was buffered to cacheDir while signing */
25
+ usingCache: boolean;
26
+ }
27
+ declare class DKIM {
28
+ options: DKIMOptions;
29
+ keys: DKIMKey[];
30
+ constructor(options: DKIMOptions);
31
+ sign(input: Readable | Buffer | string, extraOptions?: DKIMOptions): DKIMSignedStream;
32
+ }
33
+ /** The signer options without any key material */
34
+ export type DKIMOptionalOptions = Omit<DKIMOptions, 'keys' | 'domainName' | 'keySelector' | 'privateKey'>;
35
+ /** The signer options for a single key given as domainName, keySelector and privateKey */
36
+ export type DKIMSingleKeyOptions = Omit<DKIMOptions, 'keys'>;
37
+ /** The signer options for one or more keys given through `keys` */
38
+ export type DKIMMultipleKeysOptions = DKIMOptionalOptions & {
39
+ keys: DKIMKey | DKIMKey[];
40
+ };
41
+ /**
42
+ * Type aliases in the layout of @types/nodemailer, so `DKIM.Options` style references keep working
43
+ */
44
+ declare namespace DKIM {
45
+ type Options = DKIMOptions;
46
+ type OptionalOptions = DKIMOptionalOptions;
47
+ type SingleKeyOptions = DKIMSingleKeyOptions;
48
+ type MultipleKeysOptions = DKIMMultipleKeysOptions;
49
+ }
50
+ /** The same aliases as module level exports, for `import * as DKIM` and `import DKIM = require()` */
51
+ export type { DKIMOptions as Options, DKIMOptionalOptions as OptionalOptions, DKIMSingleKeyOptions as SingleKeyOptions, DKIMMultipleKeysOptions as MultipleKeysOptions };
52
+ export default DKIM;
@@ -1,75 +1,49 @@
1
- 'use strict';
2
-
3
1
  // FIXME:
4
2
  // replace this Transform mess with a method that pipes input argument to output argument
5
-
6
- const MessageParser = require('./message-parser');
7
- const RelaxedBody = require('./relaxed-body');
8
- const sign = require('./sign');
9
- const PassThrough = require('stream').PassThrough;
10
- const fs = require('fs');
11
- const path = require('path');
12
- const crypto = require('crypto');
13
-
3
+ import MessageParser from './message-parser.js';
4
+ import RelaxedBody from './relaxed-body.js';
5
+ import sign from './sign.js';
6
+ import { PassThrough } from 'node:stream';
7
+ import fs from 'node:fs';
8
+ import path from 'node:path';
9
+ import crypto from 'node:crypto';
10
+ import { copyOwnKeys } from '../shared/objects.js';
14
11
  const DKIM_ALGO = 'sha256';
15
- const MAX_MESSAGE_SIZE = 128 * 1024; // buffer messages larger than this to disk
16
-
17
- /*
18
- // Usage:
19
-
20
- let dkim = new DKIM({
21
- domainName: 'example.com',
22
- keySelector: 'key-selector',
23
- privateKey,
24
- cacheDir: '/tmp'
25
- });
26
- dkim.sign(input).pipe(process.stdout);
27
-
28
- // Where inputStream is a rfc822 message (either a stream, string or Buffer)
29
- // and outputStream is a DKIM signed rfc822 message
30
- */
31
-
12
+ const MAX_MESSAGE_SIZE = 10 * 1024 * 1024; // buffer messages larger than this to disk
32
13
  class DKIMSigner {
33
14
  constructor(options, keys, input, output) {
34
15
  this.options = options || {};
35
16
  this.keys = keys;
36
-
37
17
  this.cacheTreshold = Number(this.options.cacheTreshold) || MAX_MESSAGE_SIZE;
38
18
  this.hashAlgo = this.options.hashAlgo || DKIM_ALGO;
39
-
40
19
  this.cacheDir = this.options.cacheDir || false;
41
-
42
20
  this.chunks = [];
43
21
  this.chunklen = 0;
44
22
  this.readPos = 0;
45
- this.cachePath = this.cacheDir ? path.join(this.cacheDir, 'message.' + Date.now() + '-' + crypto.randomBytes(14).toString('hex')) : false;
23
+ this.cachePath = this.cacheDir
24
+ ? path.join(this.cacheDir, 'message.' + Date.now() + '-' + crypto.randomBytes(14).toString('hex'))
25
+ : false;
46
26
  this.cache = false;
47
-
48
27
  this.headers = false;
49
28
  this.bodyHash = false;
50
29
  this.parser = false;
51
30
  this.relaxedBody = false;
52
-
53
31
  this.input = input;
54
32
  this.output = output;
55
33
  this.output.usingCache = false;
56
-
57
34
  this.hasErrored = false;
58
-
59
35
  this.input.on('error', err => {
60
36
  this.hasErrored = true;
61
37
  this.cleanup();
62
38
  output.emit('error', err);
63
39
  });
64
40
  }
65
-
66
41
  cleanup() {
67
42
  if (!this.cache || !this.cachePath) {
68
43
  return;
69
44
  }
70
45
  fs.unlink(this.cachePath, () => false);
71
46
  }
72
-
73
47
  createReadCache() {
74
48
  // pipe remainings to cache file
75
49
  this.cache = fs.createReadStream(this.cachePath);
@@ -82,56 +56,62 @@ class DKIMSigner {
82
56
  });
83
57
  this.cache.pipe(this.output);
84
58
  }
85
-
86
59
  sendNextChunk() {
87
60
  if (this.hasErrored) {
88
61
  return;
89
62
  }
90
-
91
63
  if (this.readPos >= this.chunks.length) {
92
64
  if (!this.cache) {
93
- return this.output.end();
65
+ this.output.end();
66
+ return;
94
67
  }
95
68
  return this.createReadCache();
96
69
  }
97
- let chunk = this.chunks[this.readPos++];
70
+ const chunk = this.chunks[this.readPos++];
98
71
  if (this.output.write(chunk) === false) {
99
- return this.output.once('drain', () => {
72
+ this.output.once('drain', () => {
100
73
  this.sendNextChunk();
101
74
  });
75
+ return;
102
76
  }
103
77
  setImmediate(() => this.sendNextChunk());
104
78
  }
105
-
106
79
  sendSignedOutput() {
107
80
  let keyPos = 0;
108
- let signNextKey = () => {
81
+ const signNextKey = () => {
109
82
  if (keyPos >= this.keys.length) {
110
83
  this.output.write(this.parser.rawHeaders);
111
- return setImmediate(() => this.sendNextChunk());
84
+ setImmediate(() => this.sendNextChunk());
85
+ return;
86
+ }
87
+ const key = this.keys[keyPos++];
88
+ let dkimField;
89
+ try {
90
+ dkimField = sign(this.headers, this.hashAlgo, this.bodyHash, {
91
+ domainName: key.domainName,
92
+ keySelector: key.keySelector,
93
+ privateKey: key.privateKey,
94
+ headerFieldNames: this.options.headerFieldNames,
95
+ skipFields: this.options.skipFields
96
+ });
97
+ }
98
+ catch (err) {
99
+ this.hasErrored = true;
100
+ this.cleanup();
101
+ this.output.emit('error', err);
102
+ return;
112
103
  }
113
- let key = this.keys[keyPos++];
114
- let dkimField = sign(this.headers, this.hashAlgo, this.bodyHash, {
115
- domainName: key.domainName,
116
- keySelector: key.keySelector,
117
- privateKey: key.privateKey,
118
- headerFieldNames: this.options.headerFieldNames,
119
- skipFields: this.options.skipFields
120
- });
121
104
  if (dkimField) {
122
105
  this.output.write(Buffer.from(dkimField + '\r\n'));
123
106
  }
124
- return setImmediate(signNextKey);
107
+ setImmediate(signNextKey);
125
108
  };
126
-
127
109
  if (this.bodyHash && this.headers) {
128
110
  return signNextKey();
129
111
  }
130
-
131
112
  this.output.write(this.parser.rawHeaders);
132
113
  this.sendNextChunk();
133
114
  }
134
-
135
115
  createWriteCache() {
136
116
  this.output.usingCache = true;
137
117
  // pipe remainings to cache file
@@ -155,21 +135,17 @@ class DKIMSigner {
155
135
  this.relaxedBody.removeAllListeners('readable');
156
136
  this.relaxedBody.pipe(this.cache);
157
137
  }
158
-
159
138
  signStream() {
160
139
  this.parser = new MessageParser();
161
140
  this.relaxedBody = new RelaxedBody({
162
141
  hashAlgo: this.hashAlgo
163
142
  });
164
-
165
143
  this.parser.on('headers', value => {
166
144
  this.headers = value;
167
145
  });
168
-
169
146
  this.relaxedBody.on('hash', value => {
170
147
  this.bodyHash = value;
171
148
  });
172
-
173
149
  this.relaxedBody.on('readable', () => {
174
150
  let chunk;
175
151
  if (this.cache) {
@@ -183,69 +159,63 @@ class DKIMSigner {
183
159
  }
184
160
  }
185
161
  });
186
-
187
162
  this.relaxedBody.on('end', () => {
188
163
  if (this.cache) {
189
164
  return;
190
165
  }
191
166
  this.sendSignedOutput();
192
167
  });
193
-
194
168
  this.parser.pipe(this.relaxedBody);
195
169
  setImmediate(() => this.input.pipe(this.parser));
196
170
  }
197
171
  }
198
-
199
172
  class DKIM {
200
173
  constructor(options) {
201
174
  this.options = options || {};
202
- this.keys = [].concat(
203
- this.options.keys || {
204
- domainName: options.domainName,
205
- keySelector: options.keySelector,
206
- privateKey: options.privateKey
207
- }
208
- );
175
+ this.keys = [].concat(this.options.keys || {
176
+ domainName: options.domainName,
177
+ keySelector: options.keySelector,
178
+ privateKey: options.privateKey
179
+ });
209
180
  }
210
-
211
181
  sign(input, extraOptions) {
212
- let output = new PassThrough();
182
+ const output = new PassThrough();
213
183
  let inputStream = input;
214
184
  let writeValue = false;
215
-
216
185
  if (Buffer.isBuffer(input)) {
217
186
  writeValue = input;
218
187
  inputStream = new PassThrough();
219
- } else if (typeof input === 'string') {
188
+ }
189
+ else if (typeof input === 'string') {
220
190
  writeValue = Buffer.from(input);
221
191
  inputStream = new PassThrough();
222
192
  }
223
-
224
193
  let options = this.options;
225
194
  if (extraOptions && Object.keys(extraOptions).length) {
226
- options = {};
227
- Object.keys(this.options || {}).forEach(key => {
228
- options[key] = this.options[key];
229
- });
230
- Object.keys(extraOptions || {}).forEach(key => {
231
- if (!(key in options)) {
232
- options[key] = extraOptions[key];
233
- }
234
- });
195
+ // extraOptions is mail.data._dkim, caller supplied message data. An own
196
+ // "__proto__" key there would let every option this signer reads and the
197
+ // transport did not set, such as skipFields, answer from the caller
198
+ options = copyOwnKeys({}, extraOptions);
199
+ copyOwnKeys(options, this.options);
235
200
  }
236
-
237
- let signer = new DKIMSigner(options, this.keys, inputStream, output);
201
+ const signer = new DKIMSigner(options, this.keys, inputStream, output);
238
202
  setImmediate(() => {
239
- signer.signStream();
203
+ try {
204
+ signer.signStream();
205
+ }
206
+ catch (_E) {
207
+ // the body hash is created here, an unknown hashAlgo throws inside this timer
208
+ // where nothing else could catch it
209
+ output.emit('error', sign.unsupportedHashAlgoError(signer.hashAlgo));
210
+ return;
211
+ }
240
212
  if (writeValue) {
241
213
  setImmediate(() => {
242
214
  inputStream.end(writeValue);
243
215
  });
244
216
  }
245
217
  });
246
-
247
218
  return output;
248
219
  }
249
220
  }
250
-
251
- module.exports = DKIM;
221
+ export default DKIM;
@@ -0,0 +1,48 @@
1
+ import { Transform, type TransformOptions } from 'node:stream';
2
+ /**
3
+ * A header line as emitted with the 'headers' event
4
+ */
5
+ export interface MessageParserHeaderLine {
6
+ /** Lowercase header field name */
7
+ key: string;
8
+ /** Full header line, folded continuation lines included, one character per byte ('binary' encoding) */
9
+ line: string;
10
+ }
11
+ /**
12
+ * MessageParser instance is a transform stream that separates message headers
13
+ * from the rest of the body. Headers are emitted with the 'headers' event. Message
14
+ * body is passed on as the resulting stream.
15
+ */
16
+ declare class MessageParser extends Transform {
17
+ lastBytes: Buffer;
18
+ headersParsed: boolean;
19
+ headerBytes: number;
20
+ headerChunks: Buffer[] | null;
21
+ rawHeaders: Buffer | false;
22
+ bodySize: number;
23
+ constructor(options?: TransformOptions);
24
+ /**
25
+ * Keeps count of the last 4 bytes in order to detect line breaks on chunk boundaries
26
+ *
27
+ * @param data Next data chunk from the stream
28
+ */
29
+ updateLastBytes(data: Buffer): void;
30
+ /**
31
+ * Finds and removes message headers from the remaining body. We want to keep
32
+ * headers separated until final delivery to be able to modify these
33
+ *
34
+ * @param data Next chunk of data
35
+ * @return Returns true if headers are already found or false otherwise
36
+ */
37
+ checkHeaders(data: Buffer): boolean;
38
+ parseHeaders(): MessageParserHeaderLine[];
39
+ }
40
+ /**
41
+ * Type aliases in the layout of @types/nodemailer, so `MessageParser.Header` style references keep working
42
+ */
43
+ declare namespace MessageParser {
44
+ type Header = MessageParserHeaderLine;
45
+ }
46
+ /** The same alias as a module level export, for `import * as MessageParser` and `import MessageParser = require()` */
47
+ export type { MessageParserHeaderLine as Header };
48
+ export default MessageParser;