@mavogel/awscdk-rootmail 0.1.8 → 0.1.9

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 (166) hide show
  1. package/.jsii +10 -10
  2. package/lib/rootmail.js +1 -1
  3. package/lib/ses-receive.js +1 -1
  4. package/node_modules/@aws-sdk/client-cloudwatch-logs/dist-cjs/index.js +5 -5
  5. package/node_modules/@aws-sdk/client-cloudwatch-logs/dist-es/schemas/schemas_0.js +4 -4
  6. package/node_modules/@aws-sdk/client-cloudwatch-logs/dist-types/commands/DescribeDeliveryDestinationsCommand.d.ts +1 -0
  7. package/node_modules/@aws-sdk/client-cloudwatch-logs/dist-types/commands/GetDeliveryDestinationCommand.d.ts +1 -0
  8. package/node_modules/@aws-sdk/client-cloudwatch-logs/dist-types/commands/PutAccountPolicyCommand.d.ts +4 -1
  9. package/node_modules/@aws-sdk/client-cloudwatch-logs/dist-types/commands/PutDeliveryDestinationCommand.d.ts +2 -0
  10. package/node_modules/@aws-sdk/client-cloudwatch-logs/dist-types/models/models_0.d.ts +80 -36
  11. package/node_modules/@aws-sdk/client-cloudwatch-logs/dist-types/ts3.4/models/models_0.d.ts +2 -0
  12. package/node_modules/@aws-sdk/client-cloudwatch-logs/package.json +1 -1
  13. package/node_modules/@aws-sdk/client-route-53/dist-cjs/index.js +1 -1
  14. package/node_modules/@aws-sdk/client-route-53/package.json +1 -1
  15. package/node_modules/@aws-sdk/client-s3/dist-cjs/index.js +2 -1
  16. package/node_modules/@aws-sdk/client-s3/dist-es/models/enums.js +1 -0
  17. package/node_modules/@aws-sdk/client-s3/dist-types/commands/GetBucketInventoryConfigurationCommand.d.ts +1 -1
  18. package/node_modules/@aws-sdk/client-s3/dist-types/commands/ListBucketInventoryConfigurationsCommand.d.ts +1 -1
  19. package/node_modules/@aws-sdk/client-s3/dist-types/commands/PutBucketInventoryConfigurationCommand.d.ts +1 -1
  20. package/node_modules/@aws-sdk/client-s3/dist-types/models/enums.d.ts +1 -0
  21. package/node_modules/@aws-sdk/client-s3/dist-types/ts3.4/models/enums.d.ts +1 -0
  22. package/node_modules/@aws-sdk/client-s3/package.json +2 -2
  23. package/node_modules/@aws-sdk/client-ses/dist-cjs/index.js +1 -1
  24. package/node_modules/@aws-sdk/client-ses/package.json +1 -1
  25. package/node_modules/@aws-sdk/client-ssm/dist-cjs/index.js +9 -3
  26. package/node_modules/@aws-sdk/client-ssm/dist-es/models/enums.js +4 -0
  27. package/node_modules/@aws-sdk/client-ssm/dist-es/schemas/schemas_0.js +3 -2
  28. package/node_modules/@aws-sdk/client-ssm/dist-types/commands/DeleteResourcePolicyCommand.d.ts +6 -0
  29. package/node_modules/@aws-sdk/client-ssm/dist-types/commands/PutResourcePolicyCommand.d.ts +12 -0
  30. package/node_modules/@aws-sdk/client-ssm/dist-types/models/enums.d.ts +12 -0
  31. package/node_modules/@aws-sdk/client-ssm/dist-types/models/models_0.d.ts +20 -1
  32. package/node_modules/@aws-sdk/client-ssm/dist-types/models/models_1.d.ts +2 -2
  33. package/node_modules/@aws-sdk/client-ssm/dist-types/ts3.4/models/enums.d.ts +5 -0
  34. package/node_modules/@aws-sdk/client-ssm/dist-types/ts3.4/models/models_0.d.ts +2 -0
  35. package/node_modules/@aws-sdk/client-ssm/package.json +1 -1
  36. package/node_modules/@zone-eu/mailsplit/lib/flowed-decoder.js +1 -5
  37. package/node_modules/@zone-eu/mailsplit/lib/headers.js +35 -25
  38. package/node_modules/@zone-eu/mailsplit/lib/message-splitter.js +126 -79
  39. package/node_modules/@zone-eu/mailsplit/lib/mime-node.js +27 -5
  40. package/node_modules/@zone-eu/mailsplit/lib/node-rewriter.js +3 -2
  41. package/node_modules/@zone-eu/mailsplit/lib/types.d.ts +0 -3
  42. package/node_modules/@zone-eu/mailsplit/package.json +5 -5
  43. package/node_modules/libbase64/.github/workflows/release.yaml +12 -10
  44. package/node_modules/libbase64/.ncurc.js +7 -1
  45. package/node_modules/libbase64/CHANGELOG.md +7 -0
  46. package/node_modules/libbase64/lib/libbase64.js +27 -0
  47. package/node_modules/libbase64/package.json +4 -4
  48. package/node_modules/libmime/CHANGELOG.md +14 -0
  49. package/node_modules/libmime/lib/libmime.js +41 -21
  50. package/node_modules/libmime/package.json +3 -3
  51. package/node_modules/libqp/.github/workflows/release.yaml +12 -10
  52. package/node_modules/libqp/CHANGELOG.md +7 -0
  53. package/node_modules/libqp/lib/libqp.js +6 -4
  54. package/node_modules/libqp/package.json +2 -2
  55. package/node_modules/libqp/test/libqp-test.js +71 -14
  56. package/node_modules/mailparser/.release-please-manifest.json +1 -1
  57. package/node_modules/mailparser/CHANGELOG.md +42 -0
  58. package/node_modules/mailparser/README.md +5 -0
  59. package/node_modules/mailparser/lib/mail-parser.js +107 -32
  60. package/node_modules/mailparser/lib/simple-parser.js +12 -0
  61. package/node_modules/mailparser/lib/stream-hash.js +1 -1
  62. package/node_modules/mailparser/package.json +6 -6
  63. package/node_modules/nodemailer/CHANGELOG.md +38 -0
  64. package/node_modules/nodemailer/README.md +1 -1
  65. package/node_modules/nodemailer/dist/cjs/addressparser/index.d.ts +16 -2
  66. package/node_modules/nodemailer/dist/cjs/addressparser/index.js +147 -28
  67. package/node_modules/nodemailer/dist/cjs/base64/index.js +2 -1
  68. package/node_modules/nodemailer/dist/cjs/dkim/index.d.ts +13 -1
  69. package/node_modules/nodemailer/dist/cjs/dkim/index.js +25 -8
  70. package/node_modules/nodemailer/dist/cjs/dkim/message-parser.d.ts +10 -1
  71. package/node_modules/nodemailer/dist/cjs/dkim/message-parser.js +28 -4
  72. package/node_modules/nodemailer/dist/cjs/dkim/relaxed-body.d.ts +10 -1
  73. package/node_modules/nodemailer/dist/cjs/dkim/sign.d.ts +3 -0
  74. package/node_modules/nodemailer/dist/cjs/dkim/sign.js +18 -1
  75. package/node_modules/nodemailer/dist/cjs/errors.d.ts +3 -2
  76. package/node_modules/nodemailer/dist/cjs/fetch/cookies.d.ts +12 -1
  77. package/node_modules/nodemailer/dist/cjs/fetch/index.d.ts +15 -1
  78. package/node_modules/nodemailer/dist/cjs/fetch/index.js +39 -64
  79. package/node_modules/nodemailer/dist/cjs/json-transport/index.d.ts +14 -4
  80. package/node_modules/nodemailer/dist/cjs/json-transport/index.js +2 -0
  81. package/node_modules/nodemailer/dist/cjs/mail-composer/index.d.ts +8 -3
  82. package/node_modules/nodemailer/dist/cjs/mailer/index.d.ts +43 -25
  83. package/node_modules/nodemailer/dist/cjs/mailer/mail-message.d.ts +11 -4
  84. package/node_modules/nodemailer/dist/cjs/mime-funcs/index.d.ts +7 -3
  85. package/node_modules/nodemailer/dist/cjs/mime-funcs/index.js +198 -84
  86. package/node_modules/nodemailer/dist/cjs/mime-node/index.d.ts +5 -2
  87. package/node_modules/nodemailer/dist/cjs/mime-node/index.js +2 -1
  88. package/node_modules/nodemailer/dist/cjs/nodemailer.d.ts +38 -16
  89. package/node_modules/nodemailer/dist/cjs/nodemailer.js +1 -0
  90. package/node_modules/nodemailer/dist/cjs/package-info.d.ts +1 -1
  91. package/node_modules/nodemailer/dist/cjs/package-info.js +1 -1
  92. package/node_modules/nodemailer/dist/cjs/punycode/index.js +1 -0
  93. package/node_modules/nodemailer/dist/cjs/qp/index.d.ts +2 -0
  94. package/node_modules/nodemailer/dist/cjs/qp/index.js +10 -1
  95. package/node_modules/nodemailer/dist/cjs/sendmail-transport/index.d.ts +2 -0
  96. package/node_modules/nodemailer/dist/cjs/ses-transport/index.d.ts +39 -2
  97. package/node_modules/nodemailer/dist/cjs/shared/index.d.ts +43 -7
  98. package/node_modules/nodemailer/dist/cjs/shared/index.js +5 -2
  99. package/node_modules/nodemailer/dist/cjs/smtp-connection/data-stream.d.ts +2 -1
  100. package/node_modules/nodemailer/dist/cjs/smtp-connection/data-stream.js +32 -24
  101. package/node_modules/nodemailer/dist/cjs/smtp-connection/http-proxy-client.d.ts +13 -5
  102. package/node_modules/nodemailer/dist/cjs/smtp-connection/http-proxy-client.js +23 -11
  103. package/node_modules/nodemailer/dist/cjs/smtp-connection/index.d.ts +59 -24
  104. package/node_modules/nodemailer/dist/cjs/smtp-connection/index.js +156 -75
  105. package/node_modules/nodemailer/dist/cjs/smtp-pool/index.d.ts +12 -4
  106. package/node_modules/nodemailer/dist/cjs/smtp-pool/index.js +39 -11
  107. package/node_modules/nodemailer/dist/cjs/smtp-pool/pool-resource.js +27 -31
  108. package/node_modules/nodemailer/dist/cjs/smtp-transport/index.d.ts +19 -6
  109. package/node_modules/nodemailer/dist/cjs/smtp-transport/index.js +25 -33
  110. package/node_modules/nodemailer/dist/cjs/stream-transport/index.d.ts +2 -0
  111. package/node_modules/nodemailer/dist/cjs/well-known/services.js +6 -0
  112. package/node_modules/nodemailer/dist/cjs/xoauth2/index.d.ts +13 -3
  113. package/node_modules/nodemailer/dist/cjs/xoauth2/index.js +25 -13
  114. package/node_modules/nodemailer/dist/esm/addressparser/index.d.ts +16 -2
  115. package/node_modules/nodemailer/dist/esm/addressparser/index.js +147 -27
  116. package/node_modules/nodemailer/dist/esm/base64/index.js +2 -1
  117. package/node_modules/nodemailer/dist/esm/dkim/index.d.ts +13 -1
  118. package/node_modules/nodemailer/dist/esm/dkim/index.js +25 -8
  119. package/node_modules/nodemailer/dist/esm/dkim/message-parser.d.ts +10 -1
  120. package/node_modules/nodemailer/dist/esm/dkim/message-parser.js +30 -5
  121. package/node_modules/nodemailer/dist/esm/dkim/relaxed-body.d.ts +10 -1
  122. package/node_modules/nodemailer/dist/esm/dkim/relaxed-body.js +2 -1
  123. package/node_modules/nodemailer/dist/esm/dkim/sign.d.ts +3 -0
  124. package/node_modules/nodemailer/dist/esm/dkim/sign.js +18 -1
  125. package/node_modules/nodemailer/dist/esm/errors.d.ts +3 -2
  126. package/node_modules/nodemailer/dist/esm/fetch/cookies.d.ts +12 -1
  127. package/node_modules/nodemailer/dist/esm/fetch/cookies.js +2 -1
  128. package/node_modules/nodemailer/dist/esm/fetch/index.d.ts +15 -1
  129. package/node_modules/nodemailer/dist/esm/fetch/index.js +39 -64
  130. package/node_modules/nodemailer/dist/esm/json-transport/index.d.ts +14 -4
  131. package/node_modules/nodemailer/dist/esm/json-transport/index.js +2 -0
  132. package/node_modules/nodemailer/dist/esm/mail-composer/index.d.ts +8 -3
  133. package/node_modules/nodemailer/dist/esm/mailer/index.d.ts +43 -25
  134. package/node_modules/nodemailer/dist/esm/mailer/mail-message.d.ts +11 -4
  135. package/node_modules/nodemailer/dist/esm/mime-funcs/index.d.ts +7 -3
  136. package/node_modules/nodemailer/dist/esm/mime-funcs/index.js +198 -84
  137. package/node_modules/nodemailer/dist/esm/mime-node/index.d.ts +5 -2
  138. package/node_modules/nodemailer/dist/esm/mime-node/index.js +2 -1
  139. package/node_modules/nodemailer/dist/esm/nodemailer.d.ts +38 -16
  140. package/node_modules/nodemailer/dist/esm/package-info.d.ts +1 -1
  141. package/node_modules/nodemailer/dist/esm/package-info.js +1 -1
  142. package/node_modules/nodemailer/dist/esm/punycode/index.js +1 -0
  143. package/node_modules/nodemailer/dist/esm/qp/index.d.ts +2 -0
  144. package/node_modules/nodemailer/dist/esm/qp/index.js +10 -1
  145. package/node_modules/nodemailer/dist/esm/sendmail-transport/index.d.ts +2 -0
  146. package/node_modules/nodemailer/dist/esm/ses-transport/index.d.ts +39 -2
  147. package/node_modules/nodemailer/dist/esm/shared/index.d.ts +43 -7
  148. package/node_modules/nodemailer/dist/esm/shared/index.js +5 -2
  149. package/node_modules/nodemailer/dist/esm/smtp-connection/data-stream.d.ts +2 -1
  150. package/node_modules/nodemailer/dist/esm/smtp-connection/data-stream.js +32 -24
  151. package/node_modules/nodemailer/dist/esm/smtp-connection/http-proxy-client.d.ts +13 -5
  152. package/node_modules/nodemailer/dist/esm/smtp-connection/http-proxy-client.js +23 -11
  153. package/node_modules/nodemailer/dist/esm/smtp-connection/index.d.ts +59 -24
  154. package/node_modules/nodemailer/dist/esm/smtp-connection/index.js +156 -75
  155. package/node_modules/nodemailer/dist/esm/smtp-pool/index.d.ts +12 -4
  156. package/node_modules/nodemailer/dist/esm/smtp-pool/index.js +39 -11
  157. package/node_modules/nodemailer/dist/esm/smtp-pool/pool-resource.js +27 -31
  158. package/node_modules/nodemailer/dist/esm/smtp-transport/index.d.ts +19 -6
  159. package/node_modules/nodemailer/dist/esm/smtp-transport/index.js +25 -33
  160. package/node_modules/nodemailer/dist/esm/stream-transport/index.d.ts +2 -0
  161. package/node_modules/nodemailer/dist/esm/well-known/services.js +6 -0
  162. package/node_modules/nodemailer/dist/esm/xoauth2/index.d.ts +13 -3
  163. package/node_modules/nodemailer/dist/esm/xoauth2/index.js +25 -13
  164. package/node_modules/nodemailer/dist/well-known/services.json +7 -0
  165. package/node_modules/nodemailer/package.json +16 -12
  166. package/package.json +16 -16
