@mavogel/awscdk-rootmail 0.1.26 → 0.1.28

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 (175) hide show
  1. package/.jsii +8 -8
  2. package/lib/rootmail.js +1 -1
  3. package/lib/ses-receive.js +1 -1
  4. package/node_modules/@aws-sdk/checksums/package.json +4 -4
  5. package/node_modules/@aws-sdk/client-cloudwatch-logs/dist-cjs/index.js +1 -1
  6. package/node_modules/@aws-sdk/client-cloudwatch-logs/dist-types/CloudWatchLogsClient.d.ts +2 -1
  7. package/node_modules/@aws-sdk/client-cloudwatch-logs/package.json +5 -5
  8. package/node_modules/@aws-sdk/client-route-53/dist-cjs/index.js +1 -1
  9. package/node_modules/@aws-sdk/client-route-53/dist-types/Route53Client.d.ts +2 -1
  10. package/node_modules/@aws-sdk/client-route-53/package.json +6 -6
  11. package/node_modules/@aws-sdk/client-s3/dist-cjs/index.js +1 -1
  12. package/node_modules/@aws-sdk/client-s3/dist-types/S3Client.d.ts +2 -1
  13. package/node_modules/@aws-sdk/client-s3/package.json +9 -9
  14. package/node_modules/@aws-sdk/client-ses/dist-cjs/index.js +1 -1
  15. package/node_modules/@aws-sdk/client-ses/dist-types/SESClient.d.ts +2 -1
  16. package/node_modules/@aws-sdk/client-ses/package.json +5 -5
  17. package/node_modules/@aws-sdk/client-ssm/dist-cjs/index.js +1 -1
  18. package/node_modules/@aws-sdk/client-ssm/dist-types/SSMClient.d.ts +2 -1
  19. package/node_modules/@aws-sdk/client-ssm/package.json +5 -5
  20. package/node_modules/@aws-sdk/core/package.json +3 -3
  21. package/node_modules/@aws-sdk/credential-provider-env/package.json +4 -4
  22. package/node_modules/@aws-sdk/credential-provider-http/package.json +4 -4
  23. package/node_modules/@aws-sdk/credential-provider-ini/package.json +11 -11
  24. package/node_modules/@aws-sdk/credential-provider-login/package.json +5 -5
  25. package/node_modules/@aws-sdk/credential-provider-node/package.json +9 -9
  26. package/node_modules/@aws-sdk/credential-provider-process/package.json +4 -4
  27. package/node_modules/@aws-sdk/credential-provider-sso/package.json +6 -6
  28. package/node_modules/@aws-sdk/credential-provider-web-identity/package.json +5 -5
  29. package/node_modules/@aws-sdk/middleware-sdk-route53/package.json +2 -2
  30. package/node_modules/@aws-sdk/middleware-sdk-s3/package.json +5 -5
  31. package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/cognito-identity/index.js +1 -1
  32. package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/signin/index.js +1 -1
  33. package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/sso/index.js +1 -1
  34. package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/sso-oidc/index.js +1 -1
  35. package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/sts/index.js +1 -1
  36. package/node_modules/@aws-sdk/nested-clients/dist-types/submodules/cognito-identity/CognitoIdentityClient.d.ts +2 -1
  37. package/node_modules/@aws-sdk/nested-clients/dist-types/submodules/signin/SigninClient.d.ts +2 -1
  38. package/node_modules/@aws-sdk/nested-clients/dist-types/submodules/sso/SSOClient.d.ts +2 -1
  39. package/node_modules/@aws-sdk/nested-clients/dist-types/submodules/sso-oidc/SSOOIDCClient.d.ts +2 -1
  40. package/node_modules/@aws-sdk/nested-clients/dist-types/submodules/sts/STSClient.d.ts +2 -1
  41. package/node_modules/@aws-sdk/nested-clients/package.json +5 -5
  42. package/node_modules/@aws-sdk/signature-v4-multi-region/package.json +2 -2
  43. package/node_modules/@aws-sdk/token-providers/package.json +5 -5
  44. package/node_modules/@aws-sdk/types/dist-types/feature-ids.d.ts +3 -0
  45. package/node_modules/@aws-sdk/types/dist-types/ts3.4/feature-ids.d.ts +3 -0
  46. package/node_modules/@aws-sdk/types/package.json +1 -1
  47. package/node_modules/@smithy/core/dist-cjs/submodules/client/index.js +15 -2
  48. package/node_modules/@smithy/core/dist-cjs/submodules/event-streams/index.browser.js +10 -0
  49. package/node_modules/@smithy/core/dist-cjs/submodules/event-streams/index.js +10 -0
  50. package/node_modules/@smithy/core/dist-cjs/submodules/protocols/index.js +5 -5
  51. package/node_modules/@smithy/core/dist-es/submodules/client/smithy-client/command.js +16 -2
  52. package/node_modules/@smithy/core/dist-es/submodules/event-streams/eventstream-codec/HeaderMarshaller.js +10 -0
  53. package/node_modules/@smithy/core/dist-es/submodules/protocols/json/codec-v2/JsonShapeSerializer2.js +5 -5
  54. package/node_modules/@smithy/core/package.json +1 -1
  55. package/node_modules/@zone-eu/mailsplit/lib/message-splitter.js +39 -27
  56. package/node_modules/@zone-eu/mailsplit/lib/mime-node.d.ts +1 -1
  57. package/node_modules/@zone-eu/mailsplit/lib/mime-node.js +38 -61
  58. package/node_modules/@zone-eu/mailsplit/lib/types.d.ts +1 -1
  59. package/node_modules/@zone-eu/mailsplit/package.json +2 -2
  60. package/node_modules/libmime/CHANGELOG.md +36 -0
  61. package/node_modules/libmime/README.md +40 -3
  62. package/node_modules/libmime/dist/cjs/charset.d.ts +36 -0
  63. package/node_modules/libmime/dist/cjs/charset.js +165 -2
  64. package/node_modules/libmime/dist/cjs/charsets.js +8 -2
  65. package/node_modules/libmime/dist/cjs/libmime.d.ts +20 -3
  66. package/node_modules/libmime/dist/cjs/libmime.js +100 -6
  67. package/node_modules/libmime/dist/cjs/types.d.ts +28 -0
  68. package/node_modules/libmime/dist/esm/charset.d.ts +36 -0
  69. package/node_modules/libmime/dist/esm/charset.js +162 -2
  70. package/node_modules/libmime/dist/esm/charsets.js +8 -2
  71. package/node_modules/libmime/dist/esm/libmime.d.ts +20 -3
  72. package/node_modules/libmime/dist/esm/libmime.js +100 -6
  73. package/node_modules/libmime/dist/esm/types.d.ts +28 -0
  74. package/node_modules/libmime/package.json +3 -3
  75. package/node_modules/mailparser/CHANGELOG.md +51 -0
  76. package/node_modules/mailparser/README.md +32 -1
  77. package/node_modules/mailparser/dist/cjs/address-header.d.ts +19 -0
  78. package/node_modules/mailparser/dist/cjs/address-header.js +185 -0
  79. package/node_modules/mailparser/dist/cjs/index.d.ts +3 -1
  80. package/node_modules/mailparser/dist/cjs/index.js +4 -2
  81. package/node_modules/mailparser/dist/cjs/mail-parser.js +36 -183
  82. package/node_modules/mailparser/dist/cjs/stream-hash.d.ts +5 -4
  83. package/node_modules/mailparser/dist/cjs/stream-hash.js +8 -5
  84. package/node_modules/mailparser/dist/cjs/types.d.ts +33 -6
  85. package/node_modules/mailparser/dist/esm/address-header.d.ts +19 -0
  86. package/node_modules/mailparser/dist/esm/address-header.js +176 -0
  87. package/node_modules/mailparser/dist/esm/index.d.ts +3 -1
  88. package/node_modules/mailparser/dist/esm/index.js +3 -2
  89. package/node_modules/mailparser/dist/esm/mail-parser.js +36 -183
  90. package/node_modules/mailparser/dist/esm/stream-hash.d.ts +5 -4
  91. package/node_modules/mailparser/dist/esm/stream-hash.js +8 -5
  92. package/node_modules/mailparser/dist/esm/types.d.ts +33 -6
  93. package/node_modules/mailparser/package.json +6 -7
  94. package/node_modules/nodemailer/CHANGELOG.md +23 -0
  95. package/node_modules/nodemailer/dist/cjs/addressparser/index.js +2 -5
  96. package/node_modules/nodemailer/dist/cjs/dkim/index.js +1 -3
  97. package/node_modules/nodemailer/dist/cjs/errors.d.ts +19 -0
  98. package/node_modules/nodemailer/dist/cjs/errors.js +14 -1
  99. package/node_modules/nodemailer/dist/cjs/fetch/cookies.js +2 -4
  100. package/node_modules/nodemailer/dist/cjs/fetch/index.js +2 -8
  101. package/node_modules/nodemailer/dist/cjs/mail-composer/index.js +42 -9
  102. package/node_modules/nodemailer/dist/cjs/mailer/mail-message.js +5 -6
  103. package/node_modules/nodemailer/dist/cjs/mime-funcs/index.d.ts +18 -1
  104. package/node_modules/nodemailer/dist/cjs/mime-funcs/index.js +43 -1
  105. package/node_modules/nodemailer/dist/cjs/mime-funcs/mime-types.js +3 -12
  106. package/node_modules/nodemailer/dist/cjs/mime-node/index.d.ts +34 -1
  107. package/node_modules/nodemailer/dist/cjs/mime-node/index.js +40 -15
  108. package/node_modules/nodemailer/dist/cjs/package-info.d.ts +1 -1
  109. package/node_modules/nodemailer/dist/cjs/package-info.js +1 -1
  110. package/node_modules/nodemailer/dist/cjs/qp/index.js +3 -12
  111. package/node_modules/nodemailer/dist/cjs/sendmail-transport/index.js +1 -3
  112. package/node_modules/nodemailer/dist/cjs/shared/index.js +2 -6
  113. package/node_modules/nodemailer/dist/cjs/smtp-connection/http-proxy-client.js +1 -1
  114. package/node_modules/nodemailer/dist/cjs/smtp-connection/index.d.ts +6 -0
  115. package/node_modules/nodemailer/dist/cjs/smtp-connection/index.js +15 -12
  116. package/node_modules/nodemailer/dist/cjs/smtp-connection/server-message-id.d.ts +14 -0
  117. package/node_modules/nodemailer/dist/cjs/smtp-connection/server-message-id.js +53 -0
  118. package/node_modules/nodemailer/dist/cjs/smtp-pool/index.d.ts +11 -0
  119. package/node_modules/nodemailer/dist/cjs/smtp-pool/index.js +25 -1
  120. package/node_modules/nodemailer/dist/cjs/smtp-pool/pool-resource.js +2 -5
  121. package/node_modules/nodemailer/dist/esm/addressparser/index.js +2 -5
  122. package/node_modules/nodemailer/dist/esm/dkim/index.js +1 -3
  123. package/node_modules/nodemailer/dist/esm/errors.d.ts +19 -0
  124. package/node_modules/nodemailer/dist/esm/errors.js +12 -0
  125. package/node_modules/nodemailer/dist/esm/fetch/cookies.js +2 -4
  126. package/node_modules/nodemailer/dist/esm/fetch/index.js +2 -8
  127. package/node_modules/nodemailer/dist/esm/mail-composer/index.js +42 -9
  128. package/node_modules/nodemailer/dist/esm/mailer/mail-message.js +5 -6
  129. package/node_modules/nodemailer/dist/esm/mime-funcs/index.d.ts +18 -1
  130. package/node_modules/nodemailer/dist/esm/mime-funcs/index.js +43 -1
  131. package/node_modules/nodemailer/dist/esm/mime-funcs/mime-types.js +3 -12
  132. package/node_modules/nodemailer/dist/esm/mime-node/index.d.ts +34 -1
  133. package/node_modules/nodemailer/dist/esm/mime-node/index.js +40 -15
  134. package/node_modules/nodemailer/dist/esm/package-info.d.ts +1 -1
  135. package/node_modules/nodemailer/dist/esm/package-info.js +1 -1
  136. package/node_modules/nodemailer/dist/esm/qp/index.js +3 -12
  137. package/node_modules/nodemailer/dist/esm/sendmail-transport/index.js +1 -3
  138. package/node_modules/nodemailer/dist/esm/shared/index.js +2 -6
  139. package/node_modules/nodemailer/dist/esm/smtp-connection/http-proxy-client.js +1 -1
  140. package/node_modules/nodemailer/dist/esm/smtp-connection/index.d.ts +6 -0
  141. package/node_modules/nodemailer/dist/esm/smtp-connection/index.js +16 -13
  142. package/node_modules/nodemailer/dist/esm/smtp-connection/server-message-id.d.ts +14 -0
  143. package/node_modules/nodemailer/dist/esm/smtp-connection/server-message-id.js +50 -0
  144. package/node_modules/nodemailer/dist/esm/smtp-pool/index.d.ts +11 -0
  145. package/node_modules/nodemailer/dist/esm/smtp-pool/index.js +25 -1
  146. package/node_modules/nodemailer/dist/esm/smtp-pool/pool-resource.js +2 -5
  147. package/node_modules/nodemailer/package.json +11 -9
  148. package/package.json +9 -9
  149. package/node_modules/mailparser/node_modules/iconv-lite/LICENSE +0 -21
  150. package/node_modules/mailparser/node_modules/iconv-lite/README.md +0 -138
  151. package/node_modules/mailparser/node_modules/iconv-lite/encodings/dbcs-codec.js +0 -532
  152. package/node_modules/mailparser/node_modules/iconv-lite/encodings/dbcs-data.js +0 -185
  153. package/node_modules/mailparser/node_modules/iconv-lite/encodings/index.js +0 -23
  154. package/node_modules/mailparser/node_modules/iconv-lite/encodings/internal.js +0 -218
  155. package/node_modules/mailparser/node_modules/iconv-lite/encodings/sbcs-codec.js +0 -75
  156. package/node_modules/mailparser/node_modules/iconv-lite/encodings/sbcs-data-generated.js +0 -451
  157. package/node_modules/mailparser/node_modules/iconv-lite/encodings/sbcs-data.js +0 -180
  158. package/node_modules/mailparser/node_modules/iconv-lite/encodings/tables/big5-added.json +0 -122
  159. package/node_modules/mailparser/node_modules/iconv-lite/encodings/tables/cp936.json +0 -264
  160. package/node_modules/mailparser/node_modules/iconv-lite/encodings/tables/cp949.json +0 -273
  161. package/node_modules/mailparser/node_modules/iconv-lite/encodings/tables/cp950.json +0 -177
  162. package/node_modules/mailparser/node_modules/iconv-lite/encodings/tables/eucjp.json +0 -182
  163. package/node_modules/mailparser/node_modules/iconv-lite/encodings/tables/gb18030-ranges.json +0 -1
  164. package/node_modules/mailparser/node_modules/iconv-lite/encodings/tables/gbk-added.json +0 -56
  165. package/node_modules/mailparser/node_modules/iconv-lite/encodings/tables/shiftjis.json +0 -125
  166. package/node_modules/mailparser/node_modules/iconv-lite/encodings/utf16.js +0 -187
  167. package/node_modules/mailparser/node_modules/iconv-lite/encodings/utf32.js +0 -314
  168. package/node_modules/mailparser/node_modules/iconv-lite/encodings/utf7.js +0 -283
  169. package/node_modules/mailparser/node_modules/iconv-lite/lib/bom-handling.js +0 -48
  170. package/node_modules/mailparser/node_modules/iconv-lite/lib/helpers/merge-exports.js +0 -13
  171. package/node_modules/mailparser/node_modules/iconv-lite/lib/index.d.ts +0 -129
  172. package/node_modules/mailparser/node_modules/iconv-lite/lib/index.js +0 -182
  173. package/node_modules/mailparser/node_modules/iconv-lite/lib/streams.js +0 -105
  174. package/node_modules/mailparser/node_modules/iconv-lite/package.json +0 -70
  175. package/node_modules/mailparser/node_modules/iconv-lite/types/encodings.d.ts +0 -425
