emailjs 1.0.11 → 2.2.0
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.
- package/.editorconfig +10 -0
- package/.eslintrc.json +40 -0
- package/CHANGELOG.md +9 -0
- package/email.js +2 -0
- package/package.json +21 -16
- package/smtp/client.js +323 -206
- package/smtp/date.js +38 -0
- package/smtp/error.js +73 -7
- package/smtp/message.js +728 -619
- package/smtp/response.js +126 -68
- package/smtp/smtp.js +852 -569
- package/yarn.lock +1105 -0
package/smtp/date.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param {Date} [date] an optional date to convert to RFC2822 format
|
|
3
|
+
* @param {boolean} [useUtc=false] whether to parse the date as UTC (default: false)
|
|
4
|
+
* @returns {string} the converted date
|
|
5
|
+
*/
|
|
6
|
+
function getRFC2822Date(date = new Date(), useUtc = false) {
|
|
7
|
+
if (useUtc) {
|
|
8
|
+
return getRFC2822DateUTC(date);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const dates = date
|
|
12
|
+
.toString()
|
|
13
|
+
.replace('GMT', '')
|
|
14
|
+
.replace(/\s\(.*\)$/, '')
|
|
15
|
+
.split(' ');
|
|
16
|
+
|
|
17
|
+
dates[0] = dates[0] + ',';
|
|
18
|
+
|
|
19
|
+
const day = dates[1];
|
|
20
|
+
dates[1] = dates[2];
|
|
21
|
+
dates[2] = day;
|
|
22
|
+
|
|
23
|
+
return dates.join(' ');
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @param {Date} [date] an optional date to convert to RFC2822 format (UTC)
|
|
28
|
+
* @returns {string} the converted date
|
|
29
|
+
*/
|
|
30
|
+
function getRFC2822DateUTC(date = new Date()) {
|
|
31
|
+
const dates = date.toUTCString().split(' ');
|
|
32
|
+
dates.pop(); // remove timezone
|
|
33
|
+
dates.push('+0000');
|
|
34
|
+
return dates.join(' ');
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
exports.getRFC2822Date = getRFC2822Date;
|
|
38
|
+
exports.getRFC2822DateUTC = getRFC2822DateUTC;
|
package/smtp/error.js
CHANGED
|
@@ -1,20 +1,86 @@
|
|
|
1
|
+
class SMTPError extends Error {
|
|
2
|
+
/**
|
|
3
|
+
* @param {string} message the error message
|
|
4
|
+
*/
|
|
5
|
+
constructor(message) {
|
|
6
|
+
super(message);
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @type {number}
|
|
10
|
+
*/
|
|
11
|
+
this.code = null;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @type {*}
|
|
15
|
+
*/
|
|
16
|
+
this.smtp = null;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @type {Error}
|
|
20
|
+
*/
|
|
21
|
+
this.previous = null;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @param {string} message the error message
|
|
27
|
+
* @param {number} code the error code
|
|
28
|
+
* @param {Error} [error] an error object
|
|
29
|
+
* @param {*} [smtp] smtp
|
|
30
|
+
* @returns {SMTPError} an smtp error object
|
|
31
|
+
*/
|
|
1
32
|
module.exports = function(message, code, error, smtp) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
33
|
+
const err = new SMTPError(
|
|
34
|
+
error != null && error.message ? `${message} (${error.message})` : message
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
err.code = code;
|
|
38
|
+
err.smtp = smtp;
|
|
39
|
+
|
|
40
|
+
if (error) {
|
|
41
|
+
err.previous = error;
|
|
42
|
+
}
|
|
7
43
|
|
|
8
|
-
|
|
44
|
+
return err;
|
|
9
45
|
};
|
|
10
46
|
|
|
11
|
-
|
|
47
|
+
/**
|
|
48
|
+
* @type {1}
|
|
49
|
+
*/
|
|
50
|
+
module.exports.COULDNOTCONNECT = 1;
|
|
51
|
+
/**
|
|
52
|
+
* @type {2}
|
|
53
|
+
*/
|
|
12
54
|
module.exports.BADRESPONSE = 2;
|
|
55
|
+
/**
|
|
56
|
+
* @type {3}
|
|
57
|
+
*/
|
|
13
58
|
module.exports.AUTHFAILED = 3;
|
|
59
|
+
/**
|
|
60
|
+
* @type {4}
|
|
61
|
+
*/
|
|
14
62
|
module.exports.TIMEDOUT = 4;
|
|
63
|
+
/**
|
|
64
|
+
* @type {5}
|
|
65
|
+
*/
|
|
15
66
|
module.exports.ERROR = 5;
|
|
67
|
+
/**
|
|
68
|
+
* @type {6}
|
|
69
|
+
*/
|
|
16
70
|
module.exports.NOCONNECTION = 6;
|
|
71
|
+
/**
|
|
72
|
+
* @type {7}
|
|
73
|
+
*/
|
|
17
74
|
module.exports.AUTHNOTSUPPORTED = 7;
|
|
75
|
+
/**
|
|
76
|
+
* @type {8}
|
|
77
|
+
*/
|
|
18
78
|
module.exports.CONNECTIONCLOSED = 8;
|
|
79
|
+
/**
|
|
80
|
+
* @type {9}
|
|
81
|
+
*/
|
|
19
82
|
module.exports.CONNECTIONENDED = 9;
|
|
83
|
+
/**
|
|
84
|
+
* @type {10}
|
|
85
|
+
*/
|
|
20
86
|
module.exports.CONNECTIONAUTH = 10;
|