@bobfrankston/mailx 1.0.12 → 1.0.14

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 (172) hide show
  1. package/bin/mailx.js +52 -28
  2. package/client/app.js +113 -30
  3. package/client/components/folder-tree.js +84 -3
  4. package/client/components/message-list.js +164 -10
  5. package/client/components/message-viewer.js +130 -13
  6. package/client/compose/compose.html +4 -4
  7. package/client/compose/compose.js +53 -34
  8. package/client/index.html +50 -21
  9. package/client/lib/api-client.js +112 -31
  10. package/client/lib/mailxapi.js +123 -0
  11. package/client/package.json +1 -1
  12. package/client/styles/components.css +206 -16
  13. package/client/styles/layout.css +2 -1
  14. package/killmail.cmd +6 -0
  15. package/launch.ps1 +47 -5
  16. package/launcher/bin/mailx-app-linux +0 -0
  17. package/launcher/bin/mailx-app.exe +0 -0
  18. package/launcher/builder/build-config.json +11 -0
  19. package/launcher/builder/postinstall.js +81 -0
  20. package/package.json +2 -4
  21. package/packages/mailx-api/index.js +125 -29
  22. package/packages/mailx-core/index.d.ts +129 -0
  23. package/packages/mailx-core/index.js +323 -0
  24. package/packages/mailx-core/ipc.d.ts +13 -0
  25. package/packages/mailx-core/ipc.js +56 -0
  26. package/packages/mailx-core/package.json +18 -0
  27. package/packages/mailx-imap/index.d.ts +7 -1
  28. package/packages/mailx-imap/index.js +89 -14
  29. package/packages/mailx-server/index.js +42 -31
  30. package/packages/mailx-server/package.json +1 -2
  31. package/packages/mailx-settings/index.d.ts +1 -1
  32. package/packages/mailx-settings/index.js +21 -12
  33. package/packages/mailx-store/db.d.ts +6 -2
  34. package/packages/mailx-store/db.js +78 -16
  35. package/packages/mailx-store/file-store.d.ts +2 -8
  36. package/packages/mailx-store/file-store.js +7 -31
  37. package/packages/mailx-types/index.d.ts +3 -1
  38. package/.tswalk.json +0 -7396
  39. package/launcher/release.cmd +0 -4
  40. package/mailx.json +0 -9
  41. package/packages/mailx-api/node_modules/nodemailer/.ncurc.js +0 -9
  42. package/packages/mailx-api/node_modules/nodemailer/.prettierignore +0 -8
  43. package/packages/mailx-api/node_modules/nodemailer/.prettierrc +0 -12
  44. package/packages/mailx-api/node_modules/nodemailer/.prettierrc.js +0 -10
  45. package/packages/mailx-api/node_modules/nodemailer/.release-please-config.json +0 -9
  46. package/packages/mailx-api/node_modules/nodemailer/LICENSE +0 -16
  47. package/packages/mailx-api/node_modules/nodemailer/README.md +0 -86
  48. package/packages/mailx-api/node_modules/nodemailer/SECURITY.txt +0 -22
  49. package/packages/mailx-api/node_modules/nodemailer/eslint.config.js +0 -88
  50. package/packages/mailx-api/node_modules/nodemailer/lib/addressparser/index.js +0 -383
  51. package/packages/mailx-api/node_modules/nodemailer/lib/base64/index.js +0 -139
  52. package/packages/mailx-api/node_modules/nodemailer/lib/dkim/index.js +0 -253
  53. package/packages/mailx-api/node_modules/nodemailer/lib/dkim/message-parser.js +0 -155
  54. package/packages/mailx-api/node_modules/nodemailer/lib/dkim/relaxed-body.js +0 -154
  55. package/packages/mailx-api/node_modules/nodemailer/lib/dkim/sign.js +0 -117
  56. package/packages/mailx-api/node_modules/nodemailer/lib/fetch/cookies.js +0 -281
  57. package/packages/mailx-api/node_modules/nodemailer/lib/fetch/index.js +0 -280
  58. package/packages/mailx-api/node_modules/nodemailer/lib/json-transport/index.js +0 -82
  59. package/packages/mailx-api/node_modules/nodemailer/lib/mail-composer/index.js +0 -629
  60. package/packages/mailx-api/node_modules/nodemailer/lib/mailer/index.js +0 -441
  61. package/packages/mailx-api/node_modules/nodemailer/lib/mailer/mail-message.js +0 -316
  62. package/packages/mailx-api/node_modules/nodemailer/lib/mime-funcs/index.js +0 -625
  63. package/packages/mailx-api/node_modules/nodemailer/lib/mime-funcs/mime-types.js +0 -2113
  64. package/packages/mailx-api/node_modules/nodemailer/lib/mime-node/index.js +0 -1316
  65. package/packages/mailx-api/node_modules/nodemailer/lib/mime-node/last-newline.js +0 -33
  66. package/packages/mailx-api/node_modules/nodemailer/lib/mime-node/le-unix.js +0 -43
  67. package/packages/mailx-api/node_modules/nodemailer/lib/mime-node/le-windows.js +0 -52
  68. package/packages/mailx-api/node_modules/nodemailer/lib/nodemailer.js +0 -157
  69. package/packages/mailx-api/node_modules/nodemailer/lib/punycode/index.js +0 -460
  70. package/packages/mailx-api/node_modules/nodemailer/lib/qp/index.js +0 -227
  71. package/packages/mailx-api/node_modules/nodemailer/lib/sendmail-transport/index.js +0 -210
  72. package/packages/mailx-api/node_modules/nodemailer/lib/ses-transport/index.js +0 -234
  73. package/packages/mailx-api/node_modules/nodemailer/lib/shared/index.js +0 -754
  74. package/packages/mailx-api/node_modules/nodemailer/lib/smtp-connection/data-stream.js +0 -108
  75. package/packages/mailx-api/node_modules/nodemailer/lib/smtp-connection/http-proxy-client.js +0 -143
  76. package/packages/mailx-api/node_modules/nodemailer/lib/smtp-connection/index.js +0 -1870
  77. package/packages/mailx-api/node_modules/nodemailer/lib/smtp-pool/index.js +0 -652
  78. package/packages/mailx-api/node_modules/nodemailer/lib/smtp-pool/pool-resource.js +0 -259
  79. package/packages/mailx-api/node_modules/nodemailer/lib/smtp-transport/index.js +0 -421
  80. package/packages/mailx-api/node_modules/nodemailer/lib/stream-transport/index.js +0 -135
  81. package/packages/mailx-api/node_modules/nodemailer/lib/well-known/index.js +0 -47
  82. package/packages/mailx-api/node_modules/nodemailer/lib/well-known/services.json +0 -611
  83. package/packages/mailx-api/node_modules/nodemailer/lib/xoauth2/index.js +0 -427
  84. package/packages/mailx-api/node_modules/nodemailer/package.json +0 -47
  85. package/packages/mailx-imap/node_modules/nodemailer/.ncurc.js +0 -9
  86. package/packages/mailx-imap/node_modules/nodemailer/.prettierignore +0 -8
  87. package/packages/mailx-imap/node_modules/nodemailer/.prettierrc +0 -12
  88. package/packages/mailx-imap/node_modules/nodemailer/.prettierrc.js +0 -10
  89. package/packages/mailx-imap/node_modules/nodemailer/.release-please-config.json +0 -9
  90. package/packages/mailx-imap/node_modules/nodemailer/LICENSE +0 -16
  91. package/packages/mailx-imap/node_modules/nodemailer/README.md +0 -86
  92. package/packages/mailx-imap/node_modules/nodemailer/SECURITY.txt +0 -22
  93. package/packages/mailx-imap/node_modules/nodemailer/eslint.config.js +0 -88
  94. package/packages/mailx-imap/node_modules/nodemailer/lib/addressparser/index.js +0 -383
  95. package/packages/mailx-imap/node_modules/nodemailer/lib/base64/index.js +0 -139
  96. package/packages/mailx-imap/node_modules/nodemailer/lib/dkim/index.js +0 -253
  97. package/packages/mailx-imap/node_modules/nodemailer/lib/dkim/message-parser.js +0 -155
  98. package/packages/mailx-imap/node_modules/nodemailer/lib/dkim/relaxed-body.js +0 -154
  99. package/packages/mailx-imap/node_modules/nodemailer/lib/dkim/sign.js +0 -117
  100. package/packages/mailx-imap/node_modules/nodemailer/lib/fetch/cookies.js +0 -281
  101. package/packages/mailx-imap/node_modules/nodemailer/lib/fetch/index.js +0 -280
  102. package/packages/mailx-imap/node_modules/nodemailer/lib/json-transport/index.js +0 -82
  103. package/packages/mailx-imap/node_modules/nodemailer/lib/mail-composer/index.js +0 -629
  104. package/packages/mailx-imap/node_modules/nodemailer/lib/mailer/index.js +0 -441
  105. package/packages/mailx-imap/node_modules/nodemailer/lib/mailer/mail-message.js +0 -316
  106. package/packages/mailx-imap/node_modules/nodemailer/lib/mime-funcs/index.js +0 -625
  107. package/packages/mailx-imap/node_modules/nodemailer/lib/mime-funcs/mime-types.js +0 -2113
  108. package/packages/mailx-imap/node_modules/nodemailer/lib/mime-node/index.js +0 -1316
  109. package/packages/mailx-imap/node_modules/nodemailer/lib/mime-node/last-newline.js +0 -33
  110. package/packages/mailx-imap/node_modules/nodemailer/lib/mime-node/le-unix.js +0 -43
  111. package/packages/mailx-imap/node_modules/nodemailer/lib/mime-node/le-windows.js +0 -52
  112. package/packages/mailx-imap/node_modules/nodemailer/lib/nodemailer.js +0 -157
  113. package/packages/mailx-imap/node_modules/nodemailer/lib/punycode/index.js +0 -460
  114. package/packages/mailx-imap/node_modules/nodemailer/lib/qp/index.js +0 -227
  115. package/packages/mailx-imap/node_modules/nodemailer/lib/sendmail-transport/index.js +0 -210
  116. package/packages/mailx-imap/node_modules/nodemailer/lib/ses-transport/index.js +0 -234
  117. package/packages/mailx-imap/node_modules/nodemailer/lib/shared/index.js +0 -754
  118. package/packages/mailx-imap/node_modules/nodemailer/lib/smtp-connection/data-stream.js +0 -108
  119. package/packages/mailx-imap/node_modules/nodemailer/lib/smtp-connection/http-proxy-client.js +0 -143
  120. package/packages/mailx-imap/node_modules/nodemailer/lib/smtp-connection/index.js +0 -1870
  121. package/packages/mailx-imap/node_modules/nodemailer/lib/smtp-pool/index.js +0 -652
  122. package/packages/mailx-imap/node_modules/nodemailer/lib/smtp-pool/pool-resource.js +0 -259
  123. package/packages/mailx-imap/node_modules/nodemailer/lib/smtp-transport/index.js +0 -421
  124. package/packages/mailx-imap/node_modules/nodemailer/lib/stream-transport/index.js +0 -135
  125. package/packages/mailx-imap/node_modules/nodemailer/lib/well-known/index.js +0 -47
  126. package/packages/mailx-imap/node_modules/nodemailer/lib/well-known/services.json +0 -611
  127. package/packages/mailx-imap/node_modules/nodemailer/lib/xoauth2/index.js +0 -427
  128. package/packages/mailx-imap/node_modules/nodemailer/package.json +0 -47
  129. package/packages/mailx-send/node_modules/nodemailer/.ncurc.js +0 -9
  130. package/packages/mailx-send/node_modules/nodemailer/.prettierignore +0 -8
  131. package/packages/mailx-send/node_modules/nodemailer/.prettierrc +0 -12
  132. package/packages/mailx-send/node_modules/nodemailer/.prettierrc.js +0 -10
  133. package/packages/mailx-send/node_modules/nodemailer/.release-please-config.json +0 -9
  134. package/packages/mailx-send/node_modules/nodemailer/LICENSE +0 -16
  135. package/packages/mailx-send/node_modules/nodemailer/README.md +0 -86
  136. package/packages/mailx-send/node_modules/nodemailer/SECURITY.txt +0 -22
  137. package/packages/mailx-send/node_modules/nodemailer/eslint.config.js +0 -88
  138. package/packages/mailx-send/node_modules/nodemailer/lib/addressparser/index.js +0 -383
  139. package/packages/mailx-send/node_modules/nodemailer/lib/base64/index.js +0 -139
  140. package/packages/mailx-send/node_modules/nodemailer/lib/dkim/index.js +0 -253
  141. package/packages/mailx-send/node_modules/nodemailer/lib/dkim/message-parser.js +0 -155
  142. package/packages/mailx-send/node_modules/nodemailer/lib/dkim/relaxed-body.js +0 -154
  143. package/packages/mailx-send/node_modules/nodemailer/lib/dkim/sign.js +0 -117
  144. package/packages/mailx-send/node_modules/nodemailer/lib/fetch/cookies.js +0 -281
  145. package/packages/mailx-send/node_modules/nodemailer/lib/fetch/index.js +0 -280
  146. package/packages/mailx-send/node_modules/nodemailer/lib/json-transport/index.js +0 -82
  147. package/packages/mailx-send/node_modules/nodemailer/lib/mail-composer/index.js +0 -629
  148. package/packages/mailx-send/node_modules/nodemailer/lib/mailer/index.js +0 -441
  149. package/packages/mailx-send/node_modules/nodemailer/lib/mailer/mail-message.js +0 -316
  150. package/packages/mailx-send/node_modules/nodemailer/lib/mime-funcs/index.js +0 -625
  151. package/packages/mailx-send/node_modules/nodemailer/lib/mime-funcs/mime-types.js +0 -2113
  152. package/packages/mailx-send/node_modules/nodemailer/lib/mime-node/index.js +0 -1316
  153. package/packages/mailx-send/node_modules/nodemailer/lib/mime-node/last-newline.js +0 -33
  154. package/packages/mailx-send/node_modules/nodemailer/lib/mime-node/le-unix.js +0 -43
  155. package/packages/mailx-send/node_modules/nodemailer/lib/mime-node/le-windows.js +0 -52
  156. package/packages/mailx-send/node_modules/nodemailer/lib/nodemailer.js +0 -157
  157. package/packages/mailx-send/node_modules/nodemailer/lib/punycode/index.js +0 -460
  158. package/packages/mailx-send/node_modules/nodemailer/lib/qp/index.js +0 -227
  159. package/packages/mailx-send/node_modules/nodemailer/lib/sendmail-transport/index.js +0 -210
  160. package/packages/mailx-send/node_modules/nodemailer/lib/ses-transport/index.js +0 -234
  161. package/packages/mailx-send/node_modules/nodemailer/lib/shared/index.js +0 -754
  162. package/packages/mailx-send/node_modules/nodemailer/lib/smtp-connection/data-stream.js +0 -108
  163. package/packages/mailx-send/node_modules/nodemailer/lib/smtp-connection/http-proxy-client.js +0 -143
  164. package/packages/mailx-send/node_modules/nodemailer/lib/smtp-connection/index.js +0 -1870
  165. package/packages/mailx-send/node_modules/nodemailer/lib/smtp-pool/index.js +0 -652
  166. package/packages/mailx-send/node_modules/nodemailer/lib/smtp-pool/pool-resource.js +0 -259
  167. package/packages/mailx-send/node_modules/nodemailer/lib/smtp-transport/index.js +0 -421
  168. package/packages/mailx-send/node_modules/nodemailer/lib/stream-transport/index.js +0 -135
  169. package/packages/mailx-send/node_modules/nodemailer/lib/well-known/index.js +0 -47
  170. package/packages/mailx-send/node_modules/nodemailer/lib/well-known/services.json +0 -611
  171. package/packages/mailx-send/node_modules/nodemailer/lib/xoauth2/index.js +0 -427
  172. package/packages/mailx-send/node_modules/nodemailer/package.json +0 -47
