emailjs 4.0.3 → 5.0.1

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 (84) hide show
  1. package/README.md +215 -247
  2. package/dist/address.d.ts +6 -0
  3. package/dist/address.js +183 -0
  4. package/dist/address.js.map +1 -0
  5. package/dist/address.test.d.ts +1 -0
  6. package/dist/address.test.js +120 -0
  7. package/dist/address.test.js.map +1 -0
  8. package/dist/auth.integration.test.d.ts +1 -0
  9. package/dist/auth.integration.test.js +137 -0
  10. package/dist/auth.integration.test.js.map +1 -0
  11. package/dist/client.d.ts +39 -0
  12. package/dist/client.integration.test.d.ts +1 -0
  13. package/dist/client.integration.test.js +198 -0
  14. package/dist/client.integration.test.js.map +1 -0
  15. package/dist/client.js +202 -0
  16. package/dist/client.js.map +1 -0
  17. package/dist/client.test.d.ts +1 -0
  18. package/dist/client.test.js +293 -0
  19. package/dist/client.test.js.map +1 -0
  20. package/dist/connection.commands.integration.test.d.ts +1 -0
  21. package/dist/connection.commands.integration.test.js +79 -0
  22. package/dist/connection.commands.integration.test.js.map +1 -0
  23. package/dist/connection.d.ts +83 -0
  24. package/dist/connection.errors.integration.test.d.ts +1 -0
  25. package/dist/connection.errors.integration.test.js +186 -0
  26. package/dist/connection.errors.integration.test.js.map +1 -0
  27. package/dist/connection.greylist.integration.test.d.ts +1 -0
  28. package/dist/connection.greylist.integration.test.js +53 -0
  29. package/dist/connection.greylist.integration.test.js.map +1 -0
  30. package/dist/connection.integration.test.d.ts +1 -0
  31. package/dist/connection.integration.test.js +223 -0
  32. package/dist/connection.integration.test.js.map +1 -0
  33. package/dist/connection.js +492 -0
  34. package/dist/connection.js.map +1 -0
  35. package/dist/connection.test.d.ts +1 -0
  36. package/dist/connection.test.js +50 -0
  37. package/dist/connection.test.js.map +1 -0
  38. package/dist/date.d.ts +3 -0
  39. package/dist/date.js +26 -0
  40. package/dist/date.js.map +1 -0
  41. package/dist/date.test.d.ts +1 -0
  42. package/dist/date.test.js +26 -0
  43. package/dist/date.test.js.map +1 -0
  44. package/dist/error.d.ts +20 -0
  45. package/dist/error.js +31 -0
  46. package/dist/error.js.map +1 -0
  47. package/dist/error.test.d.ts +1 -0
  48. package/dist/error.test.js +23 -0
  49. package/dist/error.test.js.map +1 -0
  50. package/dist/index.d.ts +8 -0
  51. package/dist/index.js +9 -0
  52. package/dist/index.js.map +1 -0
  53. package/dist/message.d.ts +71 -0
  54. package/dist/message.integration.test.d.ts +1 -0
  55. package/dist/message.integration.test.js +401 -0
  56. package/dist/message.integration.test.js.map +1 -0
  57. package/dist/message.js +456 -0
  58. package/dist/message.js.map +1 -0
  59. package/dist/message.test.d.ts +1 -0
  60. package/dist/message.test.js +258 -0
  61. package/dist/message.test.js.map +1 -0
  62. package/dist/mime.d.ts +2 -0
  63. package/dist/mime.js +145 -0
  64. package/dist/mime.js.map +1 -0
  65. package/dist/mime.test.d.ts +1 -0
  66. package/dist/mime.test.js +76 -0
  67. package/dist/mime.test.js.map +1 -0
  68. package/dist/response.d.ts +6 -0
  69. package/dist/response.js +93 -0
  70. package/dist/response.js.map +1 -0
  71. package/dist/response.test.d.ts +1 -0
  72. package/dist/response.test.js +177 -0
  73. package/dist/response.test.js.map +1 -0
  74. package/package.json +30 -28
  75. package/email.js +0 -2126
  76. package/email.ts +0 -8
  77. package/smtp/address.ts +0 -237
  78. package/smtp/client.ts +0 -365
  79. package/smtp/connection.ts +0 -937
  80. package/smtp/date.ts +0 -51
  81. package/smtp/error.ts +0 -57
  82. package/smtp/message.ts +0 -774
  83. package/smtp/mime.ts +0 -234
  84. package/smtp/response.ts +0 -112
