@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
@@ -1,42 +1,31 @@
1
- 'use strict';
2
-
3
- const shared = require('../shared');
4
- const MimeNode = require('../mime-node');
5
- const mimeFuncs = require('../mime-funcs');
6
-
1
+ import * as shared from '../shared/index.js';
2
+ import MimeNode from '../mime-node/index.js';
3
+ import * as mimeFuncs from '../mime-funcs/index.js';
7
4
  // Only an own key counts as already set. `key in obj` also matches every member of
8
5
  // Object.prototype, which silently drops a transporter default legitimately named
9
6
  // toString or constructor.
10
7
  const hasOwn = (obj, key) => Object.prototype.hasOwnProperty.call(obj, key);
11
-
12
- class MailMessage {
8
+ export default class MailMessage {
13
9
  constructor(mailer, data) {
14
10
  this.mailer = mailer;
15
11
  this.data = {};
16
12
  this.message = null;
17
-
18
13
  data = data || {};
19
14
  const options = mailer.options || {};
20
15
  const defaults = mailer._defaults || {};
21
-
22
16
  shared.copyOwnKeys(this.data, data);
23
-
24
17
  this.data.headers = this.data.headers || {};
25
-
26
18
  // Apply defaults. `_defaults` is caller supplied too, it is the second argument of
27
19
  // createTransport, so it needs the same treatment as `data` above
28
20
  shared.copyOwnKeys(this.data, defaults, key => hasOwn(this.data, key));
29
-
30
21
  // headers is a special case. Allow setting individual default headers
31
22
  shared.copyOwnKeys(this.data.headers, defaults.headers, key => hasOwn(this.data.headers, key));
32
-
33
23
  // force specific keys from transporter options
34
24
  ['disableFileAccess', 'disableUrlAccess', 'normalizeHeaderKey', 'maxRecipients'].forEach(key => {
35
25
  if (key in options) {
36
26
  this.data[key] = options[key];
37
27
  }
38
28
  });
39
-
40
29
  // The access flags are a sandbox rather than a message field, so `defaults` counts as
41
30
  // transporter configuration for them. For a transporter plugin it is the only channel
42
31
  // there is, createTransport leaves `options` undefined for one, and the defaults copy
@@ -49,7 +38,6 @@ class MailMessage {
49
38
  }
50
39
  });
51
40
  }
52
-
53
41
  resolveContent(data, key, options, callback) {
54
42
  // Most plugins call this with the legacy (data, key, callback) signature, which carries
55
43
  // no access policy. The policy belongs to the message, so apply it here. Explicit
@@ -59,15 +47,12 @@ class MailMessage {
59
47
  options = false;
60
48
  }
61
49
  options = options || {};
62
-
63
50
  const policy = {
64
51
  disableFileAccess: this.data.disableFileAccess || options.disableFileAccess,
65
52
  disableUrlAccess: this.data.disableUrlAccess || options.disableUrlAccess
66
53
  };
67
-
68
54
  return shared.resolveContent(data, key, policy, callback);
69
55
  }
