@nocobase/plugin-workflow-mailer 2.3.0-beta.13 → 2.3.0-beta.15

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 (173) hide show
  1. package/dist/externalVersion.js +6 -6
  2. package/dist/node_modules/joi/package.json +1 -1
  3. package/dist/node_modules/nodemailer/dist/cjs/addressparser/index.d.ts +59 -0
  4. package/dist/node_modules/nodemailer/dist/cjs/addressparser/index.js +790 -0
  5. package/dist/node_modules/nodemailer/dist/cjs/base64/index.d.ts +36 -0
  6. package/dist/node_modules/nodemailer/dist/cjs/base64/index.js +119 -0
  7. package/dist/node_modules/nodemailer/dist/cjs/dkim/index.d.ts +52 -0
  8. package/dist/node_modules/nodemailer/dist/cjs/dkim/index.js +228 -0
  9. package/dist/node_modules/nodemailer/dist/cjs/dkim/message-parser.d.ts +48 -0
  10. package/dist/node_modules/nodemailer/dist/cjs/dkim/message-parser.js +180 -0
  11. package/dist/node_modules/nodemailer/dist/cjs/dkim/relaxed-body.d.ts +36 -0
  12. package/dist/node_modules/nodemailer/dist/cjs/dkim/relaxed-body.js +148 -0
  13. package/dist/node_modules/nodemailer/dist/cjs/dkim/sign.d.ts +52 -0
  14. package/dist/node_modules/nodemailer/dist/cjs/dkim/sign.js +165 -0
  15. package/dist/node_modules/nodemailer/dist/cjs/errors.d.ts +96 -0
  16. package/dist/node_modules/nodemailer/dist/cjs/errors.js +70 -0
  17. package/dist/node_modules/nodemailer/dist/cjs/fetch/cookies.d.ts +107 -0
  18. package/dist/node_modules/nodemailer/dist/cjs/fetch/cookies.js +282 -0
  19. package/dist/node_modules/nodemailer/dist/cjs/fetch/index.d.ts +65 -0
  20. package/dist/node_modules/nodemailer/dist/cjs/fetch/index.js +384 -0
  21. package/dist/node_modules/nodemailer/dist/cjs/json-transport/index.d.ts +64 -0
  22. package/dist/node_modules/nodemailer/dist/cjs/json-transport/index.js +99 -0
  23. package/dist/node_modules/nodemailer/dist/cjs/mail-composer/index.d.ts +174 -0
  24. package/dist/node_modules/nodemailer/dist/cjs/mail-composer/index.js +613 -0
  25. package/dist/node_modules/nodemailer/dist/cjs/mailer/index.d.ts +237 -0
  26. package/dist/node_modules/nodemailer/dist/cjs/mailer/index.js +415 -0
  27. package/dist/node_modules/nodemailer/dist/cjs/mailer/mail-message.d.ts +97 -0
  28. package/dist/node_modules/nodemailer/dist/cjs/mailer/mail-message.js +342 -0
  29. package/dist/node_modules/nodemailer/dist/cjs/mime-funcs/index.d.ts +161 -0
  30. package/dist/node_modules/nodemailer/dist/cjs/mime-funcs/index.js +787 -0
  31. package/dist/node_modules/nodemailer/dist/cjs/mime-funcs/mime-types.d.ts +2 -0
  32. package/dist/node_modules/nodemailer/dist/cjs/mime-funcs/mime-types.js +2103 -0
  33. package/dist/node_modules/nodemailer/dist/cjs/mime-node/index.d.ts +333 -0
  34. package/dist/node_modules/nodemailer/dist/cjs/mime-node/index.js +1493 -0
  35. package/dist/node_modules/nodemailer/dist/cjs/mime-node/last-newline.d.ts +5 -0
  36. package/dist/node_modules/nodemailer/dist/cjs/mime-node/last-newline.js +32 -0
  37. package/dist/node_modules/nodemailer/dist/cjs/mime-node/le-unix.d.ts +9 -0
  38. package/dist/node_modules/nodemailer/dist/cjs/mime-node/le-unix.js +40 -0
  39. package/dist/node_modules/nodemailer/dist/cjs/mime-node/le-windows.d.ts +10 -0
  40. package/dist/node_modules/nodemailer/dist/cjs/mime-node/le-windows.js +47 -0
  41. package/dist/node_modules/nodemailer/dist/cjs/nodemailer.d.ts +124 -0
  42. package/dist/node_modules/nodemailer/dist/cjs/nodemailer.js +1 -0
  43. package/dist/node_modules/nodemailer/dist/cjs/package-info.d.ts +3 -0
  44. package/dist/node_modules/nodemailer/dist/cjs/package-info.js +7 -0
  45. package/dist/node_modules/nodemailer/dist/cjs/package.json +3 -0
  46. package/dist/node_modules/nodemailer/dist/cjs/punycode/index.d.ts +73 -0
  47. package/dist/node_modules/nodemailer/{lib → dist/cjs}/punycode/index.js +62 -111
  48. package/dist/node_modules/nodemailer/dist/cjs/qp/index.d.ts +32 -0
  49. package/dist/node_modules/nodemailer/dist/cjs/qp/index.js +207 -0
  50. package/dist/node_modules/nodemailer/dist/cjs/sendmail-transport/index.d.ts +69 -0
  51. package/dist/node_modules/nodemailer/dist/cjs/sendmail-transport/index.js +210 -0
  52. package/dist/node_modules/nodemailer/dist/cjs/ses-transport/index.d.ts +112 -0
  53. package/dist/node_modules/nodemailer/dist/cjs/ses-transport/index.js +252 -0
  54. package/dist/node_modules/nodemailer/dist/cjs/shared/index.d.ts +260 -0
  55. package/dist/node_modules/nodemailer/dist/cjs/shared/index.js +680 -0
  56. package/dist/node_modules/nodemailer/dist/cjs/shared/objects.d.ts +23 -0
  57. package/dist/node_modules/nodemailer/dist/cjs/shared/objects.js +43 -0
  58. package/dist/node_modules/nodemailer/dist/cjs/shared/url.d.ts +21 -0
  59. package/dist/node_modules/nodemailer/dist/cjs/shared/url.js +255 -0
  60. package/dist/node_modules/nodemailer/dist/cjs/smtp-connection/data-stream.d.ts +15 -0
  61. package/dist/node_modules/nodemailer/dist/cjs/smtp-connection/data-stream.js +108 -0
  62. package/dist/node_modules/nodemailer/dist/cjs/smtp-connection/http-proxy-client.d.ts +47 -0
  63. package/dist/node_modules/nodemailer/dist/cjs/smtp-connection/http-proxy-client.js +189 -0
  64. package/dist/node_modules/nodemailer/dist/cjs/smtp-connection/index.d.ts +416 -0
  65. package/dist/node_modules/nodemailer/dist/cjs/smtp-connection/index.js +1837 -0
  66. package/dist/node_modules/nodemailer/dist/cjs/smtp-pool/index.d.ts +133 -0
  67. package/dist/node_modules/nodemailer/dist/cjs/smtp-pool/index.js +569 -0
  68. package/dist/node_modules/nodemailer/dist/cjs/smtp-pool/pool-resource.d.ts +62 -0
  69. package/dist/node_modules/nodemailer/dist/cjs/smtp-pool/pool-resource.js +257 -0
  70. package/dist/node_modules/nodemailer/dist/cjs/smtp-transport/index.d.ts +156 -0
  71. package/dist/node_modules/nodemailer/dist/cjs/smtp-transport/index.js +371 -0
  72. package/dist/node_modules/nodemailer/dist/cjs/stream-transport/index.d.ts +65 -0
  73. package/dist/node_modules/nodemailer/dist/cjs/stream-transport/index.js +146 -0
  74. package/dist/node_modules/nodemailer/dist/cjs/well-known/index.d.ts +35 -0
  75. package/dist/node_modules/nodemailer/dist/cjs/well-known/index.js +41 -0
  76. package/dist/node_modules/nodemailer/dist/cjs/well-known/services.d.ts +2 -0
  77. package/dist/node_modules/nodemailer/dist/cjs/well-known/services.js +674 -0
  78. package/dist/node_modules/nodemailer/dist/cjs/xoauth2/index.d.ts +201 -0
  79. package/dist/node_modules/nodemailer/dist/cjs/xoauth2/index.js +426 -0
  80. package/dist/node_modules/nodemailer/dist/esm/addressparser/index.d.ts +59 -0
  81. package/dist/node_modules/nodemailer/{lib → dist/esm}/addressparser/index.js +361 -131
  82. package/dist/node_modules/nodemailer/dist/esm/base64/index.d.ts +36 -0
  83. package/dist/node_modules/nodemailer/{lib → dist/esm}/base64/index.js +31 -56
  84. package/dist/node_modules/nodemailer/dist/esm/dkim/index.d.ts +52 -0
  85. package/dist/node_modules/nodemailer/{lib → dist/esm}/dkim/index.js +49 -78
  86. package/dist/node_modules/nodemailer/dist/esm/dkim/message-parser.d.ts +48 -0
  87. package/dist/node_modules/nodemailer/{lib → dist/esm}/dkim/message-parser.js +64 -42
  88. package/dist/node_modules/nodemailer/dist/esm/dkim/relaxed-body.d.ts +36 -0
  89. package/dist/node_modules/nodemailer/dist/esm/dkim/relaxed-body.js +141 -0
  90. package/dist/node_modules/nodemailer/dist/esm/dkim/sign.d.ts +52 -0
  91. package/dist/node_modules/nodemailer/{lib → dist/esm}/dkim/sign.js +50 -46
  92. package/dist/node_modules/nodemailer/dist/esm/errors.d.ts +96 -0
  93. package/dist/node_modules/nodemailer/{lib → dist/esm}/errors.js +26 -18
  94. package/dist/node_modules/nodemailer/dist/esm/fetch/cookies.d.ts +107 -0
  95. package/dist/node_modules/nodemailer/dist/esm/fetch/cookies.js +242 -0
  96. package/dist/node_modules/nodemailer/dist/esm/fetch/index.d.ts +65 -0
  97. package/dist/node_modules/nodemailer/{lib → dist/esm}/fetch/index.js +80 -147
  98. package/dist/node_modules/nodemailer/dist/esm/json-transport/index.d.ts +64 -0
  99. package/dist/node_modules/nodemailer/{lib → dist/esm}/json-transport/index.js +19 -39
  100. package/dist/node_modules/nodemailer/dist/esm/mail-composer/index.d.ts +174 -0
  101. package/dist/node_modules/nodemailer/{lib → dist/esm}/mail-composer/index.js +199 -265
  102. package/dist/node_modules/nodemailer/dist/esm/mailer/index.d.ts +237 -0
  103. package/dist/node_modules/nodemailer/{lib → dist/esm}/mailer/index.js +128 -234
  104. package/dist/node_modules/nodemailer/dist/esm/mailer/mail-message.d.ts +97 -0
  105. package/dist/node_modules/nodemailer/{lib → dist/esm}/mailer/mail-message.js +62 -114
  106. package/dist/node_modules/nodemailer/dist/esm/mime-funcs/index.d.ts +161 -0
  107. package/dist/node_modules/nodemailer/dist/esm/mime-funcs/index.js +738 -0
  108. package/dist/node_modules/nodemailer/dist/esm/mime-funcs/mime-types.d.ts +2 -0
  109. package/dist/node_modules/nodemailer/{lib → dist/esm}/mime-funcs/mime-types.js +29 -42
  110. package/dist/node_modules/nodemailer/dist/esm/mime-node/index.d.ts +333 -0
  111. package/dist/node_modules/nodemailer/{lib → dist/esm}/mime-node/index.js +259 -372
  112. package/dist/node_modules/nodemailer/dist/esm/mime-node/last-newline.d.ts +5 -0
  113. package/dist/node_modules/nodemailer/{lib → dist/esm}/mime-node/last-newline.js +4 -10
  114. package/dist/node_modules/nodemailer/dist/esm/mime-node/le-unix.d.ts +9 -0
  115. package/dist/node_modules/nodemailer/{lib → dist/esm}/mime-node/le-unix.js +6 -11
  116. package/dist/node_modules/nodemailer/dist/esm/mime-node/le-windows.d.ts +10 -0
  117. package/dist/node_modules/nodemailer/{lib → dist/esm}/mime-node/le-windows.js +6 -13
  118. package/dist/node_modules/nodemailer/dist/esm/nodemailer.d.ts +124 -0
  119. package/dist/node_modules/nodemailer/dist/esm/nodemailer.js +166 -0
  120. package/dist/node_modules/nodemailer/dist/esm/package-info.d.ts +3 -0
  121. package/dist/node_modules/nodemailer/dist/esm/package-info.js +4 -0
  122. package/dist/node_modules/nodemailer/dist/esm/package.json +3 -0
  123. package/dist/node_modules/nodemailer/dist/esm/punycode/index.d.ts +73 -0
  124. package/dist/node_modules/nodemailer/dist/esm/punycode/index.js +405 -0
  125. package/dist/node_modules/nodemailer/dist/esm/qp/index.d.ts +32 -0
  126. package/dist/node_modules/nodemailer/{lib → dist/esm}/qp/index.js +38 -67
  127. package/dist/node_modules/nodemailer/dist/esm/sendmail-transport/index.d.ts +69 -0
  128. package/dist/node_modules/nodemailer/{lib → dist/esm}/sendmail-transport/index.js +51 -101
  129. package/dist/node_modules/nodemailer/dist/esm/ses-transport/index.d.ts +112 -0
  130. package/dist/node_modules/nodemailer/dist/esm/ses-transport/index.js +212 -0
  131. package/dist/node_modules/nodemailer/dist/esm/shared/index.d.ts +260 -0
  132. package/dist/node_modules/nodemailer/{lib → dist/esm}/shared/index.js +156 -272
  133. package/dist/node_modules/nodemailer/dist/esm/shared/objects.d.ts +23 -0
  134. package/dist/node_modules/nodemailer/{lib → dist/esm}/shared/objects.js +13 -17
  135. package/dist/node_modules/nodemailer/dist/esm/shared/url.d.ts +21 -0
  136. package/dist/node_modules/nodemailer/dist/esm/shared/url.js +214 -0
  137. package/dist/node_modules/nodemailer/dist/esm/smtp-connection/data-stream.d.ts +15 -0
  138. package/dist/node_modules/nodemailer/dist/esm/smtp-connection/data-stream.js +103 -0
  139. package/dist/node_modules/nodemailer/dist/esm/smtp-connection/http-proxy-client.d.ts +47 -0
  140. package/dist/node_modules/nodemailer/{lib → dist/esm}/smtp-connection/http-proxy-client.js +49 -74
  141. package/dist/node_modules/nodemailer/dist/esm/smtp-connection/index.d.ts +416 -0
  142. package/dist/node_modules/nodemailer/{lib → dist/esm}/smtp-connection/index.js +574 -794
  143. package/dist/node_modules/nodemailer/dist/esm/smtp-pool/index.d.ts +133 -0
  144. package/dist/node_modules/nodemailer/{lib → dist/esm}/smtp-pool/index.js +172 -284
  145. package/dist/node_modules/nodemailer/dist/esm/smtp-pool/pool-resource.d.ts +62 -0
  146. package/dist/node_modules/nodemailer/{lib → dist/esm}/smtp-pool/pool-resource.js +57 -97
  147. package/dist/node_modules/nodemailer/dist/esm/smtp-transport/index.d.ts +156 -0
  148. package/dist/node_modules/nodemailer/{lib → dist/esm}/smtp-transport/index.js +81 -179
  149. package/dist/node_modules/nodemailer/dist/esm/stream-transport/index.d.ts +65 -0
  150. package/dist/node_modules/nodemailer/{lib → dist/esm}/stream-transport/index.js +36 -74
  151. package/dist/node_modules/nodemailer/dist/esm/well-known/index.d.ts +35 -0
  152. package/dist/node_modules/nodemailer/{lib → dist/esm}/well-known/index.js +5 -16
  153. package/dist/node_modules/nodemailer/dist/esm/well-known/services.d.ts +2 -0
  154. package/dist/node_modules/nodemailer/dist/esm/well-known/services.js +671 -0
  155. package/dist/node_modules/nodemailer/dist/esm/xoauth2/index.d.ts +201 -0
  156. package/dist/node_modules/nodemailer/{lib → dist/esm}/xoauth2/index.js +125 -187
  157. package/dist/node_modules/nodemailer/{lib → dist}/well-known/services.json +9 -2
  158. package/dist/node_modules/nodemailer/package.json +1 -1
  159. package/package.json +3 -3
  160. package/dist/node_modules/nodemailer/.gitattributes +0 -6
  161. package/dist/node_modules/nodemailer/.ncurc.js +0 -9
  162. package/dist/node_modules/nodemailer/.prettierignore +0 -8
  163. package/dist/node_modules/nodemailer/.prettierrc +0 -12
  164. package/dist/node_modules/nodemailer/.prettierrc.js +0 -10
  165. package/dist/node_modules/nodemailer/.release-please-config.json +0 -9
  166. package/dist/node_modules/nodemailer/eslint.config.js +0 -88
  167. package/dist/node_modules/nodemailer/lib/dkim/relaxed-body.js +0 -154
  168. package/dist/node_modules/nodemailer/lib/fetch/cookies.js +0 -276
  169. package/dist/node_modules/nodemailer/lib/mime-funcs/index.js +0 -671
  170. package/dist/node_modules/nodemailer/lib/nodemailer.js +0 -1
  171. package/dist/node_modules/nodemailer/lib/ses-transport/index.js +0 -266
  172. package/dist/node_modules/nodemailer/lib/shared/url.js +0 -151
  173. package/dist/node_modules/nodemailer/lib/smtp-connection/data-stream.js +0 -105
