@flun/mailer 2.1.4

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 (42) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/LICENSE +15 -0
  3. package/Mail.js +47 -0
  4. package/README.md +475 -0
  5. package/copy-files.js +36 -0
  6. package/index.d.ts +816 -0
  7. package/index.js +109 -0
  8. package/lib/addressparser.js +230 -0
  9. package/lib/base64.js +103 -0
  10. package/lib/dkim/index.js +211 -0
  11. package/lib/dkim/message-parser.js +114 -0
  12. package/lib/dkim/relaxed-body.js +133 -0
  13. package/lib/dkim/sign.js +121 -0
  14. package/lib/fetch/cookies.js +224 -0
  15. package/lib/fetch/index.js +233 -0
  16. package/lib/http-proxy-client.js +98 -0
  17. package/lib/json-transport.js +38 -0
  18. package/lib/mail-composer.js +316 -0
  19. package/lib/mailer/index.js +301 -0
  20. package/lib/mailer/mail-message.js +226 -0
  21. package/lib/mime-funcs/index.js +493 -0
  22. package/lib/mime-funcs/mime-types.js +2061 -0
  23. package/lib/mime-node/index.js +811 -0
  24. package/lib/mime-node/last-newline.js +44 -0
  25. package/lib/mime-node/le-unix.js +37 -0
  26. package/lib/mime-node/le-windows.js +46 -0
  27. package/lib/punycode.js +283 -0
  28. package/lib/qp.js +171 -0
  29. package/lib/regexs.js +124 -0
  30. package/lib/sendmail-transport.js +91 -0
  31. package/lib/ses-transport.js +115 -0
  32. package/lib/shared.js +725 -0
  33. package/lib/smtp-connection/data-stream.js +68 -0
  34. package/lib/smtp-connection/index.js +1062 -0
  35. package/lib/smtp-pool/index.js +294 -0
  36. package/lib/smtp-pool/pool-resource.js +93 -0
  37. package/lib/smtp-transport.js +81 -0
  38. package/lib/stream-transport.js +59 -0
  39. package/lib/well-known/index.js +54 -0
  40. package/lib/well-known/services.json +802 -0
  41. package/lib/xoauth2.js +249 -0
  42. package/package.json +78 -0
@@ -0,0 +1,68 @@
1
+ import { Transform } from 'stream';
2
+
3
+ /**
4
+ * 转义行首的点,以`<CR><LF>.<CR><LF>`结束流
5
+ * 同时确保只使用`<CR><LF>`作为换行序列
6
+ * >查看定义:@see {@link DataStream}
7
+ * @param {Object} options 流选项
8
+ */
9
+ class DataStream extends Transform {
10
+ constructor(options = {}) {
11
+ super(options);
12
+ this.options = options, this._curLine = '', this.inByteCount = 0, this.outByteCount = 0, this.lastByte = false;
13
+ }
14
+
15
+ /**
16
+ * 转义点号的处理函数
17
+ */
18
+ _transform(chunk, encoding, done) {
19
+ if (typeof chunk === 'string') chunk = Buffer.from(chunk, encoding); // 如果chunk是字符串,则将其转换为Buffer
20
+ if (!chunk?.length) return done(); // 如果chunk为空则直接返回
21
+ const chunks = [];
22
+ let chunklen = 0, lastPos = 0, buf;
23
+
24
+ this.inByteCount += chunk.length;
25
+ // 遍历chunk中的每个字节
26
+ for (let i = 0; i < chunk.length; i++) {
27
+ if (chunk[i] === 0x2e) {
28
+ // 遇到点号(.),检查是否在行首,如果在,那么在行首的点号前额外添加一个点号进行转义
29
+ if ((i && chunk[i - 1] === 0x0a) || (!i && (!this.lastByte || this.lastByte === 0x0a))) {
30
+ buf = chunk.slice(lastPos, i + 1), chunks.push(buf), chunks.push(Buffer.from('.'));
31
+ chunklen += buf.length + 1, lastPos = i + 1;
32
+ }
33
+ }
34
+ else if (chunk[i] === 0x0a) {
35
+ // 遇到换行符(\n),检查前面是否有回车符(\r)
36
+ if ((i && chunk[i - 1] !== 0x0d) || (!i && this.lastByte !== 0x0d)) {
37
+ i > lastPos ? (buf = chunk.slice(lastPos, i), chunks.push(buf), chunklen += buf.length + 2) : chunklen += 2;
38
+ chunks.push(Buffer.from('\r\n')), lastPos = i + 1;
39
+ }
40
+ }
41
+ }
42
+
43
+ // 如果有处理过的数据块
44
+ if (chunklen) {
45
+ // 添加最后一段数据
46
+ if (lastPos < chunk.length) buf = chunk.slice(lastPos), chunks.push(buf), chunklen += buf.length;
47
+ this.outByteCount += chunklen, this.push(Buffer.concat(chunks, chunklen));
48
+ }
49
+ else this.outByteCount += chunk.length, this.push(chunk); // 没有需要转义的情况,直接推送原数据
50
+
51
+ this.lastByte = chunk.at(-1); done(); // 记录最后一个字节后,完成处理
52
+ }
53
+
54
+ /**
55
+ * 结束流处理,添加终止序列
56
+ */
57
+ _flush(done) {
58
+ let buf;
59
+ // 根据最后一个字节的类型添加适当的终止序列
60
+ if (this.lastByte === 0x0a) buf = Buffer.from('.\r\n'); // 如果最后是LF,直接添加点号和CRLF
61
+ else if (this.lastByte === 0x0d) buf = Buffer.from('\n.\r\n'); // 如果最后是CR,添加LF、点号和CRLF
62
+ else buf = Buffer.from('\r\n.\r\n'); // 其他情况,添加完整的CRLF、点号和CRLF
63
+
64
+ this.outByteCount += buf.length, this.push(buf), done();
65
+ }
66
+ }
67
+
68
+ export { DataStream };