@@ -1,187 +0,0 @@
1
- "use strict"
2
- var Buffer = require("safer-buffer").Buffer
3
-
4
- // Note: UTF16-LE (or UCS2) codec is Node.js native. See encodings/internal.js
5
-
6
- // == UTF16-BE codec. ==========================================================
7
-
8
- exports.utf16be = Utf16BECodec
9
- function Utf16BECodec () {
10
- }
11
-
12
- Utf16BECodec.prototype.encoder = Utf16BEEncoder
13
- Utf16BECodec.prototype.decoder = Utf16BEDecoder
14
- Utf16BECodec.prototype.bomAware = true
15
-
16
- // -- Encoding
17
-
18
- function Utf16BEEncoder () {
19
- }
20
-
21
- Utf16BEEncoder.prototype.write = function (str) {
22
- var buf = Buffer.from(str, "ucs2")
23
- for (var i = 0; i < buf.length; i += 2) {
24
- var tmp = buf[i]; buf[i] = buf[i + 1]; buf[i + 1] = tmp
25
- }
26
- return buf
27
- }
28
-
29
- Utf16BEEncoder.prototype.end = function () {
30
- }
31
-
32
- // -- Decoding
33
-
34
- function Utf16BEDecoder () {
35
- this.overflowByte = -1
36
- }
37
-
38
- Utf16BEDecoder.prototype.write = function (buf) {
39
- if (buf.length == 0) { return "" }
40
-
41
- var buf2 = Buffer.alloc(buf.length + 1)
42
- var i = 0; var j = 0
43
-
44
- if (this.overflowByte !== -1) {
45
- buf2[0] = buf[0]
46
- buf2[1] = this.overflowByte
47
- i = 1; j = 2
48
- }
49
-
50
- for (; i < buf.length - 1; i += 2, j += 2) {
51
- buf2[j] = buf[i + 1]
52
- buf2[j + 1] = buf[i]
53
- }
54
-
55
- this.overflowByte = (i == buf.length - 1) ? buf[buf.length - 1] : -1
56
-
57
- return buf2.slice(0, j).toString("ucs2")
58
- }
59
-
60
- Utf16BEDecoder.prototype.end = function () {
61
- this.overflowByte = -1
62
- }
63
-
64
- // == UTF-16 codec =============================================================
65
- // Decoder chooses automatically from UTF-16LE and UTF-16BE using BOM and space-based heuristic.
66
- // Defaults to UTF-16LE, as it's prevalent and default in Node.
67
- // http://en.wikipedia.org/wiki/UTF-16 and http://encoding.spec.whatwg.org/#utf-16le
68
- // Decoder default can be changed: iconv.decode(buf, 'utf16', {defaultEncoding: 'utf-16be'});
69
-
70
- // Encoder uses UTF-16LE and prepends BOM (which can be overridden with addBOM: false).
71
-
72
- exports.utf16 = Utf16Codec
73
- function Utf16Codec (codecOptions, iconv) {
74
- this.iconv = iconv
75
- }
76
-
77
- Utf16Codec.prototype.encoder = Utf16Encoder
78
- Utf16Codec.prototype.decoder = Utf16Decoder
79
-
80
- // -- Encoding (pass-through)
81
-
82
- function Utf16Encoder (options, codec) {
83
- options = options || {}
84
- if (options.addBOM === undefined) { options.addBOM = true }
85
- this.encoder = codec.iconv.getEncoder("utf-16le", options)
86
- }
87
-
88
- Utf16Encoder.prototype.write = function (str) {
89
- return this.encoder.write(str)
90
- }
91
-
92
- Utf16Encoder.prototype.end = function () {
93
- return this.encoder.end()
94
- }
95
-
96
- // -- Decoding
97
-
98
- function Utf16Decoder (options, codec) {
99
- this.decoder = null
100
- this.initialBufs = []
101
- this.initialBufsLen = 0
102
-
103
- this.options = options || {}
104
- this.iconv = codec.iconv
105
- }
106
-
107
- Utf16Decoder.prototype.write = function (buf) {
108
- if (!this.decoder) {
109
- // Codec is not chosen yet. Accumulate initial bytes.
110
- this.initialBufs.push(buf)
111
- this.initialBufsLen += buf.length
112
-
113
- if (this.initialBufsLen < 16) // We need more bytes to use space heuristic (see below)
114
- { return "" }
115
-
116
- // We have enough bytes -> detect endianness.
117
- var encoding = detectEncoding(this.initialBufs, this.options.defaultEncoding)
118
- this.decoder = this.iconv.getDecoder(encoding, this.options)
119
-
120
- var resStr = ""
121
- for (var i = 0; i < this.initialBufs.length; i++) { resStr += this.decoder.write(this.initialBufs[i]) }
122
-
123
- this.initialBufs.length = this.initialBufsLen = 0
124
- return resStr
125
- }
126
-
127
- return this.decoder.write(buf)
128
- }
129
-
130
- Utf16Decoder.prototype.end = function () {
131
- if (!this.decoder) {
132
- var encoding = detectEncoding(this.initialBufs, this.options.defaultEncoding)
133
- this.decoder = this.iconv.getDecoder(encoding, this.options)
134
-
135
- var resStr = ""
136
- for (var i = 0; i < this.initialBufs.length; i++) { resStr += this.decoder.write(this.initialBufs[i]) }
137
-
138
- var trail = this.decoder.end()
139
- if (trail) { resStr += trail }
140
-
141
- this.initialBufs.length = this.initialBufsLen = 0
142
- return resStr
143
- }
144
- return this.decoder.end()
145
- }
146
-
147
- function detectEncoding (bufs, defaultEncoding) {
148
- var b = []
149
- var charsProcessed = 0
150
- // Number of ASCII chars when decoded as LE or BE.
151
- var asciiCharsLE = 0
152
- var asciiCharsBE = 0
153
-
154
- outerLoop:
155
- for (var i = 0; i < bufs.length; i++) {
156
- var buf = bufs[i]
157
- for (var j = 0; j < buf.length; j++) {
158
- b.push(buf[j])
159
- if (b.length === 2) {
160
- if (charsProcessed === 0) {
161
- // Check BOM first.
162
- if (b[0] === 0xFF && b[1] === 0xFE) return "utf-16le"
163
- if (b[0] === 0xFE && b[1] === 0xFF) return "utf-16be"
164
- }
165
-
166
- if (b[0] === 0 && b[1] !== 0) asciiCharsBE++
167
- if (b[0] !== 0 && b[1] === 0) asciiCharsLE++
168
-
169
- b.length = 0
170
- charsProcessed++
171
-
172
- if (charsProcessed >= 100) {
173
- break outerLoop
174
- }
175
- }
176
- }
177
- }
178
-
179
- // Make decisions.
180
- // Most of the time, the content has ASCII chars (U+00**), but the opposite (U+**00) is uncommon.
181
- // So, we count ASCII as if it was LE or BE, and decide from that.
182
- if (asciiCharsBE > asciiCharsLE) return "utf-16be"
183
- if (asciiCharsBE < asciiCharsLE) return "utf-16le"
184
-
185
- // Couldn't decide (likely all zeros or not enough data).
186
- return defaultEncoding || "utf-16le"
187
- }
@@ -1,314 +0,0 @@
1
- "use strict"
2
-
3
- var Buffer = require("safer-buffer").Buffer
4
-
5
- // == UTF32-LE/BE codec. ==========================================================
6
-
7
- exports._utf32 = Utf32Codec
8
-
9
- function Utf32Codec (codecOptions, iconv) {
10
- this.iconv = iconv
11
- this.bomAware = true
12
- this.isLE = codecOptions.isLE
13
- }
14
-
15
- exports.utf32le = { type: "_utf32", isLE: true }
16
- exports.utf32be = { type: "_utf32", isLE: false }
17
-
18
- // Aliases
19
- exports.ucs4le = "utf32le"
20
- exports.ucs4be = "utf32be"
21
-
22
- Utf32Codec.prototype.encoder = Utf32Encoder
23
- Utf32Codec.prototype.decoder = Utf32Decoder
24
-
25
- // -- Encoding
26
-
27
- function Utf32Encoder (options, codec) {
28
- this.isLE = codec.isLE
29
- this.highSurrogate = 0
30
- }
31
-
32
- Utf32Encoder.prototype.write = function (str) {
33
- var src = Buffer.from(str, "ucs2")
34
- // src.length * 2 covers this chunk's code units (4 bytes each); the extra 4 bytes leave room for a
35
- // high surrogate held over from a previous chunk, which is flushed ahead of this chunk's units.
36
- var dst = Buffer.alloc(src.length * 2 + 4)
37
- var write32 = this.isLE ? dst.writeUInt32LE : dst.writeUInt32BE
38
- var offset = 0
39
-
40
- for (var i = 0; i < src.length; i += 2) {
41
- var code = src.readUInt16LE(i)
42
- var isHighSurrogate = (code >= 0xD800 && code < 0xDC00)
43
- var isLowSurrogate = (code >= 0xDC00 && code < 0xE000)
44
-
45
- if (this.highSurrogate) {
46
- if (isHighSurrogate || !isLowSurrogate) {
47
- // There shouldn't be two high surrogates in a row, nor a high surrogate which isn't followed by a low
48
- // surrogate. If this happens, keep the pending high surrogate as a stand-alone semi-invalid character
49
- // (technically wrong, but expected by some applications, like Windows file names).
50
- write32.call(dst, this.highSurrogate, offset)
51
- offset += 4
52
- } else {
53
- // Create 32-bit value from high and low surrogates;
54
- var codepoint = (((this.highSurrogate - 0xD800) << 10) | (code - 0xDC00)) + 0x10000
55
-
56
- write32.call(dst, codepoint, offset)
57
- offset += 4
58
- this.highSurrogate = 0
59
-
60
- continue
61
- }
62
- }
63
-
64
- if (isHighSurrogate) { this.highSurrogate = code } else {
65
- // Even if the current character is a low surrogate, with no previous high surrogate, we'll
66
- // encode it as a semi-invalid stand-alone character for the same reasons expressed above for
67
- // unpaired high surrogates.
68
- write32.call(dst, code, offset)
69
- offset += 4
70
- this.highSurrogate = 0
71
- }
72
- }
73
-
74
- if (offset < dst.length) { dst = dst.slice(0, offset) }
75
-
76
- return dst
77
- }
78
-
79
- Utf32Encoder.prototype.end = function () {
80
- // Treat any leftover high surrogate as a semi-valid independent character.
81
- if (!this.highSurrogate) { return }
82
-
83
- var buf = Buffer.alloc(4)
84
-
85
- if (this.isLE) { buf.writeUInt32LE(this.highSurrogate, 0) } else { buf.writeUInt32BE(this.highSurrogate, 0) }
86
-
87
- this.highSurrogate = 0
88
-
89
- return buf
90
- }
91
-
92
- // -- Decoding
93
-
94
- function Utf32Decoder (options, codec) {
95
- this.isLE = codec.isLE
96
- this.badChar = codec.iconv.defaultCharUnicode.charCodeAt(0)
97
- this.overflow = []
98
- }
99
-
100
- Utf32Decoder.prototype.write = function (src) {
101
- if (src.length === 0) { return "" }
102
-
103
- var i = 0
104
- var codepoint = 0
105
- var dst = Buffer.alloc(src.length + 4)
106
- var offset = 0
107
- var isLE = this.isLE
108
- var overflow = this.overflow
109
- var badChar = this.badChar
110
-
111
- if (overflow.length > 0) {
112
- for (; i < src.length && overflow.length < 4; i++) { overflow.push(src[i]) }
113
-
114
- if (overflow.length === 4) {
115
- // NOTE: codepoint is a signed int32 and can be negative.
116
- // NOTE: We copied this block from below to help V8 optimize it (it works with array, not buffer).
117
- if (isLE) {
118
- codepoint = overflow[0] | (overflow[1] << 8) | (overflow[2] << 16) | (overflow[3] << 24)
119
- } else {
120
- codepoint = overflow[3] | (overflow[2] << 8) | (overflow[1] << 16) | (overflow[0] << 24)
121
- }
122
- overflow.length = 0
123
-
124
- offset = _writeCodepoint(dst, offset, codepoint, badChar)
125
- }
126
- }
127
-
128
- // Main loop. Should be as optimized as possible.
129
- for (; i < src.length - 3; i += 4) {
130
- // NOTE: codepoint is a signed int32 and can be negative.
131
- if (isLE) {
132
- codepoint = src[i] | (src[i + 1] << 8) | (src[i + 2] << 16) | (src[i + 3] << 24)
133
- } else {
134
- codepoint = src[i + 3] | (src[i + 2] << 8) | (src[i + 1] << 16) | (src[i] << 24)
135
- }
136
- offset = _writeCodepoint(dst, offset, codepoint, badChar)
137
- }
138
-
139
- // Keep overflowing bytes.
140
- for (; i < src.length; i++) {
141
- overflow.push(src[i])
142
- }
143
-
144
- return dst.slice(0, offset).toString("ucs2")
145
- }
146
-
147
- function _writeCodepoint (dst, offset, codepoint, badChar) {
148
- // NOTE: codepoint is signed int32 and can be negative. We keep it that way to help V8 with optimizations.
149
- if (codepoint < 0 || codepoint > 0x10FFFF) {
150
- // Not a valid Unicode codepoint
151
- codepoint = badChar
152
- }
153
-
154
- // Ephemeral Planes: Write high surrogate.
155
- if (codepoint >= 0x10000) {
156
- codepoint -= 0x10000
157
-
158
- var high = 0xD800 | (codepoint >> 10)
159
- dst[offset++] = high & 0xff
160
- dst[offset++] = high >> 8
161
-
162
- // Low surrogate is written below.
163
- var codepoint = 0xDC00 | (codepoint & 0x3FF)
164
- }
165
-
166
- // Write BMP char or low surrogate.
167
- dst[offset++] = codepoint & 0xff
168
- dst[offset++] = codepoint >> 8
169
-
170
- return offset
171
- };
172
-
173
- Utf32Decoder.prototype.end = function () {
174
- if (this.overflow.length === 0) { return }
175
-
176
- // A leftover, incomplete 4-byte code unit at the end of the input is ill-formed. Substitute a
177
- // single U+FFFD (Unicode Standard conformance clause C10) instead of silently dropping the bytes.
178
- this.overflow.length = 0
179
- return String.fromCharCode(this.badChar)
180
- }
181
-
182
- // == UTF-32 Auto codec =============================================================
183
- // Decoder chooses automatically from UTF-32LE and UTF-32BE using BOM and space-based heuristic.
184
- // Defaults to UTF-32LE. http://en.wikipedia.org/wiki/UTF-32
185
- // Encoder/decoder default can be changed: iconv.decode(buf, 'utf32', {defaultEncoding: 'utf-32be'});
186
-
187
- // Encoder prepends BOM (which can be overridden with (addBOM: false}).
188
-
189
- exports.utf32 = Utf32AutoCodec
190
- exports.ucs4 = "utf32"
191
-
192
- function Utf32AutoCodec (options, iconv) {
193
- this.iconv = iconv
194
- }
195
-
196
- Utf32AutoCodec.prototype.encoder = Utf32AutoEncoder
197
- Utf32AutoCodec.prototype.decoder = Utf32AutoDecoder
198
-
199
- // -- Encoding
200
-
201
- function Utf32AutoEncoder (options, codec) {
202
- options = options || {}
203
-
204
- if (options.addBOM === undefined) {
205
- options.addBOM = true
206
- }
207
-
208
- this.encoder = codec.iconv.getEncoder(options.defaultEncoding || "utf-32le", options)
209
- }
210
-
211
- Utf32AutoEncoder.prototype.write = function (str) {
212
- return this.encoder.write(str)
213
- }
214
-
215
- Utf32AutoEncoder.prototype.end = function () {
216
- return this.encoder.end()
217
- }
218
-
219
- // -- Decoding
220
-
221
- function Utf32AutoDecoder (options, codec) {
222
- this.decoder = null
223
- this.initialBufs = []
224
- this.initialBufsLen = 0
225
- this.options = options || {}
226
- this.iconv = codec.iconv
227
- }
228
-
229
- Utf32AutoDecoder.prototype.write = function (buf) {
230
- if (!this.decoder) {
231
- // Codec is not chosen yet. Accumulate initial bytes.
232
- this.initialBufs.push(buf)
233
- this.initialBufsLen += buf.length
234
-
235
- if (this.initialBufsLen < 32) // We need more bytes to use space heuristic (see below)
236
- { return "" }
237
-
238
- // We have enough bytes -> detect endianness.
239
- var encoding = detectEncoding(this.initialBufs, this.options.defaultEncoding)
240
- this.decoder = this.iconv.getDecoder(encoding, this.options)
241
-
242
- var resStr = ""
243
- for (var i = 0; i < this.initialBufs.length; i++) { resStr += this.decoder.write(this.initialBufs[i]) }
244
-
245
- this.initialBufs.length = this.initialBufsLen = 0
246
- return resStr
247
- }
248
-
249
- return this.decoder.write(buf)
250
- }
251
-
252
- Utf32AutoDecoder.prototype.end = function () {
253
- if (!this.decoder) {
254
- var encoding = detectEncoding(this.initialBufs, this.options.defaultEncoding)
255
- this.decoder = this.iconv.getDecoder(encoding, this.options)
256
-
257
- var resStr = ""
258
- for (var i = 0; i < this.initialBufs.length; i++) { resStr += this.decoder.write(this.initialBufs[i]) }
259
-
260
- var trail = this.decoder.end()
261
- if (trail) { resStr += trail }
262
-
263
- this.initialBufs.length = this.initialBufsLen = 0
264
- return resStr
265
- }
266
-
267
- return this.decoder.end()
268
- }
269
-
270
- function detectEncoding (bufs, defaultEncoding) {
271
- var b = []
272
- var charsProcessed = 0
273
- var invalidLE = 0; var invalidBE = 0 // Number of invalid chars when decoded as LE or BE.
274
- var bmpCharsLE = 0; var bmpCharsBE = 0 // Number of BMP chars when decoded as LE or BE.
275
-
276
- outerLoop:
277
- for (var i = 0; i < bufs.length; i++) {
278
- var buf = bufs[i]
279
- for (var j = 0; j < buf.length; j++) {
280
- b.push(buf[j])
281
- if (b.length === 4) {
282
- if (charsProcessed === 0) {
283
- // Check BOM first.
284
- if (b[0] === 0xFF && b[1] === 0xFE && b[2] === 0 && b[3] === 0) {
285
- return "utf-32le"
286
- }
287
- if (b[0] === 0 && b[1] === 0 && b[2] === 0xFE && b[3] === 0xFF) {
288
- return "utf-32be"
289
- }
290
- }
291
-
292
- if (b[0] !== 0 || b[1] > 0x10) invalidBE++
293
- if (b[3] !== 0 || b[2] > 0x10) invalidLE++
294
-
295
- if (b[0] === 0 && b[1] === 0 && (b[2] !== 0 || b[3] !== 0)) bmpCharsBE++
296
- if ((b[0] !== 0 || b[1] !== 0) && b[2] === 0 && b[3] === 0) bmpCharsLE++
297
-
298
- b.length = 0
299
- charsProcessed++
300
-
301
- if (charsProcessed >= 100) {
302
- break outerLoop
303
- }
304
- }
305
- }
306
- }
307
-
308
- // Make decisions.
309
- if (bmpCharsBE - invalidBE > bmpCharsLE - invalidLE) return "utf-32be"
310
- if (bmpCharsBE - invalidBE < bmpCharsLE - invalidLE) return "utf-32le"
311
-
312
- // Couldn't decide (likely all zeros or not enough data).
313
- return defaultEncoding || "utf-32le"
314
- }