@@ -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,36 +1,30 @@
1
- 'use strict';
2
-
3
- const { Transform } = require('stream');
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
28
  const result = [];
35
29
  let pos = 0;
36
30
  const chunkLength = lineLength * 1024;
@@ -40,87 +34,74 @@ function wrap(str, lineLength) {
40
34
  result.push(wrappedLines);
41
35
  pos += chunkLength;
42
36
  }
43
-
44
37
  return result.join('\r\n').trim();
45
38
  }
46
-
47
39
  /**
48
40
  * Creates a transform stream for encoding data to base64 encoding
49
41
  *
50
42
  * @constructor
51
- * @param {Object} options Stream options
52
- * @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
53
45
  */
54
- class Encoder extends Transform {
46
+ export class Encoder extends Transform {
55
47
  constructor(options) {
56
48
  super();
57
49
  this.options = options || {};
58
-
59
50
  if (this.options.lineLength !== false) {
60
51
  this.options.lineLength = this.options.lineLength || 76;
61
52
  }
62
-
63
53
  this._curLine = '';
64
54
  this._remainingBytes = false;
65
-
66
55
  this.inputBytes = 0;
67
56
  this.outputBytes = 0;
68
57
  }
69
-
58
+ /** @internal */
70
59
  _transform(chunk, encoding, done) {
71
- if (encoding !== 'buffer') {
72
- 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;
73
64
  }
74
-
75
- if (!chunk || !chunk.length) {
76
- return setImmediate(done);
77
- }
78
-
79
- this.inputBytes += chunk.length;
80
-
65
+ this.inputBytes += buf.length;
81
66
  if (this._remainingBytes && this._remainingBytes.length) {
82
- chunk = Buffer.concat([this._remainingBytes, chunk], this._remainingBytes.length + chunk.length);
67
+ buf = Buffer.concat([this._remainingBytes, buf], this._remainingBytes.length + buf.length);
83
68
  this._remainingBytes = false;
84
69
  }
85
-
86
- if (chunk.length % 3) {
87
- this._remainingBytes = chunk.slice(chunk.length - (chunk.length % 3));
88
- chunk = chunk.slice(0, chunk.length - (chunk.length % 3));
89
- } 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 {
90
75
  this._remainingBytes = false;
91
76
  }
92
-
93
- let b64 = this._curLine + encode(chunk);
94
-
77
+ let b64 = this._curLine + encode(buf);
95
78
  if (this.options.lineLength) {
96
79
  b64 = wrap(b64, this.options.lineLength);
97
-
98
80
  // remove last line as it is still most probably incomplete
99
81
  const lastLF = b64.lastIndexOf('\n');
100
82
  if (lastLF < 0) {
101
83
  this._curLine = b64;
102
84
  b64 = '';
103
- } else if (lastLF === b64.length - 1) {
85
+ }
86
+ else if (lastLF === b64.length - 1) {
104
87
  this._curLine = '';
105
- } else {
88
+ }
89
+ else {
106
90
  this._curLine = b64.substring(lastLF + 1);
107
91
  b64 = b64.substring(0, lastLF + 1);
108
92
  }
109
93
  }
110
-
111
94
  if (b64) {
112
95
  this.outputBytes += b64.length;
113
96
  this.push(Buffer.from(b64, 'ascii'));
114
97
  }
115
-
116
98
  setImmediate(done);
117
99
  }
118
-
100
+ /** @internal */
119
101
  _flush(done) {
120
102
  if (this._remainingBytes && this._remainingBytes.length) {
121
103
  this._curLine += encode(this._remainingBytes);
122
104
  }
123
-
124
105
  if (this._curLine) {
125
106
  this._curLine = wrap(this._curLine, this.options.lineLength);
126
107
  this.outputBytes += this._curLine.length;
@@ -130,9 +111,3 @@ class Encoder extends Transform {
130
111
  done();
131
112
  }
132
113
  }
133
-
134
- module.exports = {
135
- encode,
136
- wrap,
137
- Encoder
138
- };
@@ -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,45 +1,22 @@
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');
10
- const fs = require('fs');
11
- const path = require('path');
12
- const crypto = require('crypto');
13
- const { copyOwnKeys } = require('../shared/objects');
14
-
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';
15
11
  const DKIM_ALGO = 'sha256';
16
- const MAX_MESSAGE_SIZE = 2 * 1024 * 1024; // buffer messages larger than this to disk
17
-
18
- /*
19
- // Usage:
20
-
21
- let dkim = new DKIM({
22
- domainName: 'example.com',
23
- keySelector: 'key-selector',
24
- privateKey,
25
- cacheDir: '/tmp'
26
- });
27
- dkim.sign(input).pipe(process.stdout);
28
-
29
- // Where inputStream is a rfc822 message (either a stream, string or Buffer)
30
- // and outputStream is a DKIM signed rfc822 message
31
- */
32
-
12
+ const MAX_MESSAGE_SIZE = 10 * 1024 * 1024; // buffer messages larger than this to disk
33
13
  class DKIMSigner {
34
14
  constructor(options, keys, input, output) {
35
15
  this.options = options || {};
36
16
  this.keys = keys;
37
-
38
17
  this.cacheTreshold = Number(this.options.cacheTreshold) || MAX_MESSAGE_SIZE;
39
18
  this.hashAlgo = this.options.hashAlgo || DKIM_ALGO;
40
-
41
19
  this.cacheDir = this.options.cacheDir || false;
42
-
43
20
  this.chunks = [];
44
21
  this.chunklen = 0;
45
22
  this.readPos = 0;
@@ -47,32 +24,26 @@ class DKIMSigner {
47
24
  ? path.join(this.cacheDir, 'message.' + Date.now() + '-' + crypto.randomBytes(14).toString('hex'))
48
25
  : false;
49
26
  this.cache = false;
50
-
51
27
  this.headers = false;
52
28
  this.bodyHash = false;
53
29
  this.parser = false;
54
30
  this.relaxedBody = false;
55
-
56
31
  this.input = input;
57
32
  this.output = output;
58
33
  this.output.usingCache = false;
59
-
60
34
  this.hasErrored = false;
61
-
62
35
  this.input.on('error', err => {
63
36
  this.hasErrored = true;
64
37
  this.cleanup();
65
38
  output.emit('error', err);
66
39
  });
67
40
  }
68
-
69
41
  cleanup() {
70
42
  if (!this.cache || !this.cachePath) {
71
43
  return;
72
44
  }
73
45
  fs.unlink(this.cachePath, () => false);
74
46
  }
75
-
76
47
  createReadCache() {
77
48
  // pipe remainings to cache file
78
49
  this.cache = fs.createReadStream(this.cachePath);
@@ -85,56 +56,62 @@ class DKIMSigner {
85
56
  });
86
57
  this.cache.pipe(this.output);
87
58
  }
88
-
89
59
  sendNextChunk() {
90
60
  if (this.hasErrored) {
91
61
  return;
92
62
  }
93
-
94
63
  if (this.readPos >= this.chunks.length) {
95
64
  if (!this.cache) {
96
- return this.output.end();
65
+ this.output.end();
66
+ return;
97
67
  }
98
68
  return this.createReadCache();
99
69
  }
100
70
  const chunk = this.chunks[this.readPos++];
101
71
  if (this.output.write(chunk) === false) {
102
- return this.output.once('drain', () => {
72
+ this.output.once('drain', () => {
103
73
  this.sendNextChunk();
104
74
  });
75
+ return;
105
76
  }
106
77
  setImmediate(() => this.sendNextChunk());
107
78
  }
108
-
109
79
  sendSignedOutput() {
110
80
  let keyPos = 0;
111
81
  const signNextKey = () => {
112
82
  if (keyPos >= this.keys.length) {
113
83
  this.output.write(this.parser.rawHeaders);
114
- return setImmediate(() => this.sendNextChunk());
84
+ setImmediate(() => this.sendNextChunk());
85
+ return;
115
86
  }
116
87
  const key = this.keys[keyPos++];
117
- const dkimField = sign(this.headers, this.hashAlgo, this.bodyHash, {
118
- domainName: key.domainName,
119
- keySelector: key.keySelector,
120
- privateKey: key.privateKey,
121
- headerFieldNames: this.options.headerFieldNames,
122
- skipFields: this.options.skipFields
123
- });
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;
103
+ }
124
104
  if (dkimField) {
125
105
  this.output.write(Buffer.from(dkimField + '\r\n'));
126
106
  }
127
- return setImmediate(signNextKey);
107
+ setImmediate(signNextKey);
128
108
  };
129
-
130
109
  if (this.bodyHash && this.headers) {
131
110
  return signNextKey();
132
111
  }
133
-
134
112
  this.output.write(this.parser.rawHeaders);
135
113
  this.sendNextChunk();
136
114
  }
137
-
138
115
  createWriteCache() {
139
116
  this.output.usingCache = true;
140
117
  // pipe remainings to cache file
@@ -158,21 +135,17 @@ class DKIMSigner {
158
135
  this.relaxedBody.removeAllListeners('readable');
159
136
  this.relaxedBody.pipe(this.cache);
160
137
  }
161
-
162
138
  signStream() {
163
139
  this.parser = new MessageParser();
164
140
  this.relaxedBody = new RelaxedBody({
165
141
  hashAlgo: this.hashAlgo
166
142
  });
167
-
168
143
  this.parser.on('headers', value => {
169
144
  this.headers = value;
170
145
  });
171
-
172
146
  this.relaxedBody.on('hash', value => {
173
147
  this.bodyHash = value;
174
148
  });
175
-
176
149
  this.relaxedBody.on('readable', () => {
177
150
  let chunk;
178
151
  if (this.cache) {
@@ -186,44 +159,37 @@ class DKIMSigner {
186
159
  }
187
160
  }
188
161
  });
189
-
190
162
  this.relaxedBody.on('end', () => {
191
163
  if (this.cache) {
192
164
  return;
193
165
  }
194
166
  this.sendSignedOutput();
195
167
  });
196
-
197
168
  this.parser.pipe(this.relaxedBody);
198
169
  setImmediate(() => this.input.pipe(this.parser));
199
170
  }
200
171
  }
201
-
202
172
  class DKIM {
203
173
  constructor(options) {
204
174
  this.options = options || {};
205
- this.keys = [].concat(
206
- this.options.keys || {
207
- domainName: options.domainName,
208
- keySelector: options.keySelector,
209
- privateKey: options.privateKey
210
- }
211
- );
175
+ this.keys = [].concat(this.options.keys || {
176
+ domainName: options.domainName,
177
+ keySelector: options.keySelector,
178
+ privateKey: options.privateKey
179
+ });
212
180
  }
213
-
214
181
  sign(input, extraOptions) {
215
182
  const output = new PassThrough();
216
183
  let inputStream = input;
217
184
  let writeValue = false;
218
-
219
185
  if (Buffer.isBuffer(input)) {
220
186
  writeValue = input;
221
187
  inputStream = new PassThrough();
222
- } else if (typeof input === 'string') {
188
+ }
189
+ else if (typeof input === 'string') {
223
190
  writeValue = Buffer.from(input);
224
191
  inputStream = new PassThrough();
225
192
  }
226
-
227
193
  let options = this.options;
228
194
  if (extraOptions && Object.keys(extraOptions).length) {
229
195
  // extraOptions is mail.data._dkim, caller supplied message data. An own
@@ -232,19 +198,24 @@ class DKIM {
232
198
  options = copyOwnKeys({}, extraOptions);
233
199
  copyOwnKeys(options, this.options);
234
200
  }
235
-
236
201
  const signer = new DKIMSigner(options, this.keys, inputStream, output);
237
202
  setImmediate(() => {
238
- 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
+ }
239
212
  if (writeValue) {
240
213
  setImmediate(() => {
241
214
  inputStream.end(writeValue);
242
215
  });
243
216
  }
244
217
  });
245
-
246
218
  return output;
247
219
  }
248
220
  }
249
-
250
- 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;