@@ -25,7 +25,8 @@ function encode(buffer) {
25
25
  */
26
26
  function wrap(str, lineLength) {
27
27
  str = (str || '').toString();
28
- lineLength = lineLength || 76;
28
+ // a negative length would step backwards through the input and never finish
29
+ lineLength = Math.max(Number(lineLength) || 76, 1);
29
30
  if (str.length <= lineLength) {
30
31
  return str;
31
32
  }
@@ -30,11 +30,23 @@ declare class DKIM {
30
30
  constructor(options: DKIMOptions);
31
31
  sign(input: Readable | Buffer | string, extraOptions?: DKIMOptions): DKIMSignedStream;
32
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
+ };
33
41
  /**
34
42
  * Type aliases in the layout of @types/nodemailer, so `DKIM.Options` style references keep working
35
43
  */
36
44
  declare namespace DKIM {
37
45
  type Options = DKIMOptions;
38
- type SingleKeyOptions = Omit<DKIMOptions, 'keys'>;
46
+ type OptionalOptions = DKIMOptionalOptions;
47
+ type SingleKeyOptions = DKIMSingleKeyOptions;
48
+ type MultipleKeysOptions = DKIMMultipleKeysOptions;
39
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 };
40
52
  export default DKIM;
@@ -90,13 +90,22 @@ class DKIMSigner {
90
90
  return;
91
91
  }
92
92
  const key = this.keys[keyPos++];
93
- const dkimField = (0, sign_js_1.default)(this.headers, this.hashAlgo, this.bodyHash, {
94
- domainName: key.domainName,
95
- keySelector: key.keySelector,
96
- privateKey: key.privateKey,
97
- headerFieldNames: this.options.headerFieldNames,
98
- skipFields: this.options.skipFields
99
- });
93
+ let dkimField;
94
+ try {
95
+ dkimField = (0, sign_js_1.default)(this.headers, this.hashAlgo, this.bodyHash, {
96
+ domainName: key.domainName,
97
+ keySelector: key.keySelector,
98
+ privateKey: key.privateKey,
99
+ headerFieldNames: this.options.headerFieldNames,
100
+ skipFields: this.options.skipFields
101
+ });
102
+ }
103
+ catch (err) {
104
+ this.hasErrored = true;
105
+ this.cleanup();
106
+ this.output.emit('error', err);
107
+ return;
108
+ }
100
109
  if (dkimField) {
101
110
  this.output.write(Buffer.from(dkimField + '\r\n'));
102
111
  }
@@ -196,7 +205,15 @@ class DKIM {
196
205
  }
197
206
  const signer = new DKIMSigner(options, this.keys, inputStream, output);
198
207
  setImmediate(() => {
199
- signer.signStream();
208
+ try {
209
+ signer.signStream();
210
+ }
211
+ catch (_E) {
212
+ // the body hash is created here, an unknown hashAlgo throws inside this timer
213
+ // where nothing else could catch it
214
+ output.emit('error', sign_js_1.default.unsupportedHashAlgoError(signer.hashAlgo));
215
+ return;
216
+ }
200
217
  if (writeValue) {
201
218
  setImmediate(() => {
202
219
  inputStream.end(writeValue);
@@ -13,7 +13,7 @@ export interface MessageParserHeaderLine {
13
13
  * from the rest of the body. Headers are emitted with the 'headers' event. Message
14
14
  * body is passed on as the resulting stream.
15
15
  */
16
- export default class MessageParser extends Transform {
16
+ declare class MessageParser extends Transform {
17
17
  lastBytes: Buffer;
18
18
  headersParsed: boolean;
19
19
  headerBytes: number;
@@ -37,3 +37,12 @@ export default class MessageParser extends Transform {
37
37
  checkHeaders(data: Buffer): boolean;
38
38
  parseHeaders(): MessageParserHeaderLine[];
39
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;
@@ -1,6 +1,33 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const node_stream_1 = require("node:stream");
4
+ /**
5
+ * Drops the SP and HTAB from both ends of a field name.
6
+ *
7
+ * An index scan rather than `/^[ \t]+|[ \t]+$/g`, which retries the trailing branch at
8
+ * every offset of a blank run that is followed by other text: the run is consumed greedily,
9
+ * `$` fails, and the engine gives the characters back one at a time before moving on to
10
+ * start the same walk one offset further in. A field name carrying a 128 KiB run of spaces
11
+ * between two atoms took about 6.7 seconds to trim, and the cost grows with its square.
12
+ *
13
+ * Not `.trim()`, which takes the other Unicode spaces along: an NBSP in front of a field
14
+ * name would come off and select the name into the signed set, where the relaxed
15
+ * canonicalization in sign.ts deliberately leaves everything but SP and HTAB alone.
16
+ *
17
+ * @param str Field name to trim
18
+ * @return The field name without the surrounding SP and HTAB
19
+ */
20
+ function _trimFieldName(str) {
21
+ let start = 0;
22
+ let end = str.length;
23
+ while (start < end && (str.charCodeAt(start) === 0x20 || str.charCodeAt(start) === 0x09)) {
24
+ start++;
25
+ }
26
+ while (end > start && (str.charCodeAt(end - 1) === 0x20 || str.charCodeAt(end - 1) === 0x09)) {
27
+ end--;
28
+ }
29
+ return str.slice(start, end);
30
+ }
4
31
  /**
5
32
  * MessageParser instance is a transform stream that separates message headers
6
33
  * from the rest of the body. Headers are emitted with the 'headers' event. Message
@@ -143,10 +170,7 @@ class MessageParser extends node_stream_1.Transform {
143
170
  return lines
144
171
  .filter(line => /[^ \t\r]/.test(line))
145
172
  .map(line => ({
146
- key: line
147
- .substr(0, line.indexOf(':'))
148
- .replace(/^[ \t]+|[ \t]+$/g, '')
149
- .toLowerCase(),
173
+ key: _trimFieldName(line.substr(0, line.indexOf(':'))).toLowerCase(),
150
174
  line
151
175
  }));
152
176
  }
@@ -17,7 +17,7 @@ export interface RelaxedBodyOptions {
17
17
  * a non-empty body always ends with CRLF. Bytes are canonicalized as they arrive,
18
18
  * so a line of any length costs constant memory.
19
19
  */
20
- export default class RelaxedBody extends Transform {
20
+ declare class RelaxedBody extends Transform {
21
21
  bodyHash: crypto.Hash;
22
22
  /** Bytes of the original body seen so far */
23
23
  byteLength: number;
@@ -25,3 +25,12 @@ export default class RelaxedBody extends Transform {
25
25
  constructor(options?: RelaxedBodyOptions);
26
26
  updateHash(chunk: Buffer, final?: boolean): void;
27
27
  }
28
+ /**
29
+ * Type aliases in the layout of @types/nodemailer, so `RelaxedBody.Options` style references keep working
30
+ */
31
+ declare namespace RelaxedBody {
32
+ type Options = RelaxedBodyOptions;
33
+ }
34
+ /** The same alias as a module level export, for `import * as RelaxedBody` and `import RelaxedBody = require()` */
35
+ export type { RelaxedBodyOptions as Options };
36
+ export default RelaxedBody;
@@ -1,4 +1,5 @@
1
1
  import crypto from 'node:crypto';
2
+ import type { NodemailerError } from '../errors.js';
2
3
  import type { MessageParserHeaderLine } from './message-parser.js';
3
4
  /**
4
5
  * Private key accepted by crypto.Sign#sign: a PEM string, a Buffer, a KeyObject or an
@@ -35,6 +36,7 @@ export interface DKIMRelaxedHeaders {
35
36
  * Returns DKIM signature header line
36
37
  *
37
38
  * @param headers Parsed headers object from MessageParser
39
+ * @param hashAlgo Hash algorithm the body hash was calculated with, for example "sha256"
38
40
  * @param bodyHash Base64 encoded hash of the message
39
41
  * @param options DKIM options
40
42
  * @param options.domainName Domain name to be signed for
@@ -45,5 +47,6 @@ export interface DKIMRelaxedHeaders {
45
47
  declare function sign(headers: MessageParserHeaderLine[], hashAlgo: string, bodyHash: string, options?: DKIMSignOptions): string | false;
46
48
  declare namespace sign {
47
49
  var relaxedHeaders: (headers: MessageParserHeaderLine[], fieldNames?: string, skipFields?: string) => DKIMRelaxedHeaders;
50
+ var unsupportedHashAlgoError: (hashAlgo: string) => NodemailerError;
48
51
  }
49
52
  export default sign;
@@ -39,10 +39,20 @@ Object.defineProperty(exports, "__esModule", { value: true });
39
39
  const punycode = __importStar(require("../punycode/index.js"));
40
40
  const mimeFuncs = __importStar(require("../mime-funcs/index.js"));
41
41
  const node_crypto_1 = __importDefault(require("node:crypto"));
42
+ const errors = __importStar(require("../errors.js"));
43
+ /**
44
+ * Error for a hashAlgo value the crypto module does not know
45
+ */
46
+ function unsupportedHashAlgoError(hashAlgo) {
47
+ const err = new Error('Unsupported DKIM hash algorithm "' + hashAlgo + '"');
48
+ err.code = errors.ECONFIG;
49
+ return err;
50
+ }
42
51
  /**
43
52
  * Returns DKIM signature header line
44
53
  *
45
54
  * @param headers Parsed headers object from MessageParser
55
+ * @param hashAlgo Hash algorithm the body hash was calculated with, for example "sha256"
46
56
  * @param bodyHash Base64 encoded hash of the message
47
57
  * @param options DKIM options
48
58
  * @param options.domainName Domain name to be signed for
@@ -63,7 +73,13 @@ function sign(headers, hashAlgo, bodyHash, options) {
63
73
  const canonicalizedHeaderData = relaxedHeaders(headers, fieldNames, options.skipFields);
64
74
  const dkimHeader = generateDKIMHeader(options.domainName, options.keySelector, canonicalizedHeaderData.fieldNames, hashAlgo, bodyHash);
65
75
  canonicalizedHeaderData.headers += 'dkim-signature:' + relaxedHeaderLine(dkimHeader);
66
- const signer = node_crypto_1.default.createSign(('rsa-' + hashAlgo).toUpperCase());
76
+ let signer;
77
+ try {
78
+ signer = node_crypto_1.default.createSign(('rsa-' + hashAlgo).toUpperCase());
79
+ }
80
+ catch (_E) {
81
+ throw unsupportedHashAlgoError(hashAlgo);
82
+ }
67
83
  // the header lines are 'binary' strings, so this reproduces the original header bytes
68
84
  signer.update(canonicalizedHeaderData.headers, 'latin1');
69
85
  let signature;
@@ -76,6 +92,7 @@ function sign(headers, hashAlgo, bodyHash, options) {
76
92
  return dkimHeader + signature.replace(/(^.{73}|.{75}(?!\r?\n|\r))/g, '$&\r\n ').trim();
77
93
  }
78
94
  sign.relaxedHeaders = relaxedHeaders;
95
+ sign.unsupportedHashAlgoError = unsupportedHashAlgoError;
79
96
  exports.default = sign;
80
97
  function generateDKIMHeader(domainName, keySelector, fieldNames, hashAlgo, bodyHash) {
81
98
  // the caller supplied tag values are interpolated straight into the tag list, and none of
@@ -64,9 +64,10 @@ export declare const EFETCH = "EFETCH";
64
64
  /**
65
65
  * An Error together with the properties Nodemailer attaches to the errors it
66
66
  * hands to callers. Every property is optional, the set that is present
67
- * depends on where the error originated.
67
+ * depends on where the error originated. Socket level errors keep the errno
68
+ * and syscall fields Node.js sets on them.
68
69
  */
69
- export interface NodemailerError extends Error {
70
+ export interface NodemailerError extends NodeJS.ErrnoException {
70
71
  /** Nodemailer error code, see ERROR_CODES */
71
72
  code?: string | undefined;
72
73
  /** SMTP command that was in flight when the server replied with an error */
@@ -17,13 +17,14 @@ export interface Cookie {
17
17
  secure?: boolean | undefined;
18
18
  httponly?: boolean | undefined;
19
19
  }
20
+ type CookieEntry = Cookie;
20
21
  /**
21
22
  * Creates a biskviit cookie jar for managing cookie values in memory
22
23
  *
23
24
  * @constructor
24
25
  * @param [options] Optional options object
25
26
  */
26
- export default class Cookies {
27
+ declare class Cookies {
27
28
  options: CookiesOptions;
28
29
  cookies: Cookie[];
29
30
  constructor(options?: CookiesOptions);
@@ -94,3 +95,13 @@ export default class Cookies {
94
95
  */
95
96
  getPath(pathname?: string | null): string;
96
97
  }
98
+ /**
99
+ * Type aliases in the layout of @types/nodemailer, so `Cookies.Cookie` style references keep working
100
+ */
101
+ declare namespace Cookies {
102
+ type Options = CookiesOptions;
103
+ type Cookie = CookieEntry;
104
+ }
105
+ /** The same alias as a module level export, for `import * as Cookies` and `import Cookies = require()` */
106
+ export type { CookiesOptions as Options };
107
+ export default Cookies;
@@ -25,8 +25,10 @@ export interface FetchOptions {
25
25
  tls?: {
26
26
  [key: string]: any;
27
27
  } | undefined;
28
- /** Request timeout in milliseconds */
28
+ /** Socket inactivity timeout in milliseconds, defaults to 60000, 0 disables it */
29
29
  timeout?: number | undefined;
30
+ /** Maximum size of the (decoded) response body in bytes, defaults to 64 MB, Infinity disables the limit */
31
+ maxBytes?: number | undefined;
30
32
  /** Maximum number of redirects to follow (default 5) */
31
33
  maxRedirects?: number | undefined;
32
34
  /** Resolve responses with a status code of 300 or above instead of emitting an error */
@@ -47,5 +49,17 @@ export interface FetchResponse extends PassThrough {
47
49
  declare function nmfetch(url: string, options?: FetchOptions): FetchResponse;
48
50
  declare namespace nmfetch {
49
51
  var Cookies: typeof import("./cookies.js").default;
52
+ var DEFAULT_TIMEOUT: number;
50
53
  }
54
+ type CookiesJar = Cookies;
55
+ /**
56
+ * Type aliases in the layout of @types/nodemailer, so `fetch.Options` style references keep working
57
+ */
58
+ declare namespace nmfetch {
59
+ type Options = FetchOptions;
60
+ type WritableResponse = FetchResponse;
61
+ type Cookies = CookiesJar;
62
+ }
63
+ /** The same aliases as module level exports, for `import * as fetch` and `import fetch = require()` */
64
+ export type { FetchOptions as Options, FetchResponse as WritableResponse, Cookies };
51
65
  export default nmfetch;
@@ -47,6 +47,10 @@ const node_net_1 = __importDefault(require("node:net"));
47
47
  const errors = __importStar(require("../errors.js"));
48
48
  const objects_js_1 = require("../shared/objects.js");
49
49
  const MAX_REDIRECTS = 5;
50
+ // a stalled server would otherwise hold the request, and whatever waits on it, open forever
51
+ const DEFAULT_TIMEOUT = 60 * 1000;
52
+ // the body is usually buffered in memory by the caller, so an unbounded download is refused
53
+ const DEFAULT_MAX_BYTES = 64 * 1024 * 1024;
50
54
  // Only genuine TLS settings are taken from options.tls. That object reaches us straight
51
55
  // from a user supplied attachment (content.tls), so keys like host, port, path, socketPath
52
56
  // or lookup would otherwise repoint the request at a destination that never went through
@@ -193,14 +197,14 @@ function nmfetch(url, options) {
193
197
  .join('&'));
194
198
  }
195
199
  catch (E) {
196
- if (finished) {
197
- return undefined;
198
- }
200
+ // the caller attaches its error listener once nmfetch has returned, so
201
+ // the error is emitted on the next tick and the stream is handed back
202
+ // the way every other failure is reported
199
203
  finished = true;
200
204
  E.code = errors.EFETCH;
201
205
  E.sourceUrl = url;
202
- fetchRes.emit('error', E);
203
- return undefined;
206
+ setImmediate(() => fetchRes.emit('error', E));
207
+ return fetchRes;
204
208
  }
205
209
  }
206
210
  else {
@@ -252,28 +256,22 @@ function nmfetch(url, options) {
252
256
  });
253
257
  return fetchRes;
254
258
  }
255
- if (options.timeout) {
256
- req.setTimeout(options.timeout, () => {
257
- if (finished) {
258
- return;
259
- }
260
- finished = true;
261
- req.abort();
262
- const err = new Error('Request Timeout');
263
- err.code = errors.EFETCH;
264
- err.sourceUrl = url;
265
- fetchRes.emit('error', err);
266
- });
267
- }
268
- req.on('error', (err) => {
259
+ // reports the first failure of this request on fetchRes and releases the request
260
+ const fail = (err, sourceUrl = url) => {
269
261
  if (finished) {
270
262
  return;
271
263
  }
272
264
  finished = true;
273
265
  err.code = errors.EFETCH;
274
- err.sourceUrl = url;
266
+ err.sourceUrl = sourceUrl;
275
267
  fetchRes.emit('error', err);
276
- });
268
+ req.abort();
269
+ };
270
+ const timeout = typeof options.timeout === 'number' && options.timeout >= 0 ? options.timeout : DEFAULT_TIMEOUT;
271
+ if (timeout) {
272
+ req.setTimeout(timeout, () => fail(new Error('Request Timeout')));
273
+ }
274
+ req.on('error', (err) => fail(err));
277
275
  req.on('response', res => {
278
276
  let inflate;
279
277
  if (finished) {
@@ -294,13 +292,7 @@ function nmfetch(url, options) {
294
292
  // redirect
295
293
  options.redirects++;
296
294
  if (options.redirects > options.maxRedirects) {
297
- finished = true;
298
- const err = new Error('Maximum redirect count exceeded');
299
- err.code = errors.EFETCH;
300
- err.sourceUrl = url;
301
- fetchRes.emit('error', err);
302
- req.abort();
303
- return;
295
+ return fail(new Error('Maximum redirect count exceeded'));
304
296
  }
305
297
  // redirect does not include POST body
306
298
  options.method = 'GET';
@@ -320,13 +312,7 @@ function nmfetch(url, options) {
320
312
  // call: that call gets its own `finished` flag and no handle on this
321
313
  // request, so this one would stay open and could emit a second error on
322
314
  // the shared fetchRes once it times out. Callers listen with req.once().
323
- finished = true;
324
- const err = new Error('Unsupported protocol for URL ' + redirectUrl);
325
- err.code = errors.EFETCH;
326
- err.sourceUrl = redirectUrl;
327
- fetchRes.emit('error', err);
328
- req.abort();
329
- return;
315
+ return fail(new Error('Unsupported protocol for URL ' + redirectUrl), redirectUrl);
330
316
  }
331
317
  // Do not forward credentials when the redirect leaves the original
332
318
  // security context: a different host, or a downgrade from https to
@@ -343,41 +329,33 @@ function nmfetch(url, options) {
343
329
  }
344
330
  });
345
331
  }
332
+ // this request is done with, release it so its socket and timeout do not
333
+ // outlive it and report a late error on the shared fetchRes
334
+ finished = true;
335
+ res.resume();
336
+ req.abort();
346
337
  return nmfetch(redirectUrl, options);
347
338
  }
348
339
  fetchRes.statusCode = res.statusCode;
349
340
  fetchRes.headers = res.headers;
350
341
  if (res.statusCode >= 300 && !options.allowErrorResponse) {
351
- finished = true;
352
- const err = new Error('Invalid status code ' + res.statusCode);
353
- err.code = errors.EFETCH;
354
- err.sourceUrl = url;
355
- fetchRes.emit('error', err);
356
- req.abort();
357
- return;
342
+ return fail(new Error('Invalid status code ' + res.statusCode));
358
343
  }
359
- res.on('error', (err) => {
360
- if (finished) {
344
+ res.on('error', (err) => fail(err));
345
+ const maxBytes = typeof options.maxBytes === 'number' && options.maxBytes > 0 ? options.maxBytes : DEFAULT_MAX_BYTES;
346
+ const source = inflate || res;
347
+ let received = 0;
348
+ source.on('data', (chunk) => {
349
+ received += chunk.length;
350
+ if (received <= maxBytes || finished) {
361
351
  return;
362
352
  }
363
- finished = true;
364
- err.code = errors.EFETCH;
365
- err.sourceUrl = url;
366
- fetchRes.emit('error', err);
367
- req.abort();
353
+ source.unpipe(fetchRes);
354
+ fail(new Error('Response size exceeds the allowed ' + maxBytes + ' bytes'));
368
355
  });
369
356
  if (inflate) {
370
357
  res.pipe(inflate).pipe(fetchRes);
371
- inflate.on('error', (err) => {
372
- if (finished) {
373
- return;
374
- }
375
- finished = true;
376
- err.code = errors.EFETCH;
377
- err.sourceUrl = url;
378
- fetchRes.emit('error', err);
379
- req.abort();
380
- });
358
+ inflate.on('error', (err) => fail(err));
381
359
  }
382
360
  else {
383
361
  res.pipe(fetchRes);
@@ -392,11 +370,7 @@ function nmfetch(url, options) {
392
370
  req.write(body);
393
371
  }
394
372
  catch (err) {
395
- finished = true;
396
- err.code = errors.EFETCH;
397
- err.sourceUrl = url;
398
- fetchRes.emit('error', err);
399
- return;
373
+ return fail(err);
400
374
  }
401
375
  }
402
376
  req.end();
@@ -404,6 +378,7 @@ function nmfetch(url, options) {
404
378
  return fetchRes;
405
379
  }
406
380
  nmfetch.Cookies = cookies_js_1.default;
381
+ nmfetch.DEFAULT_TIMEOUT = DEFAULT_TIMEOUT;
407
382
  exports.default = nmfetch;
408
383
  module.exports = exports.default;
409
384
  Object.defineProperty(module.exports, 'default', { value: exports.default, enumerable: false, writable: true, configurable: true });
@@ -1,6 +1,6 @@
1
1
  import type { Logger } from '../shared/index.js';
2
2
  import type { MimeNodeEnvelope } from '../mime-node/index.js';
3
- import type { default as MailMessage, MailMessageData } from '../mailer/mail-message.js';
3
+ import type MailMessage from '../mailer/mail-message.js';
4
4
  import type { default as Mail, SentMessageInfo, SendMailOptions, TransportOptions } from '../mailer/index.js';
5
5
  /**
6
6
  * Options for the JSON transport
@@ -12,16 +12,23 @@ export interface JSONTransportOptions extends TransportOptions {
12
12
  skipEncoding?: boolean | undefined;
13
13
  }
14
14
  /**
15
- * The value the JSON transport hands to the send callback
15
+ * The value the JSON transport hands to the send callback. M is the type of the message
16
+ * field: a JSON string by default, the message object itself when skipEncoding is set
16
17
  */
17
- export interface JSONSentMessageInfo extends SentMessageInfo {
18
+ export interface JSONSentMessageInfo<M = string> extends SentMessageInfo {
18
19
  /** The envelope the message was generated with */
19
20
  envelope: MimeNodeEnvelope;
20
21
  /** Message-ID value of the message */
21
22
  messageId: string;
22
23
  /** The normalized message as a JSON string, or as the object itself when skipEncoding is set */
23
- message: string | MailMessageData;
24
+ message: M;
24
25
  }
26
+ /**
27
+ * The value the JSON transport hands to the send callback when skipEncoding is set: the
28
+ * message field holds the message object. Typed loosely so that a transporter created with
29
+ * skipEncoding still fits a variable declared with the plain result type
30
+ */
31
+ export type JSONSentMessageObjectInfo = JSONSentMessageInfo<any>;
25
32
  /**
26
33
  * Generates a Transport object to generate JSON output
27
34
  *
@@ -50,5 +57,8 @@ declare namespace JSONTransport {
50
57
  type Options = JSONTransportOptions;
51
58
  type MailOptions = SendMailOptions;
52
59
  type SentMessageInfo = JSONSentMessageInfo;
60
+ type SentMessageObjectInfo = JSONSentMessageObjectInfo;
53
61
  }
62
+ /** The same aliases as module level exports, for `import * as JSONTransport` and `import JSONTransport = require()` */
63
+ export type { JSONTransportOptions as Options, SendMailOptions as MailOptions, JSONSentMessageInfo as SentMessageInfo, JSONSentMessageObjectInfo as SentMessageObjectInfo };
54
64
  export default JSONTransport;
@@ -83,6 +83,8 @@ class JSONTransport {
83
83
  }
84
84
  delete data.envelope;
85
85
  delete data.normalizedHeaders;
86
+ // the message field is the object itself with skipEncoding, the
87
+ // createTransport overload for that option types the result accordingly
86
88
  return done(null, {
87
89
  envelope,
88
90
  messageId,
@@ -72,6 +72,11 @@ export type MailComposerListHeaderEntry = string | {
72
72
  export interface MailComposerListHeaders {
73
73
  [key: string]: MailComposerListHeaderEntry | (MailComposerListHeaderEntry | MailComposerListHeaderEntry[])[];
74
74
  }
75
+ /**
76
+ * Encoding for the non-ascii header values: quoted-printable ('Q', the default) or base64
77
+ * ('B'). Only the first letter is read, so the short forms work as well
78
+ */
79
+ export type MailComposerTextEncoding = 'quoted-printable' | 'base64' | 'Q' | 'B';
75
80
  /**
76
81
  * Mail options, the message data MailComposer builds the MIME tree from. The address
77
82
  * fields, subject, messageId, date, inReplyTo and references become headers of the root
@@ -114,7 +119,7 @@ export interface MailComposerOptions {
114
119
  /** Content-Transfer-Encoding to force for the text/* nodes that do not set their own */
115
120
  encoding?: string | undefined;
116
121
  /** Header string encoding, 'Q' (the default) or 'B', 'quoted-printable' and 'base64' are accepted as well */
117
- textEncoding?: string | undefined;
122
+ textEncoding?: MailComposerTextEncoding | undefined;
118
123
  /** Pregenerated rfc822 message, used as is instead of building one */
119
124
  raw?: MimeNodeContent | undefined;
120
125
  /** Reject content that points to a URL */
@@ -129,8 +134,6 @@ export interface MailComposerOptions {
129
134
  baseBoundary?: string | undefined;
130
135
  /** 'win' for CRLF and 'linux' for LF line breaks in the generated message, kept as is when not set */
131
136
  newline?: string | undefined;
132
- /** Keep the Bcc header in the generated message, listed for completeness, the transports set it on the message directly */
133
- keepBcc?: boolean | undefined;
134
137
  /** Method to normalize header keys for custom caseing */
135
138
  normalizeHeaderKey?: MimeNodeOptions['normalizeHeaderKey'] | undefined;
136
139
  /** 'high', 'normal' or 'low', sets the priority headers, read by the mailer */
@@ -166,4 +169,6 @@ declare class MailComposer {
166
169
  declare namespace MailComposer {
167
170
  type Options = MailComposerOptions;
168
171
  }
172
+ /** The same alias as a module level export, for `import * as MailComposer` and `import MailComposer = require()` */
173
+ export type { MailComposerOptions as Options };
169
174
  export default MailComposer;