70
-
71
56
  resolveAll(callback) {
72
57
  const keys = [
73
58
  [this.data, 'html'],
@@ -76,56 +61,51 @@ class MailMessage {
76
61
  [this.data, 'amp'],
77
62
  [this.data, 'icalEvent']
78
63
  ];
79
-
80
64
  if (this.data.alternatives && this.data.alternatives.length) {
81
65
  this.data.alternatives.forEach((alternative, i) => {
82
66
  keys.push([this.data.alternatives, i]);
83
67
  });
84
68
  }
85
-
86
69
  if (this.data.attachments && this.data.attachments.length) {
87
70
  this.data.attachments.forEach((attachment, i) => {
88
71
  if (!attachment.filename) {
72
+ // a backslash separates as well, so a Windows path does not put the sender's directories in the headers
89
73
  attachment.filename =
90
- (attachment.path || attachment.href || '').split('/').pop().split('?').shift() || 'attachment-' + (i + 1);
74
+ (attachment.path || attachment.href || '').split(/[/\\]/).pop().split('?').shift() ||
75
+ 'attachment-' + (i + 1);
91
76
  if (attachment.filename.indexOf('.') < 0) {
92
77
  attachment.filename += '.' + mimeFuncs.detectExtension(attachment.contentType);
93
78
  }
94
79
  }
95
-
96
80
  if (!attachment.contentType) {
97
81
  attachment.contentType = mimeFuncs.detectMimeType(attachment.filename || attachment.path || attachment.href || 'bin');
98
82
  }
99
-
100
83
  keys.push([this.data.attachments, i]);
101
84
  });
102
85
  }
103
-
104
86
  const mimeNode = new MimeNode();
105
-
106
87
  const addressKeys = ['from', 'to', 'cc', 'bcc', 'sender', 'replyTo'];
107
-
108
88
  addressKeys.forEach(address => {
109
89
  let value;
110
90
  if (this.message) {
111
91
  value = [].concat(mimeNode._parseAddresses(this.message.getHeader(address === 'replyTo' ? 'reply-to' : address)) || []);
112
- } else if (this.data[address]) {
92
+ }
93
+ else if (this.data[address]) {
113
94
  value = [].concat(mimeNode._parseAddresses(this.data[address]) || []);
114
95
  }
115
96
  if (value && value.length) {
116
97
  this.data[address] = value;
117
- } else if (address in this.data) {
98
+ }
99
+ else if (address in this.data) {
118
100
  this.data[address] = null;
119
101
  }
120
102
  });
121
-
122
103
  const singleKeys = ['from', 'sender'];
123
104
  singleKeys.forEach(address => {
124
105
  if (this.data[address]) {
125
106
  this.data[address] = this.data[address].shift();
126
107
  }
127
108
  });
128
-
129
109
  let pos = 0;
130
110
  const resolveNext = () => {
131
111
  if (pos >= keys.length) {
@@ -135,80 +115,66 @@ class MailMessage {
135
115
  if (!args[0] || !args[0][args[1]]) {
136
116
  return resolveNext();
137
117
  }
138
- shared.resolveContent(
139
- ...args,
140
- { disableFileAccess: this.data.disableFileAccess, disableUrlAccess: this.data.disableUrlAccess },
141
- (err, value) => {
142
- if (err) {
143
- return callback(err);
144
- }
145
-
146
- const node = {
147
- content: value
148
- };
149
- if (args[0][args[1]] && typeof args[0][args[1]] === 'object' && !Buffer.isBuffer(args[0][args[1]])) {
150
- // The keys are the caller's, so copying them takes the same "__proto__"
151
- // rule as the constructor. `key in node` stays as the already-set test
152
- // here, unlike for the defaults: it also skips the Object.prototype
153
- // member names, and letting message data land a `toString` string on a
154
- // node only buys a TypeError the first time something stringifies it.
155
- shared.copyOwnKeys(node, args[0][args[1]], key => key in node || ['content', 'path', 'href', 'raw'].includes(key));
156
- }
157
-
158
- args[0][args[1]] = node;
159
- resolveNext();
118
+ shared.resolveContent(...args, { disableFileAccess: this.data.disableFileAccess, disableUrlAccess: this.data.disableUrlAccess }, (err, value) => {
119
+ if (err) {
120
+ return callback(err);
121
+ }
122
+ const node = {
123
+ content: value
124
+ };
125
+ if (args[0][args[1]] && typeof args[0][args[1]] === 'object' && !Buffer.isBuffer(args[0][args[1]])) {
126
+ // The keys are the caller's, so copying them takes the same "__proto__"
127
+ // rule as the constructor. `key in node` stays as the already-set test
128
+ // here, unlike for the defaults: it also skips the Object.prototype
129
+ // member names, and letting message data land a `toString` string on a
130
+ // node only buys a TypeError the first time something stringifies it.
131
+ shared.copyOwnKeys(node, args[0][args[1]], key => key in node || ['content', 'path', 'href', 'raw'].includes(key));
160
132
  }
161
- );
133
+ args[0][args[1]] = node;
134
+ resolveNext();
135
+ });
162
136
  };
163
-
164
137
  setImmediate(() => resolveNext());
165
138
  }
166
-
167
139
  normalize(callback) {
168
140
  const envelope = this.message.getEnvelope();
169
141
  const messageId = this.message.messageId();
170
-
171
142
  this.resolveAll((err, data) => {
172
143
  if (err) {
173
144
  return callback(err);
174
145
  }
175
-
176
146
  data.envelope = envelope;
177
147
  data.messageId = messageId;
178
-
179
148
  ['html', 'text', 'watchHtml', 'amp'].forEach(key => {
180
149
  if (data[key] && data[key].content) {
181
150
  if (typeof data[key].content === 'string') {
182
151
  data[key] = data[key].content;
183
- } else if (Buffer.isBuffer(data[key].content)) {
152
+ }
153
+ else if (Buffer.isBuffer(data[key].content)) {
184
154
  data[key] = data[key].content.toString();
185
155
  }
186
156
  }
187
157
  });
188
-
189
158
  if (data.icalEvent && Buffer.isBuffer(data.icalEvent.content)) {
190
159
  data.icalEvent.content = data.icalEvent.content.toString('base64');
191
160
  data.icalEvent.encoding = 'base64';
192
161
  }
193
-
194
162
  if (data.alternatives && data.alternatives.length) {
195
- data.alternatives.forEach(alternative => {
163
+ data.alternatives.forEach((alternative) => {
196
164
  if (alternative && alternative.content && Buffer.isBuffer(alternative.content)) {
197
165
  alternative.content = alternative.content.toString('base64');
198
166
  alternative.encoding = 'base64';
199
167
  }
200
168
  });
201
169
  }
202
-
203
170
  if (data.attachments && data.attachments.length) {
204
- data.attachments.forEach(attachment => {
171
+ data.attachments.forEach((attachment) => {
205
172
  if (attachment && attachment.content && Buffer.isBuffer(attachment.content)) {
206
173
  attachment.content = attachment.content.toString('base64');
207
174
  attachment.encoding = 'base64';
208
175
  }
209
176
  });
210
177
  }
211
-
212
178
  data.normalizedHeaders = {};
213
179
  Object.keys(data.headers || {}).forEach(key => {
214
180
  if (shared.isProtoKey(key)) {
@@ -223,33 +189,27 @@ class MailMessage {
223
189
  data.normalizedHeaders[key] = value;
224
190
  }
225
191
  });
226
-
227
192
  if (data.list && typeof data.list === 'object') {
228
193
  const listHeaders = this._getListHeaders(data.list);
229
194
  listHeaders.forEach(entry => {
230
195
  data.normalizedHeaders[entry.key] = entry.value.map(val => (val && val.value) || val).join(', ');
231
196
  });
232
197
  }
233
-
234
198
  if (data.references) {
235
199
  data.normalizedHeaders.references = this.message._encodeHeaderValue('references', data.references);
236
200
  }
237
-
238
201
  if (data.inReplyTo) {
239
202
  data.normalizedHeaders['in-reply-to'] = this.message._encodeHeaderValue('in-reply-to', data.inReplyTo);
240
203
  }
241
-
242
204
  return callback(null, data);
243
205
  });
244
206
  }
245
-
246
207
  setMailerHeader() {
247
208
  if (!this.message || !this.data.xMailer) {
248
209
  return;
249
210
  }
250
211
  this.message.setHeader('X-Mailer', this.data.xMailer);
251
212
  }
252
-
253
213
  setPriorityHeaders() {
254
214
  if (!this.message || !this.data.priority) {
255
215
  return;
@@ -269,7 +229,6 @@ class MailMessage {
269
229
  // do not add anything, since all messages are 'Normal' by default
270
230
  }
271
231
  }
272
-
273
232
  setListHeaders() {
274
233
  if (!this.message || !this.data.list || typeof this.data.list !== 'object') {
275
234
  return;
@@ -281,7 +240,7 @@ class MailMessage {
281
240
  });
282
241
  });
283
242
  }
284
-
243
+ /** @internal */
285
244
  _getListHeaders(listData) {
286
245
  // make sure an url looks like <protocol:url>
287
246
  return Object.keys(listData).map(key => ({
@@ -292,49 +251,41 @@ class MailMessage {
292
251
  value: []
293
252
  .concat(value || [])
294
253
  .map(value => {
295
- if (typeof value === 'string') {
296
- value = {
297
- url: value
298
- };
299
- }
300
-
301
- if (value && value.url) {
302
- // strip CR/LF so a comment can't inject extra header lines. DEL is neither
303
- // qtext nor ctext, so it can not be carried literally by either construct
304
- // and has to become an encoded word like any other non-plaintext value
305
- let comment = (value.comment || '').toString().replace(/\r?\n|\r/g, ' ');
306
- const needsEncoding = !mimeFuncs.isPlainText(comment) || /\x7f/.test(comment);
307
-
308
- if (key.toLowerCase().trim() === 'id') {
309
- // List-ID: "comment" <domain>, where an unescaped quote or a trailing
310
- // backslash in the comment would swallow the <domain> behind it
311
- comment = needsEncoding ? mimeFuncs.encodeWord(comment) : mimeFuncs.quoteString(comment);
312
-
313
- // List-ID expects a bare domain-like identifier, so strip the
314
- // scheme prefix that _formatListUrl adds or passes through
315
- return (
316
- (value.comment ? comment + ' ' : '') + this._formatListUrl(value.url).replace(/^<[^:]+:\/{0,2}/, '<')
317
- );
318
- }
319
-
320
- // List-*: <http://domain> (comment)
321
- // the ctext specials go out as quoted-pairs, otherwise a ")" closes the
322
- // comment early and leaves the rest as junk, an unpaired "(" opens a
323
- // nested comment that never closes, and a trailing backslash escapes
324
- // the closing ")" so the comment swallows whatever follows it
325
- comment = needsEncoding ? mimeFuncs.encodeWord(comment) : comment.replace(/[()\\]/g, '\\$&');
326
-
327
- return this._formatListUrl(value.url) + (value.comment ? ' (' + comment + ')' : '');
254
+ if (typeof value === 'string') {
255
+ value = {
256
+ url: value
257
+ };
258
+ }
259
+ if (value && value.url) {
260
+ // strip CR/LF so a comment can't inject extra header lines. DEL is neither
261
+ // qtext nor ctext, so it can not be carried literally by either construct
262
+ // and has to become an encoded word like any other non-plaintext value
263
+ let comment = (value.comment || '').toString().replace(/\r?\n|\r/g, ' ');
264
+ const needsEncoding = !mimeFuncs.isPlainText(comment) || /\x7f/.test(comment);
265
+ if (key.toLowerCase().trim() === 'id') {
266
+ // List-ID: "comment" <domain>, where an unescaped quote or a trailing
267
+ // backslash in the comment would swallow the <domain> behind it
268
+ comment = needsEncoding ? mimeFuncs.encodeWord(comment) : mimeFuncs.quoteString(comment);
269
+ // List-ID expects a bare domain-like identifier, so strip the
270
+ // scheme prefix that _formatListUrl adds or passes through
271
+ return ((value.comment ? comment + ' ' : '') + this._formatListUrl(value.url).replace(/^<[^:]+:\/{0,2}/, '<'));
328
272
  }
329
-
330
- return '';
331
- })
273
+ // List-*: <http://domain> (comment)
274
+ // the ctext specials go out as quoted-pairs, otherwise a ")" closes the
275
+ // comment early and leaves the rest as junk, an unpaired "(" opens a
276
+ // nested comment that never closes, and a trailing backslash escapes
277
+ // the closing ")" so the comment swallows whatever follows it
278
+ comment = needsEncoding ? mimeFuncs.encodeWord(comment) : comment.replace(/[()\\]/g, '\\$&');
279
+ return this._formatListUrl(value.url) + (value.comment ? ' (' + comment + ')' : '');
280
+ }
281
+ return '';
282
+ })
332
283
  .filter(value => value)
333
284
  .join(', ')
334
285
  }))
335
286
  }));
336
287
  }
337
-
288
+ /** @internal */
338
289
  _formatListUrl(url) {
339
290
  // a url has no way to carry a control char or DEL, and the angle brackets around it
340
291
  // are not a quoting construct, so anything left here lands in the header raw
@@ -345,9 +296,6 @@ class MailMessage {
345
296
  if (/^[^@]+@[^@]+$/.test(url)) {
346
297
  return '<mailto:' + url + '>';
347
298
  }
348
-
349
299
  return '<http://' + url + '>';
350
300
  }
351
301
  }
352
-
353
- module.exports = MailMessage;
@@ -0,0 +1,161 @@
1
+ /**
2
+ * A header value split into the value token and its parameters, the result of parseHeaderValue
3
+ */
4
+ export interface ParsedHeaderValue {
5
+ /** The value ahead of the parameters, for example the content type, an empty string when there is none */
6
+ value: string;
7
+ /** Parameter values keyed by lowercase parameter name */
8
+ params: Record<string, string>;
9
+ }
10
+ /**
11
+ * Header value structure accepted by buildHeaderValue
12
+ */
13
+ export interface StructuredHeaderValue {
14
+ /** The value ahead of the parameters, for example the content type */
15
+ value: string | false;
16
+ /** Parameter values keyed by parameter name */
17
+ params?: Record<string, string> | undefined;
18
+ }
19
+ /**
20
+ * A single key=value pair of an rfc2231 encoded header parameter
21
+ */
22
+ export interface EncodedHeaderParam {
23
+ /** Parameter name with the continuation suffix, for example title*0* */
24
+ key: string;
25
+ /** Parameter value of this part */
26
+ value: string;
27
+ }
28
+ /** The names @types/nodemailer used for the two types above */
29
+ export type HeaderValue = StructuredHeaderValue;
30
+ export type ParsedHeaderParam = EncodedHeaderParam;
31
+ /**
32
+ * Checks if a value is plaintext string (uses only printable 7bit chars)
33
+ *
34
+ * When isParam is set the value is destined for a header parameter, so HT, CR and LF
35
+ * are not plaintext either: a header parameter has no way to carry them. HT is a valid
36
+ * fold point, so folding and unfolding a header would rewrite it as a space, and CR/LF
37
+ * cannot appear in a header value at all. DEL is neither a token character nor qtext,
38
+ * so it can not be carried bare or quoted. Such values have to go through the rfc2231
39
+ * parameter continuation encoding instead, the same way a quote already does.
40
+ *
41
+ * @param value String to be tested
42
+ * @param [isParam] Set to true if the value is a header parameter value
43
+ * @returns true if it is a plaintext string
44
+ */
45
+ export declare function isPlainText(value: unknown, isParam?: boolean): boolean;
46
+ /**
47
+ * Wraps a value into a quoted-string. Inside one a quote would end the string early
48
+ * and a backslash would escape whatever follows it, so both go out as quoted-pairs.
49
+ *
50
+ * @param value String to be quoted
51
+ * @returns The value as a quoted-string, quotes included
52
+ */
53
+ export declare function quoteString(value?: string): string;
54
+ /**
55
+ * Checks if a multi line string containes lines longer than the selected value.
56
+ *
57
+ * Useful when detecting if a mail message needs any processing at all:
58
+ * if only plaintext characters are used and lines are short, then there is
59
+ * no need to encode the values in any way. If the value is plaintext but has
60
+ * longer lines then allowed, then use format=flowed
61
+ *
62
+ * @param str Multi line string to check
63
+ * @param lineLength Max line length to check for
64
+ * @returns Returns true if there is at least one line longer than lineLength chars
65
+ */
66
+ export declare function hasLongerLines(str: string, lineLength: number): boolean;
67
+ /**
68
+ * Encodes a string or an Buffer to an UTF-8 MIME Word (rfc2047)
69
+ *
70
+ * @param data String to be encoded
71
+ * @param mimeWordEncoding='Q' Encoding for the mime word, either Q or B
72
+ * @param [maxLength=0] If set, split mime words into several chunks if needed
73
+ * @return Single or several mime words joined together
74
+ */
75
+ export declare function encodeWord(data: string | Buffer, mimeWordEncoding?: string, maxLength?: number): string;
76
+ /**
77
+ * Finds word sequences with non ascii text and converts these to mime words
78
+ *
79
+ * @param value String to be encoded
80
+ * @param mimeWordEncoding='Q' Encoding for the mime word, either Q or B
81
+ * @param [maxLength=0] If set, split mime words into several chunks if needed
82
+ * @param [encodeAll=false] If true and the value needs encoding then encodes entire string, not just the smallest match
83
+ * @return String with possible mime words
84
+ */
85
+ export declare function encodeWords(value: string, mimeWordEncoding?: string, maxLength?: number, encodeAll?: boolean): string;
86
+ /**
87
+ * Joins parsed header value together as 'value; param1=value1; param2=value2'
88
+ * PS: We are following RFC 822 for the list of special characters that we need to keep in quotes.
89
+ * Refer: https://www.w3.org/Protocols/rfc1341/4_Content-Type.html
90
+ * @param structured Parsed header value
91
+ * @return joined header value
92
+ */
93
+ export declare function buildHeaderValue(structured: StructuredHeaderValue): string;
94
+ /**
95
+ * Encodes a string or an Buffer to an UTF-8 Parameter Value Continuation encoding (rfc2231)
96
+ * Useful for splitting long parameter values.
97
+ *
98
+ * For example
99
+ * title="unicode string"
100
+ * becomes
101
+ * title*0*=utf-8''unicode
102
+ * title*1*=%20string
103
+ *
104
+ * @param key Parameter name the generated keys are built from, for example title
105
+ * @param data String to be encoded
106
+ * @param [maxLength=50] Max length for generated chunks
107
+ * @return A list of encoded keys and headers
108
+ */
109
+ export declare function buildHeaderParam(key: string, data: string | Buffer, maxLength?: number): EncodedHeaderParam[];
110
+ /**
111
+ * Parses a header value with key=value arguments into a structured
112
+ * object.
113
+ *
114
+ * parseHeaderValue('content-type: text/plain; CHARSET='UTF-8'') ->
115
+ * {
116
+ * 'value': 'text/plain',
117
+ * 'params': {
118
+ * 'charset': 'UTF-8'
119
+ * }
120
+ * }
121
+ *
122
+ * @param str Header value
123
+ * @return Header value as a parsed structure
124
+ */
125
+ export declare function parseHeaderValue(str: string): ParsedHeaderValue;
126
+ /**
127
+ * Returns file extension for a content type string. If no suitable extensions
128
+ * are found, 'bin' is used as the default extension
129
+ *
130
+ * @param mimeType Content type to be checked for
131
+ * @return File extension
132
+ */
133
+ export declare function detectExtension(mimeType?: string | false): string;
134
+ /**
135
+ * Returns content type for a file extension. If no suitable content types
136
+ * are found, 'application/octet-stream' is used as the default content type
137
+ *
138
+ * @param extension Extension to be checked for
139
+ * @return File extension
140
+ */
141
+ export declare function detectMimeType(extension?: string | false): string;
142
+ /**
143
+ * Folds long lines, useful for folding header lines (afterSpace=false) and
144
+ * flowed text (afterSpace=true)
145
+ *
146
+ * @param str String to be folded
147
+ * @param [lineLength=76] Maximum length of a line
148
+ * @param afterSpace If true, leave a space in th end of a line
149
+ * @return String with folded lines
150
+ */
151
+ export declare function foldLines(str: string, lineLength?: number, afterSpace?: boolean): string;
152
+ /**
153
+ * Splits a mime encoded string. Needed for dividing mime words into smaller chunks
154
+ *
155
+ * @param str Mime encoded string to be split up
156
+ * @param maxlen Maximum length of characters for one part (minimum 12)
157
+ * @return Split string
158
+ */
159
+ export declare function splitMimeEncodedString(str: string, maxlen?: number): string[];
160
+ export declare function encodeURICharComponent(chr: string): string;
161
+ export declare function safeEncodeURIComponent(str: string): string;