@@ -1,210 +0,0 @@
1
- 'use strict';
2
-
3
- const spawn = require('child_process').spawn;
4
- const packageData = require('../../package.json');
5
- const shared = require('../shared');
6
-
7
- /**
8
- * Generates a Transport object for Sendmail
9
- *
10
- * Possible options can be the following:
11
- *
12
- * * **path** optional path to sendmail binary
13
- * * **newline** either 'windows' or 'unix'
14
- * * **args** an array of arguments for the sendmail binary
15
- *
16
- * @constructor
17
- * @param {Object} optional config parameter for Sendmail
18
- */
19
- class SendmailTransport {
20
- constructor(options) {
21
- options = options || {};
22
-
23
- // use a reference to spawn for mocking purposes
24
- this._spawn = spawn;
25
-
26
- this.options = options || {};
27
-
28
- this.name = 'Sendmail';
29
- this.version = packageData.version;
30
-
31
- this.path = 'sendmail';
32
- this.args = false;
33
- this.winbreak = false;
34
-
35
- this.logger = shared.getLogger(this.options, {
36
- component: this.options.component || 'sendmail'
37
- });
38
-
39
- if (options) {
40
- if (typeof options === 'string') {
41
- this.path = options;
42
- } else if (typeof options === 'object') {
43
- if (options.path) {
44
- this.path = options.path;
45
- }
46
- if (Array.isArray(options.args)) {
47
- this.args = options.args;
48
- }
49
- this.winbreak = ['win', 'windows', 'dos', '\r\n'].includes((options.newline || '').toString().toLowerCase());
50
- }
51
- }
52
- }
53
-
54
- /**
55
- * <p>Compiles a mailcomposer message and forwards it to handler that sends it.</p>
56
- *
57
- * @param {Object} emailMessage MailComposer object
58
- * @param {Function} callback Callback function to run when the sending is completed
59
- */
60
- send(mail, done) {
61
- // Sendmail strips this header line by itself
62
- mail.message.keepBcc = true;
63
-
64
- let envelope = mail.data.envelope || mail.message.getEnvelope();
65
- let messageId = mail.message.messageId();
66
- let args;
67
- let sendmail;
68
- let returned;
69
-
70
- const hasInvalidAddresses = []
71
- .concat(envelope.from || [])
72
- .concat(envelope.to || [])
73
- .some(addr => /^-/.test(addr));
74
- if (hasInvalidAddresses) {
75
- return done(new Error('Can not send mail. Invalid envelope addresses.'));
76
- }
77
-
78
- if (this.args) {
79
- // force -i to keep single dots
80
- args = ['-i'].concat(this.args).concat(envelope.to);
81
- } else {
82
- args = ['-i'].concat(envelope.from ? ['-f', envelope.from] : []).concat(envelope.to);
83
- }
84
-
85
- let callback = err => {
86
- if (returned) {
87
- // ignore any additional responses, already done
88
- return;
89
- }
90
- returned = true;
91
- if (typeof done === 'function') {
92
- if (err) {
93
- return done(err);
94
- } else {
95
- return done(null, {
96
- envelope: mail.data.envelope || mail.message.getEnvelope(),
97
- messageId,
98
- response: 'Messages queued for delivery'
99
- });
100
- }
101
- }
102
- };
103
-
104
- try {
105
- sendmail = this._spawn(this.path, args);
106
- } catch (E) {
107
- this.logger.error(
108
- {
109
- err: E,
110
- tnx: 'spawn',
111
- messageId
112
- },
113
- 'Error occurred while spawning sendmail. %s',
114
- E.message
115
- );
116
- return callback(E);
117
- }
118
-
119
- if (sendmail) {
120
- sendmail.on('error', err => {
121
- this.logger.error(
122
- {
123
- err,
124
- tnx: 'spawn',
125
- messageId
126
- },
127
- 'Error occurred when sending message %s. %s',
128
- messageId,
129
- err.message
130
- );
131
- callback(err);
132
- });
133
-
134
- sendmail.once('exit', code => {
135
- if (!code) {
136
- return callback();
137
- }
138
- let err;
139
- if (code === 127) {
140
- err = new Error('Sendmail command not found, process exited with code ' + code);
141
- } else {
142
- err = new Error('Sendmail exited with code ' + code);
143
- }
144
-
145
- this.logger.error(
146
- {
147
- err,
148
- tnx: 'stdin',
149
- messageId
150
- },
151
- 'Error sending message %s to sendmail. %s',
152
- messageId,
153
- err.message
154
- );
155
- callback(err);
156
- });
157
- sendmail.once('close', callback);
158
-
159
- sendmail.stdin.on('error', err => {
160
- this.logger.error(
161
- {
162
- err,
163
- tnx: 'stdin',
164
- messageId
165
- },
166
- 'Error occurred when piping message %s to sendmail. %s',
167
- messageId,
168
- err.message
169
- );
170
- callback(err);
171
- });
172
-
173
- let recipients = [].concat(envelope.to || []);
174
- if (recipients.length > 3) {
175
- recipients.push('...and ' + recipients.splice(2).length + ' more');
176
- }
177
- this.logger.info(
178
- {
179
- tnx: 'send',
180
- messageId
181
- },
182
- 'Sending message %s to <%s>',
183
- messageId,
184
- recipients.join(', ')
185
- );
186
-
187
- let sourceStream = mail.message.createReadStream();
188
- sourceStream.once('error', err => {
189
- this.logger.error(
190
- {
191
- err,
192
- tnx: 'stdin',
193
- messageId
194
- },
195
- 'Error occurred when generating message %s. %s',
196
- messageId,
197
- err.message
198
- );
199
- sendmail.kill('SIGINT'); // do not deliver the message
200
- callback(err);
201
- });
202
-
203
- sourceStream.pipe(sendmail.stdin);
204
- } else {
205
- return callback(new Error('sendmail was not found'));
206
- }
207
- }
208
- }
209
-
210
- module.exports = SendmailTransport;
@@ -1,234 +0,0 @@
1
- 'use strict';
2
-
3
- const EventEmitter = require('events');
4
- const packageData = require('../../package.json');
5
- const shared = require('../shared');
6
- const LeWindows = require('../mime-node/le-windows');
7
- const MimeNode = require('../mime-node');
8
-
9
- /**
10
- * Generates a Transport object for AWS SES
11
- *
12
- * @constructor
13
- * @param {Object} optional config parameter
14
- */
15
- class SESTransport extends EventEmitter {
16
- constructor(options) {
17
- super();
18
- options = options || {};
19
-
20
- this.options = options || {};
21
- this.ses = this.options.SES;
22
-
23
- this.name = 'SESTransport';
24
- this.version = packageData.version;
25
-
26
- this.logger = shared.getLogger(this.options, {
27
- component: this.options.component || 'ses-transport'
28
- });
29
- }
30
-
31
- getRegion(cb) {
32
- if (this.ses.sesClient.config && typeof this.ses.sesClient.config.region === 'function') {
33
- // promise
34
- return this.ses.sesClient.config
35
- .region()
36
- .then(region => cb(null, region))
37
- .catch(err => cb(err));
38
- }
39
- return cb(null, false);
40
- }
41
-
42
- /**
43
- * Compiles a mailcomposer message and forwards it to SES
44
- *
45
- * @param {Object} emailMessage MailComposer object
46
- * @param {Function} callback Callback function to run when the sending is completed
47
- */
48
- send(mail, callback) {
49
- let statObject = {
50
- ts: Date.now(),
51
- pending: true
52
- };
53
-
54
- let fromHeader = mail.message._headers.find(header => /^from$/i.test(header.key));
55
- if (fromHeader) {
56
- let mimeNode = new MimeNode('text/plain');
57
- fromHeader = mimeNode._convertAddresses(mimeNode._parseAddresses(fromHeader.value));
58
- }
59
-
60
- let envelope = mail.data.envelope || mail.message.getEnvelope();
61
- let messageId = mail.message.messageId();
62
-
63
- let recipients = [].concat(envelope.to || []);
64
- if (recipients.length > 3) {
65
- recipients.push('...and ' + recipients.splice(2).length + ' more');
66
- }
67
- this.logger.info(
68
- {
69
- tnx: 'send',
70
- messageId
71
- },
72
- 'Sending message %s to <%s>',
73
- messageId,
74
- recipients.join(', ')
75
- );
76
-
77
- let getRawMessage = next => {
78
- // do not use Message-ID and Date in DKIM signature
79
- if (!mail.data._dkim) {
80
- mail.data._dkim = {};
81
- }
82
- if (mail.data._dkim.skipFields && typeof mail.data._dkim.skipFields === 'string') {
83
- mail.data._dkim.skipFields += ':date:message-id';
84
- } else {
85
- mail.data._dkim.skipFields = 'date:message-id';
86
- }
87
-
88
- let sourceStream = mail.message.createReadStream();
89
- let stream = sourceStream.pipe(new LeWindows());
90
- let chunks = [];
91
- let chunklen = 0;
92
-
93
- stream.on('readable', () => {
94
- let chunk;
95
- while ((chunk = stream.read()) !== null) {
96
- chunks.push(chunk);
97
- chunklen += chunk.length;
98
- }
99
- });
100
-
101
- sourceStream.once('error', err => stream.emit('error', err));
102
-
103
- stream.once('error', err => {
104
- next(err);
105
- });
106
-
107
- stream.once('end', () => next(null, Buffer.concat(chunks, chunklen)));
108
- };
109
-
110
- setImmediate(() =>
111
- getRawMessage((err, raw) => {
112
- if (err) {
113
- this.logger.error(
114
- {
115
- err,
116
- tnx: 'send',
117
- messageId
118
- },
119
- 'Failed creating message for %s. %s',
120
- messageId,
121
- err.message
122
- );
123
- statObject.pending = false;
124
- return callback(err);
125
- }
126
-
127
- let sesMessage = {
128
- Content: {
129
- Raw: {
130
- // required
131
- Data: raw // required
132
- }
133
- },
134
- FromEmailAddress: fromHeader ? fromHeader : envelope.from,
135
- Destination: {
136
- ToAddresses: envelope.to
137
- }
138
- };
139
-
140
- Object.keys(mail.data.ses || {}).forEach(key => {
141
- sesMessage[key] = mail.data.ses[key];
142
- });
143
-
144
- this.getRegion((err, region) => {
145
- if (err || !region) {
146
- region = 'us-east-1';
147
- }
148
-
149
- const command = new this.ses.SendEmailCommand(sesMessage);
150
- const sendPromise = this.ses.sesClient.send(command);
151
-
152
- sendPromise
153
- .then(data => {
154
- if (region === 'us-east-1') {
155
- region = 'email';
156
- }
157
-
158
- statObject.pending = true;
159
- callback(null, {
160
- envelope: {
161
- from: envelope.from,
162
- to: envelope.to
163
- },
164
- messageId: '<' + data.MessageId + (!/@/.test(data.MessageId) ? '@' + region + '.amazonses.com' : '') + '>',
165
- response: data.MessageId,
166
- raw
167
- });
168
- })
169
- .catch(err => {
170
- this.logger.error(
171
- {
172
- err,
173
- tnx: 'send'
174
- },
175
- 'Send error for %s: %s',
176
- messageId,
177
- err.message
178
- );
179
- statObject.pending = false;
180
- callback(err);
181
- });
182
- });
183
- })
184
- );
185
- }
186
-
187
- /**
188
- * Verifies SES configuration
189
- *
190
- * @param {Function} callback Callback function
191
- */
192
- verify(callback) {
193
- let promise;
194
- if (!callback) {
195
- promise = new Promise((resolve, reject) => {
196
- callback = shared.callbackPromise(resolve, reject);
197
- });
198
- }
199
-
200
- const cb = err => {
201
- if (err && !['InvalidParameterValue', 'MessageRejected'].includes(err.code || err.Code || err.name)) {
202
- return callback(err);
203
- }
204
- return callback(null, true);
205
- };
206
-
207
- const sesMessage = {
208
- Content: {
209
- Raw: {
210
- Data: Buffer.from('From: <invalid@invalid>\r\nTo: <invalid@invalid>\r\n Subject: Invalid\r\n\r\nInvalid')
211
- }
212
- },
213
- FromEmailAddress: 'invalid@invalid',
214
- Destination: {
215
- ToAddresses: ['invalid@invalid']
216
- }
217
- };
218
-
219
- this.getRegion((err, region) => {
220
- if (err || !region) {
221
- region = 'us-east-1';
222
- }
223
-
224
- const command = new this.ses.SendEmailCommand(sesMessage);
225
- const sendPromise = this.ses.sesClient.send(command);
226
-
227
- sendPromise.then(data => cb(null, data)).catch(err => cb(err));
228
- });
229
-
230
- return promise;
231
- }
232
- }
233
-
234
- module.exports = SESTransport;