package/smtp/mime.ts DELETED
@@ -1,234 +0,0 @@
1
- // adapted from https://github.com/emailjs/emailjs-mime-codec/blob/6909c706b9f09bc0e5c3faf48f723cca53e5b352/src/mimecodec.js
2
- import { TextDecoder, TextEncoder } from 'util';
3
-
4
- const encoder = new TextEncoder();
5
-
6
- /**
7
- * @see https://tools.ietf.org/html/rfc2045#section-6.7
8
- */
9
- const RANGES = [
10
- [0x09], // <TAB>
11
- [0x0a], // <LF>
12
- [0x0d], // <CR>
13
- [0x20, 0x3c], // <SP>!"#$%&'()*+,-./0123456789:;
14
- [0x3e, 0x7e], // >?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}
15
- ];
16
- const LOOKUP =
17
- 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'.split('');
18
- const MAX_CHUNK_LENGTH = 16383; // must be multiple of 3
19
- const MAX_MIME_WORD_LENGTH = 52;
20
- const MAX_B64_MIME_WORD_BYTE_LENGTH = 39;
21
-
22
- function tripletToBase64(num: number) {
23
- return (
24
- LOOKUP[(num >> 18) & 0x3f] +
25
- LOOKUP[(num >> 12) & 0x3f] +
26
- LOOKUP[(num >> 6) & 0x3f] +
27
- LOOKUP[num & 0x3f]
28
- );
29
- }
30
-
31
- function encodeChunk(uint8: Uint8Array, start: number, end: number) {
32
- let output = '';
33
- for (let i = start; i < end; i += 3) {
34
- output += tripletToBase64(
35
- (uint8[i] << 16) + (uint8[i + 1] << 8) + uint8[i + 2]
36
- );
37
- }
38
- return output;
39
- }
40
-
41
- function encodeBase64(data: Uint8Array) {
42
- const len = data.length;
43
- const extraBytes = len % 3; // if we have 1 byte left, pad 2 bytes
44
- let output = '';
45
-
46
- // go through the array every three bytes, we'll deal with trailing stuff later
47
- for (let i = 0, len2 = len - extraBytes; i < len2; i += MAX_CHUNK_LENGTH) {
48
- output += encodeChunk(
49
- data,
50
- i,
51
- i + MAX_CHUNK_LENGTH > len2 ? len2 : i + MAX_CHUNK_LENGTH
52
- );
53
- }
54
-
55
- // pad the end with zeros, but make sure to not forget the extra bytes
56
- if (extraBytes === 1) {
57
- const tmp = data[len - 1];
58
- output += LOOKUP[tmp >> 2];
59
- output += LOOKUP[(tmp << 4) & 0x3f];
60
- output += '==';
61
- } else if (extraBytes === 2) {
62
- const tmp = (data[len - 2] << 8) + data[len - 1];
63
- output += LOOKUP[tmp >> 10];
64
- output += LOOKUP[(tmp >> 4) & 0x3f];
65
- output += LOOKUP[(tmp << 2) & 0x3f];
66
- output += '=';
67
- }
68
-
69
- return output;
70
- }
71
-
72
- /**
73
- * Splits a mime encoded string. Needed for dividing mime words into smaller chunks
74
- *
75
- * @param {string} str Mime encoded string to be split up
76
- * @param {number} maxlen Maximum length of characters for one part (minimum 12)
77
- * @return {string[]} lines
78
- */
79
- function splitMimeEncodedString(str: string, maxlen = 12) {
80
- const minWordLength = 12; // require at least 12 symbols to fit possible 4 octet UTF-8 sequences
81
- const maxWordLength = Math.max(maxlen, minWordLength);
82
- const lines: string[] = [];
83
-
84
- while (str.length) {
85
- let curLine = str.substr(0, maxWordLength);
86
-
87
- const match = curLine.match(/=[0-9A-F]?$/i); // skip incomplete escaped char
88
- if (match) {
89
- curLine = curLine.substr(0, match.index);
90
- }
91
-
92
- let done = false;
93
- while (!done) {
94
- let chr;
95
- done = true;
96
- const match = str.substr(curLine.length).match(/^=([0-9A-F]{2})/i); // check if not middle of a unicode char sequence
97
- if (match) {
98
- chr = parseInt(match[1], 16);
99
- // invalid sequence, move one char back anc recheck
100
- if (chr < 0xc2 && chr > 0x7f) {
101
- curLine = curLine.substr(0, curLine.length - 3);
102
- done = false;
103
- }
104
- }
105
- }
106
-
107
- if (curLine.length) {
108
- lines.push(curLine);
109
- }
110
- str = str.substr(curLine.length);
111
- }
112
-
113
- return lines;
114
- }
115
-
116
- /**
117
- *
118
- * @param {number} nr number
119
- * @returns {boolean} if number is in range
120
- */
121
- function checkRanges(nr: number) {
122
- return RANGES.reduce(
123
- (val, range) =>
124
- val ||
125
- (range.length === 1 && nr === range[0]) ||
126
- (range.length === 2 && nr >= range[0] && nr <= range[1]),
127
- false
128
- );
129
- }
130
-
131
- /**
132
- * Encodes all non printable and non ascii bytes to =XX form, where XX is the
133
- * byte value in hex. This function does not convert linebreaks etc. it
134
- * only escapes character sequences
135
- *
136
- * NOTE: Encoding support depends on util.TextDecoder, which is severely limited
137
- * prior to Node.js 13.
138
- *
139
- * @see https://nodejs.org/api/util.html#util_whatwg_supported_encodings
140
- * @see https://github.com/nodejs/node/issues/19214
141
- *
142
- * @param {string|Uint8Array} data Either a string or an Uint8Array
143
- * @param {string} encoding WHATWG supported encoding
144
- * @return {string} Mime encoded string
145
- */
146
- export function mimeEncode(data: string | Uint8Array = '', encoding = 'utf-8') {
147
- const decoder = new TextDecoder(encoding);
148
- const buffer =
149
- typeof data === 'string'
150
- ? encoder.encode(data)
151
- : encoder.encode(decoder.decode(data));
152
-
153
- return buffer.reduce(
154
- (aggregate, ord, index) =>
155
- checkRanges(ord) &&
156
- !(
157
- (ord === 0x20 || ord === 0x09) &&
158
- (index === buffer.length - 1 ||
159
- buffer[index + 1] === 0x0a ||
160
- buffer[index + 1] === 0x0d)
161
- )
162
- ? // if the char is in allowed range, then keep as is, unless it is a ws in the end of a line
163
- aggregate + String.fromCharCode(ord)
164
- : `${aggregate}=${ord < 0x10 ? '0' : ''}${ord
165
- .toString(16)
166
- .toUpperCase()}`,
167
- ''
168
- );
169
- }
170
-
171
- /**
172
- * Encodes a string or an Uint8Array to an UTF-8 MIME Word
173
- *
174
- * NOTE: Encoding support depends on util.TextDecoder, which is severely limited
175
- * prior to Node.js 13.
176
- *
177
- * @see https://tools.ietf.org/html/rfc2047
178
- * @see https://nodejs.org/api/util.html#util_whatwg_supported_encodings
179
- * @see https://github.com/nodejs/node/issues/19214
180
- *
181
- * @param {string|Uint8Array} data String to be encoded
182
- * @param {'Q' | 'B'} mimeWordEncoding='Q' Encoding for the mime word, either Q or B
183
- * @param {string} encoding WHATWG supported encoding
184
- * @return {string} Single or several mime words joined together
185
- */
186
- export function mimeWordEncode(
187
- data: string | Uint8Array,
188
- mimeWordEncoding: 'Q' | 'B' = 'Q',
189
- encoding = 'utf-8'
190
- ) {
191
- let parts: string[] = [];
192
- const decoder = new TextDecoder(encoding);
193
- const str = typeof data === 'string' ? data : decoder.decode(data);
194
-
195
- if (mimeWordEncoding === 'Q') {
196
- const encodedStr = mimeEncode(str, encoding).replace(
197
- /[^a-z0-9!*+\-/=]/gi,
198
- (chr: string) =>
199
- chr === ' '
200
- ? '_'
201
- : '=' +
202
- (chr.charCodeAt(0) < 0x10 ? '0' : '') +
203
- chr.charCodeAt(0).toString(16).toUpperCase()
204
- );
205
- parts =
206
- encodedStr.length < MAX_MIME_WORD_LENGTH
207
- ? [encodedStr]
208
- : splitMimeEncodedString(encodedStr, MAX_MIME_WORD_LENGTH);
209
- } else {
210
- // Fits as much as possible into every line without breaking utf-8 multibyte characters' octets up across lines
211
- let j = 0;
212
- let i = 0;
213
- while (i < str.length) {
214
- if (
215
- encoder.encode(str.substring(j, i)).length >
216
- MAX_B64_MIME_WORD_BYTE_LENGTH
217
- ) {
218
- // we went one character too far, substring at the char before
219
- parts.push(str.substring(j, i - 1));
220
- j = i - 1;
221
- } else {
222
- i++;
223
- }
224
- }
225
- // add the remainder of the string
226
- str.substring(j) && parts.push(str.substring(j));
227
- parts = parts.map((x) => encoder.encode(x)).map((x) => encodeBase64(x));
228
- }
229
-
230
- return parts
231
- .map((p) => `=?UTF-8?${mimeWordEncoding}?${p}?= `)
232
- .join('')
233
- .trim();
234
- }
package/smtp/response.ts DELETED
@@ -1,112 +0,0 @@
1
- import { SMTPError, SMTPErrorStates } from './error.js';
2
- import type { Socket } from 'net';
3
- import type { TLSSocket } from 'tls';
4
-
5
- export class SMTPResponseMonitor {
6
- public readonly stop: (err?: Error) => void;
7
-
8
- constructor(
9
- stream: Socket | TLSSocket,
10
- timeout: number,
11
- onerror: (err: Error) => void
12
- ) {
13
- let buffer = '';
14
-
15
- const notify = () => {
16
- if (buffer.length) {
17
- // parse buffer for response codes
18
- const line = buffer.replace('\r', '');
19
- if (
20
- !(
21
- line
22
- .trim()
23
- .split(/\n/)
24
- .pop()
25
- ?.match(/^(\d{3})\s/) ?? false
26
- )
27
- ) {
28
- return;
29
- }
30
-
31
- const match = line ? line.match(/(\d+)\s?(.*)/) : null;
32
- const data =
33
- match !== null
34
- ? { code: match[1], message: match[2], data: line }
35
- : { code: -1, data: line };
36
-
37
- stream.emit('response', null, data);
38
- buffer = '';
39
- }
40
- };
41
-
42
- const error = (err: Error) => {
43
- stream.emit(
44
- 'response',
45
- SMTPError.create(
46
- 'connection encountered an error',
47
- SMTPErrorStates.ERROR,
48
- err
49
- )
50
- );
51
- };
52
-
53
- const timedout = (err?: Error) => {
54
- stream.end();
55
- stream.emit(
56
- 'response',
57
- SMTPError.create(
58
- 'timedout while connecting to smtp server',
59
- SMTPErrorStates.TIMEDOUT,
60
- err
61
- )
62
- );
63
- };
64
-
65
- const watch = (data: string | Buffer) => {
66
- if (data !== null) {
67
- buffer += data.toString();
68
- notify();
69
- }
70
- };
71
-
72
- const close = (err: Error) => {
73
- stream.emit(
74
- 'response',
75
- SMTPError.create(
76
- 'connection has closed',
77
- SMTPErrorStates.CONNECTIONCLOSED,
78
- err
79
- )
80
- );
81
- };
82
-
83
- const end = (err: Error) => {
84
- stream.emit(
85
- 'response',
86
- SMTPError.create(
87
- 'connection has ended',
88
- SMTPErrorStates.CONNECTIONENDED,
89
- err
90
- )
91
- );
92
- };
93
-
94
- this.stop = (err) => {
95
- stream.removeAllListeners('response');
96
- stream.removeListener('data', watch);
97
- stream.removeListener('end', end);
98
- stream.removeListener('close', close);
99
- stream.removeListener('error', error);
100
-
101
- if (err != null && typeof onerror === 'function') {
102
- onerror(err);
103
- }
104
- };
105
-
106
- stream.on('data', watch);
107
- stream.on('end', end);
108
- stream.on('close', close);
109
- stream.on('error', error);
110
- stream.setTimeout(timeout, timedout);
111
- }
112
- }