@social-mail/shared 1.0.16 → 1.0.22

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 (58) hide show
  1. package/.gitlab-ci.yml +2 -2
  2. package/dist/QueryIterator.d.ts +2 -2
  3. package/dist/QueryIterator.d.ts.map +1 -1
  4. package/dist/QueryIterator.js +21 -20
  5. package/dist/QueryIterator.js.map +1 -1
  6. package/dist/ical-parser/Calender.d.ts +0 -1
  7. package/dist/ical-parser/Calender.d.ts.map +1 -1
  8. package/dist/ical-parser/Calender.js +136 -151
  9. package/dist/ical-parser/Calender.js.map +1 -1
  10. package/dist/ical-parser/parseDate.js +25 -32
  11. package/dist/ical-parser/parseDate.js.map +1 -1
  12. package/dist/index.d.ts +32 -5
  13. package/dist/mime-parser/AttachmentFile.d.ts +1 -1
  14. package/dist/mime-parser/AttachmentFile.d.ts.map +1 -1
  15. package/dist/mime-parser/AttachmentFile.js +11 -19
  16. package/dist/mime-parser/AttachmentFile.js.map +1 -1
  17. package/dist/mime-parser/HeaderContentDisposition.js +20 -30
  18. package/dist/mime-parser/HeaderContentDisposition.js.map +1 -1
  19. package/dist/mime-parser/HeaderContentType.js +20 -29
  20. package/dist/mime-parser/HeaderContentType.js.map +1 -1
  21. package/dist/mime-parser/MimeMessage.d.ts +4 -4
  22. package/dist/mime-parser/MimeMessage.d.ts.map +1 -1
  23. package/dist/mime-parser/MimeMessage.js +83 -82
  24. package/dist/mime-parser/MimeMessage.js.map +1 -1
  25. package/dist/mime-parser/MimeNode.d.ts +4 -4
  26. package/dist/mime-parser/MimeNode.d.ts.map +1 -1
  27. package/dist/mime-parser/MimeNode.js +357 -339
  28. package/dist/mime-parser/MimeNode.js.map +1 -1
  29. package/dist/mime-parser/encoder/RawBuffer.d.ts +1 -1
  30. package/dist/mime-parser/encoder/RawBuffer.d.ts.map +1 -1
  31. package/dist/mime-parser/encoder/RawBuffer.js +42 -46
  32. package/dist/mime-parser/encoder/RawBuffer.js.map +1 -1
  33. package/dist/mime-parser/encoder/base64-to-blob.d.ts +1 -1
  34. package/dist/mime-parser/encoder/base64-to-blob.d.ts.map +1 -1
  35. package/dist/mime-parser/encoder/base64-to-blob.js +16 -21
  36. package/dist/mime-parser/encoder/base64-to-blob.js.map +1 -1
  37. package/dist/mime-parser/encoder/quoted-printable.d.ts +1 -1
  38. package/dist/mime-parser/encoder/quoted-printable.js +92 -61
  39. package/dist/mime-parser/encoder/quoted-printable.js.map +1 -1
  40. package/dist/mime-parser/encoder/word-encoding.d.ts.map +1 -1
  41. package/dist/mime-parser/encoder/word-encoding.js +27 -37
  42. package/dist/mime-parser/encoder/word-encoding.js.map +1 -1
  43. package/dist/mime-parser/parsePairs.js +25 -31
  44. package/dist/mime-parser/parsePairs.js.map +1 -1
  45. package/dist/mime-parser/stream/LineStream.d.ts.map +1 -1
  46. package/dist/mime-parser/stream/LineStream.js +95 -106
  47. package/dist/mime-parser/stream/LineStream.js.map +1 -1
  48. package/dist/mime-parser/stream/TextWriter.d.ts +1 -1
  49. package/dist/mime-parser/stream/TextWriter.d.ts.map +1 -1
  50. package/dist/mime-parser/stream/TextWriter.js +21 -34
  51. package/dist/mime-parser/stream/TextWriter.js.map +1 -1
  52. package/dist/mime-parser/tokenizer.js +43 -51
  53. package/dist/mime-parser/tokenizer.js.map +1 -1
  54. package/dist/tsconfig.tsbuildinfo +1 -1
  55. package/index.js +1 -0
  56. package/package.json +2 -2
  57. package/src/ical-parser/Calender.ts +7 -7
  58. package/tsconfig.json +4 -1
@@ -1,426 +1,444 @@
1
- System.register(["tslib", "./AttachmentFile.js", "./HeaderContentType.js", "./HeaderContentDisposition.js", "./encoder/RawBuffer.js", "./encoder/base64-to-blob.js", "./encoder/quoted-printable.js", "./encoder/word-encoding.js", "./stream/LineStream.js", "./stream/TextWriter.js"], function (_export, _context) {
2
- "use strict";
3
-
4
- var __asyncValues, __awaiter, AttachmentFile, HeaderContentType, HeaderContentDisposition, RawBuffer, base64toBlob, quotedPrintable, wordEncoding, LineStream, TextWriter, CIMap, MimeNode;
5
- _export({
6
- CIMap: void 0,
7
- MimeNode: void 0
8
- });
9
- return {
10
- setters: [function (_tslib) {
11
- __asyncValues = _tslib.__asyncValues;
12
- __awaiter = _tslib.__awaiter;
13
- }, function (_AttachmentFileJs) {
14
- AttachmentFile = _AttachmentFileJs.AttachmentFile;
15
- }, function (_HeaderContentTypeJs) {
16
- HeaderContentType = _HeaderContentTypeJs.HeaderContentType;
17
- }, function (_HeaderContentDispositionJs) {
18
- HeaderContentDisposition = _HeaderContentDispositionJs.HeaderContentDisposition;
19
- }, function (_encoderRawBufferJs) {
20
- RawBuffer = _encoderRawBufferJs.RawBuffer;
21
- }, function (_encoderBase64ToBlobJs) {
22
- base64toBlob = _encoderBase64ToBlobJs.base64toBlob;
23
- }, function (_encoderQuotedPrintableJs) {
24
- quotedPrintable = _encoderQuotedPrintableJs.quotedPrintable;
25
- }, function (_encoderWordEncodingJs) {
26
- wordEncoding = _encoderWordEncodingJs.wordEncoding;
27
- }, function (_streamLineStreamJs) {
28
- LineStream = _streamLineStreamJs.default;
29
- }, function (_streamTextWriterJs) {
30
- TextWriter = _streamTextWriterJs.default;
31
- }],
32
- execute: function () {
33
- _export("CIMap", CIMap = class CIMap extends Map {
34
- constructor() {
35
- super(...arguments);
36
- this.ci = new Map();
37
- }
38
- set(key, value) {
39
- if (typeof key === "string") {
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ var __asyncValues = (this && this.__asyncValues) || function (o) {
11
+ if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
12
+ var m = o[Symbol.asyncIterator], i;
13
+ return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
14
+ function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
15
+ function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
16
+ };
17
+ /* eslint-disable @typescript-eslint/no-redundant-type-constituents */
18
+ // import QueryIterator from "../../common/QueryIterator";
19
+ import { AttachmentFile } from "./AttachmentFile.js";
20
+ import { HeaderContentType } from "./HeaderContentType.js";
21
+ import { HeaderContentDisposition } from "./HeaderContentDisposition.js";
22
+ import { RawBuffer } from "./encoder/RawBuffer.js";
23
+ import { base64toBlob } from "./encoder/base64-to-blob.js";
24
+ import { quotedPrintable } from "./encoder/quoted-printable.js";
25
+ import { wordEncoding } from "./encoder/word-encoding.js";
26
+ import LineStream from "./stream/LineStream.js";
27
+ import TextWriter from "./stream/TextWriter.js";
28
+ // export interface IContentTypeObject {
29
+ // type: string;
30
+ // boundary?: string;
31
+ // charset?: string
32
+ // };
33
+ // export type IContentType = string | IContentTypeObject;
34
+ // export interface IContentDispositionObject {
35
+ // type: string;
36
+ // filename?: string;
37
+ // };
38
+ // export type IContentDisposition = string | IContentDispositionObject;
39
+ export class CIMap extends Map {
40
+ constructor() {
41
+ super(...arguments);
42
+ this.ci = new Map();
43
+ }
44
+ set(key, value) {
45
+ if (typeof key === "string") {
40
46
  let ck = this.ci.get(key);
41
47
  if (ck === void 0) {
42
- ck = key.toLocaleLowerCase();
43
- this.ci.set(ck, key);
44
- } else {
45
- key = ck;
48
+ ck = key.toLocaleLowerCase();
49
+ this.ci.set(ck, key);
50
+ }
51
+ else {
52
+ key = ck;
46
53
  }
47
- }
48
- return super.set(key, value);
49
54
  }
50
- get(key) {
51
- if (typeof key === "string") {
55
+ return super.set(key, value);
56
+ }
57
+ get(key) {
58
+ if (typeof key === "string") {
52
59
  const ck = key.toLocaleLowerCase();
53
60
  key = this.ci.get(ck);
54
- }
55
- return super.get(key);
56
61
  }
57
- });
58
- _export("MimeNode", MimeNode = class MimeNode {
59
- static createMessage({
60
- html,
61
- subject,
62
- text = "",
63
- name = "",
64
- attachments = []
65
- }) {
66
- const root = new MimeNode("multipart/mixed");
67
- root.setHeader("Subject", subject);
68
- if (name) {
62
+ return super.get(key);
63
+ }
64
+ }
65
+ export class MimeNode {
66
+ static createMessage({ html, subject, text = "", name = "", attachments = [] }) {
67
+ const root = new MimeNode("multipart/mixed");
68
+ root.setHeader("Subject", subject);
69
+ if (name) {
69
70
  root.setHeader("X-Name", name);
70
- }
71
- const body = new MimeNode("multipart/alternative");
72
- body.children = [];
73
- if (html) {
71
+ }
72
+ const body = new MimeNode("multipart/alternative");
73
+ body.children = [];
74
+ if (html) {
74
75
  body.children.push(this.create(html, "text/html"));
75
- }
76
- if (text) {
76
+ }
77
+ if (text) {
77
78
  body.children.push(this.create(text, "text/plain"));
78
- }
79
- root.children = [body];
80
- if (attachments) {
79
+ }
80
+ root.children = [body];
81
+ if (attachments) {
81
82
  for (const iterator of attachments) {
82
- root.children.push(this.create(iterator));
83
+ root.children.push(this.create(iterator));
83
84
  }
84
- }
85
- return root;
86
85
  }
87
- static create(text, type, id) {
88
- if (typeof text === "string") {
86
+ return root;
87
+ }
88
+ static create(
89
+ /** @type {string | File} */ text,
90
+ /** @type {string} */ type,
91
+ /** @type {string} */ id) {
92
+ if (typeof text === "string") {
89
93
  const node = new MimeNode(type);
90
94
  node.text = text;
91
95
  return node;
92
- }
93
- const fileNode = new MimeNode(text.type);
94
- fileNode.blobData = text;
95
- fileNode.contentDisposition = new HeaderContentDisposition(type || "attachment");
96
- fileNode.contentDisposition.filename = text.name;
97
- fileNode.setHeader("Content-Disposition", fileNode.contentDisposition);
98
- if (id) {
96
+ }
97
+ const fileNode = new MimeNode(text.type);
98
+ fileNode.blobData = text;
99
+ fileNode.contentDisposition = new HeaderContentDisposition(type || "attachment");
100
+ fileNode.contentDisposition.filename = text.name;
101
+ fileNode.setHeader("Content-Disposition", fileNode.contentDisposition);
102
+ if (id) {
99
103
  fileNode.setHeader("Content-Id", id);
100
- }
101
- return fileNode;
102
104
  }
103
- get text() {
104
- var _a, _b, _c;
105
- let tc = this.textContent;
106
- if (tc) {
105
+ return fileNode;
106
+ }
107
+ /** @returns {string} */
108
+ get text() {
109
+ var _a, _b, _c;
110
+ let tc = this.textContent;
111
+ if (tc) {
107
112
  return tc;
108
- }
109
- let {
110
- encoded
111
- } = this;
112
- if (!encoded) {
113
+ }
114
+ let { encoded } = this;
115
+ if (!encoded) {
113
116
  return;
114
- }
115
- const cte = (_a = this.contentTransferEncoding) === null || _a === void 0 ? void 0 : _a.toLowerCase();
116
- switch (cte) {
117
+ }
118
+ // we need to convert byte array to utf8
119
+ const cte = (_a = this.contentTransferEncoding) === null || _a === void 0 ? void 0 : _a.toLowerCase();
120
+ switch (cte) {
117
121
  case "quoted-printable":
118
- encoded = quotedPrintable.decode(encoded);
119
- tc = RawBuffer.decode(encoded, (_b = this.contentType) === null || _b === void 0 ? void 0 : _b.charset);
120
- this.textContent = tc;
121
- break;
122
+ encoded = quotedPrintable.decode(encoded);
123
+ tc = RawBuffer.decode(encoded, (_b = this.contentType) === null || _b === void 0 ? void 0 : _b.charset);
124
+ this.textContent = tc;
125
+ break;
122
126
  case "base64":
123
- encoded = atob(encoded);
124
- tc = RawBuffer.decode(encoded, (_c = this.contentType) === null || _c === void 0 ? void 0 : _c.charset);
125
- this.textContent = tc;
126
- break;
127
+ encoded = atob(encoded);
128
+ tc = RawBuffer.decode(encoded, (_c = this.contentType) === null || _c === void 0 ? void 0 : _c.charset);
129
+ this.textContent = tc;
130
+ break;
127
131
  default:
128
- tc = encoded;
129
- this.textContent = tc;
130
- break;
131
- }
132
- return tc;
133
- }
134
- set text(v) {
135
- this.contentTransferEncoding = "quoted-printable";
136
- this.textContent = v;
132
+ tc = encoded;
133
+ this.textContent = tc;
134
+ break;
137
135
  }
138
- get blob() {
139
- var _a, _b;
140
- if (((_a = this.contentTransferEncoding) === null || _a === void 0 ? void 0 : _a.toLocaleLowerCase()) !== "base64") {
136
+ return tc;
137
+ }
138
+ set text(/** @type {string} */ v) {
139
+ this.contentTransferEncoding = "quoted-printable";
140
+ this.textContent = v;
141
+ }
142
+ /** @returns {Blob} */
143
+ get blob() {
144
+ var _a, _b;
145
+ // this will create blob..
146
+ if (((_a = this.contentTransferEncoding) === null || _a === void 0 ? void 0 : _a.toLocaleLowerCase()) !== "base64") {
141
147
  throw new Error("Not supported");
142
- }
143
- return (_b = this.blobData) !== null && _b !== void 0 ? _b : this.blobData = base64toBlob(this.encoded, this.contentType.type);
144
- }
145
- set blob(v) {
146
- this.blobData = v;
147
- }
148
- get contentTransferEncoding() {
149
- return this.header("Content-Transfer-Encoding");
150
148
  }
151
- set contentTransferEncoding(v) {
152
- this.setHeader("Content-Transfer-Encoding", v);
153
- }
154
- get boundary() {
155
- return this.contentType.boundary;
156
- }
157
- get descendent() {
158
- return this.enumerate();
159
- }
160
- constructor(type) {
161
- this.headers = new CIMap();
162
- this.contentType = new HeaderContentType(type);
163
- this.headers.set("Content-Type", this.contentType);
164
- }
165
- getFirstChild(contentType, create = false) {
166
- var _a;
167
- contentType = contentType.toLocaleLowerCase();
168
- let child = QueryIterator.first(this.descendent, x => x.contentType.type === contentType);
169
- if (!child && create) {
149
+ return (_b = this.blobData) !== null && _b !== void 0 ? _b : (this.blobData = base64toBlob(this.encoded, this.contentType.type));
150
+ }
151
+ set blob(/** @type {Blob} */ v) {
152
+ this.blobData = v;
153
+ }
154
+ /** @returns {string} */
155
+ get contentTransferEncoding() {
156
+ return this.header("Content-Transfer-Encoding");
157
+ }
158
+ set contentTransferEncoding(/** @type {string} */ v) {
159
+ this.setHeader("Content-Transfer-Encoding", v);
160
+ }
161
+ /** @returns {string} */
162
+ get boundary() {
163
+ return this.contentType.boundary;
164
+ }
165
+ /** @returns {IterableIterator<MimeNode>} */
166
+ get descendent() {
167
+ return this.enumerate();
168
+ }
169
+ constructor(/** @type {string} */ type) {
170
+ this.headers = new CIMap();
171
+ this.contentType = new HeaderContentType(type);
172
+ this.headers.set("Content-Type", this.contentType);
173
+ }
174
+ getFirstChild(
175
+ /** @type {string} */ contentType, create = false) {
176
+ var _a;
177
+ contentType = contentType.toLocaleLowerCase();
178
+ let child = QueryIterator.first(this.descendent, (x) => x.contentType.type === contentType);
179
+ if (!child && create) {
170
180
  child = new MimeNode(contentType);
171
- ((_a = this.children) !== null && _a !== void 0 ? _a : this.children = []).push(child);
172
- }
173
- return child;
174
- }
175
- header(name) {
176
- return this.headers.get(name);
177
- }
178
- setHeader(name, value) {
179
- this.headers.set(name, value);
181
+ ((_a = this.children) !== null && _a !== void 0 ? _a : (this.children = [])).push(child);
180
182
  }
181
- asFile() {
182
- return __awaiter(this, void 0, void 0, function* () {
183
- const text = this.encoded.split("\n").map(x => x.trim()).join("");
183
+ return child;
184
+ }
185
+ header(/** @type {string} */ name) {
186
+ return this.headers.get(name);
187
+ }
188
+ setHeader(
189
+ /** @type {string} */ name,
190
+ /** @type {string} */ value) {
191
+ // name = name.toLocaleLowerCase();
192
+ // for (const [key] of this.headers.keys()) {
193
+ // if (key.toLocaleLowerCase() === name) {
194
+ // this.headers.set(key, value);
195
+ // return;
196
+ // }
197
+ // }
198
+ // // change name...
199
+ // switch(name.toLocaleLowerCase()) {
200
+ // case "content-type":
201
+ // name = "Content-Type";
202
+ // break;
203
+ // case "content-transfer-encoding":
204
+ // name = "Content-Transfer-Encoding";
205
+ // break;
206
+ // case "content-disposition":
207
+ // name = "Content-Disposition";
208
+ // break;
209
+ // }
210
+ this.headers.set(name, value);
211
+ }
212
+ asFile() {
213
+ return __awaiter(this, void 0, void 0, function* () {
214
+ const text = this.encoded.split("\n").map((x) => x.trim()).join("");
184
215
  const url = `data:${this.contentType.type};base64,${text}`;
185
216
  const blob = yield fetch(url);
186
217
  const af = new AttachmentFile([yield blob.blob()], this.contentDisposition.filename, {
187
- type: this.contentType.type,
188
- contentId: this.header("Content-Id"),
189
- disposition: this.contentDisposition.type
218
+ type: this.contentType.type,
219
+ contentId: this.header("Content-Id"),
220
+ disposition: this.contentDisposition.type
190
221
  });
191
222
  af.node = this;
192
223
  return af;
193
- });
194
- }
195
- attachments(files = []) {
196
- var _a;
197
- return __awaiter(this, void 0, void 0, function* () {
224
+ });
225
+ }
226
+ attachments() {
227
+ return __awaiter(this, arguments, void 0, function* (
228
+ /** @type {AttachmentFile[]} */ files = []) {
229
+ var _a;
198
230
  for (const iterator of this.children) {
199
- if (iterator.children) {
200
- yield iterator.attachments(files);
201
- continue;
202
- }
203
- if ((_a = iterator.contentDisposition) === null || _a === void 0 ? void 0 : _a.type) {
204
- files.push(yield iterator.asFile());
205
- }
231
+ if (iterator.children) {
232
+ yield iterator.attachments(files);
233
+ continue;
234
+ }
235
+ if ((_a = iterator.contentDisposition) === null || _a === void 0 ? void 0 : _a.type) {
236
+ files.push(yield iterator.asFile());
237
+ }
206
238
  }
207
239
  return files;
208
- });
209
- }
210
- parse(lines, last = "") {
211
- var _a, e_1, _b, _c, _d, e_2, _e, _f;
212
- var _g;
213
- return __awaiter(this, void 0, void 0, function* () {
240
+ });
241
+ }
242
+ parse(lines_1) {
243
+ return __awaiter(this, arguments, void 0, function* (
244
+ /** @type {LineStream} */ lines, last = "") {
245
+ var _a, e_1, _b, _c, _d, e_2, _e, _f;
246
+ var _g;
214
247
  yield this.parseHeaders(lines);
215
248
  const end = last + "--";
216
249
  let boundary = this.contentType.boundary;
217
250
  if (!boundary) {
218
- const data = [];
219
- let isEnd = true;
220
- try {
221
- for (var _h = true, _j = __asyncValues(lines.read()), _k; _k = yield _j.next(), _a = _k.done, !_a;) {
222
- _c = _k.value;
223
- _h = false;
224
- try {
225
- const line = _c;
226
- const trimmed = line.trimEnd();
227
- if (trimmed === last) {
228
- isEnd = false;
229
- break;
230
- }
231
- if (trimmed === end) {
232
- isEnd = true;
233
- break;
251
+ const data = [];
252
+ let isEnd = true;
253
+ try {
254
+ // parse data till end of the boundary
255
+ for (var _h = true, _j = __asyncValues(lines.read()), _k; _k = yield _j.next(), _a = _k.done, !_a; _h = true) {
256
+ _c = _k.value;
257
+ _h = false;
258
+ const line = _c;
259
+ const trimmed = line.trimEnd();
260
+ if (trimmed === last) {
261
+ isEnd = false;
262
+ break;
263
+ }
264
+ if (trimmed === end) {
265
+ isEnd = true;
266
+ break;
267
+ }
268
+ data.push(line);
234
269
  }
235
- data.push(line);
236
- } finally {
237
- _h = true;
238
- }
239
270
  }
240
- } catch (e_1_1) {
241
- e_1 = {
242
- error: e_1_1
243
- };
244
- } finally {
245
- try {
246
- if (!_h && !_a && (_b = _j.return)) yield _b.call(_j);
247
- } finally {
248
- if (e_1) throw e_1.error;
271
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
272
+ finally {
273
+ try {
274
+ if (!_h && !_a && (_b = _j.return)) yield _b.call(_j);
275
+ }
276
+ finally { if (e_1) throw e_1.error; }
249
277
  }
250
- }
251
- this.encoded = data.join("\n");
252
- return isEnd;
278
+ this.encoded = data.join("\n");
279
+ return isEnd;
253
280
  }
281
+ // skip till boundary
254
282
  const start = "--" + boundary;
255
283
  try {
256
- for (var _l = true, _m = __asyncValues(lines.read()), _o; _o = yield _m.next(), _d = _o.done, !_d;) {
257
- _f = _o.value;
258
- _l = false;
284
+ for (var _l = true, _m = __asyncValues(lines.read()), _o; _o = yield _m.next(), _d = _o.done, !_d; _l = true) {
285
+ _f = _o.value;
286
+ _l = false;
287
+ const line = _f;
288
+ const trimmed = line;
289
+ if (trimmed === start) {
290
+ break;
291
+ }
292
+ }
293
+ }
294
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
295
+ finally {
259
296
  try {
260
- const line = _f;
261
- const trimmed = line;
262
- if (trimmed === start) {
263
- break;
264
- }
265
- } finally {
266
- _l = true;
297
+ if (!_l && !_d && (_e = _m.return)) yield _e.call(_m);
267
298
  }
268
- }
269
- } catch (e_2_1) {
270
- e_2 = {
271
- error: e_2_1
272
- };
273
- } finally {
274
- try {
275
- if (!_l && !_d && (_e = _m.return)) yield _e.call(_m);
276
- } finally {
277
- if (e_2) throw e_2.error;
278
- }
299
+ finally { if (e_2) throw e_2.error; }
279
300
  }
280
- (_g = this.children) !== null && _g !== void 0 ? _g : this.children = [];
301
+ (_g = this.children) !== null && _g !== void 0 ? _g : (this.children = []);
281
302
  for (;;) {
282
- const child = new MimeNode("");
283
- const isLast = yield child.parse(lines, start);
284
- this.children.push(child);
285
- if (isLast) {
286
- return;
287
- }
303
+ const child = new MimeNode("");
304
+ const isLast = yield child.parse(lines, start);
305
+ this.children.push(child);
306
+ if (isLast) {
307
+ return;
308
+ }
288
309
  }
289
- });
290
- }
291
- parseHeaders(lines) {
292
- var _a, e_3, _b, _c;
293
- var _d;
294
- return __awaiter(this, void 0, void 0, function* () {
310
+ });
311
+ }
312
+ parseHeaders(
313
+ /** @type {LineStream} */ lines) {
314
+ return __awaiter(this, void 0, void 0, function* () {
315
+ var _a, e_3, _b, _c;
316
+ var _d;
295
317
  let headerName = "";
296
318
  let headerValue = "";
297
319
  try {
298
- for (var _e = true, _f = __asyncValues(lines.read()), _g; _g = yield _f.next(), _a = _g.done, !_a;) {
299
- _c = _g.value;
300
- _e = false;
320
+ for (var _e = true, _f = __asyncValues(lines.read()), _g; _g = yield _f.next(), _a = _g.done, !_a; _e = true) {
321
+ _c = _g.value;
322
+ _e = false;
323
+ const iterator = _c;
324
+ const value = iterator.trim();
325
+ if (value.length === 0) {
326
+ break;
327
+ }
328
+ if (/^[\x20\t]/.test(iterator)) {
329
+ headerValue += wordEncoding.decode(value);
330
+ continue;
331
+ }
332
+ if (headerValue) {
333
+ this.setHeader(headerName, headerValue);
334
+ }
335
+ const index = value.indexOf(":");
336
+ headerName = value.substring(0, index);
337
+ headerValue = wordEncoding.decode(value.substring(index + 1).trim());
338
+ }
339
+ }
340
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
341
+ finally {
301
342
  try {
302
- const iterator = _c;
303
- const value = iterator.trim();
304
- if (value.length === 0) {
305
- break;
306
- }
307
- if (/^[\x20\t]/.test(iterator)) {
308
- headerValue += wordEncoding.decode(value);
309
- continue;
310
- }
311
- if (headerValue) {
312
- this.setHeader(headerName, headerValue);
313
- }
314
- const index = value.indexOf(":");
315
- headerName = value.substring(0, index);
316
- headerValue = wordEncoding.decode(value.substring(index + 1).trim());
317
- } finally {
318
- _e = true;
343
+ if (!_e && !_a && (_b = _f.return)) yield _b.call(_f);
319
344
  }
320
- }
321
- } catch (e_3_1) {
322
- e_3 = {
323
- error: e_3_1
324
- };
325
- } finally {
326
- try {
327
- if (!_e && !_a && (_b = _f.return)) yield _b.call(_f);
328
- } finally {
329
- if (e_3) throw e_3.error;
330
- }
345
+ finally { if (e_3) throw e_3.error; }
331
346
  }
332
347
  if (headerValue) {
333
- this.setHeader(headerName, headerValue);
334
- } else {
335
- return;
348
+ this.setHeader(headerName, headerValue);
349
+ }
350
+ else {
351
+ return;
336
352
  }
337
353
  const ct = this.header("Content-Type");
338
354
  this.contentType.parse(ct);
339
355
  this.setHeader("Content-Type", ct);
340
356
  const cd = this.header("Content-Disposition");
341
357
  if (cd) {
342
- (_d = this.contentDisposition) !== null && _d !== void 0 ? _d : this.contentDisposition = new HeaderContentDisposition();
343
- this.contentDisposition.parse(cd);
344
- this.setHeader("Content-Disposition", cd);
358
+ (_d = this.contentDisposition) !== null && _d !== void 0 ? _d : (this.contentDisposition = new HeaderContentDisposition());
359
+ this.contentDisposition.parse(cd);
360
+ this.setHeader("Content-Disposition", cd);
345
361
  }
346
- });
347
- }
348
- save(writer) {
349
- var _a, _b;
350
- var _c;
351
- return __awaiter(this, void 0, void 0, function* () {
362
+ });
363
+ }
364
+ save(/** @type {TextWriter} */ writer) {
365
+ return __awaiter(this, void 0, void 0, function* () {
366
+ var _a, _b;
367
+ var _c;
352
368
  if (this.textContent) {
353
- this.contentType.charset = "UTF-8";
369
+ this.contentType.charset = "UTF-8";
354
370
  }
355
371
  if ((_a = this.children) === null || _a === void 0 ? void 0 : _a.length) {
356
- (_c = this.contentType).boundary || (_c.boundary = `${Date.now()}-${Date.now()}-${Date.now()}`);
372
+ (_c = this.contentType).boundary || (_c.boundary = `${Date.now()}-${Date.now()}-${Date.now()}`);
357
373
  }
358
374
  for (const [key, element] of this.headers.entries()) {
359
- switch (key) {
360
- case "content-disposition":
361
- writer.writeLine(`Content-Disposition: ${this.contentDisposition}`);
362
- continue;
363
- case "content-type":
364
- writer.writeLine(`Content-Type:${this.contentType.toString()}`);
365
- continue;
366
- case "subject":
367
- writer.writeLine(`${key}: ${wordEncoding.encode(element, true)}`);
368
- continue;
369
- }
370
- writer.writeLine(`${key}: ${element}`);
375
+ switch (key) {
376
+ case "content-disposition":
377
+ writer.writeLine(`Content-Disposition: ${this.contentDisposition}`);
378
+ continue;
379
+ case "content-type":
380
+ writer.writeLine(`Content-Type:${this.contentType.toString()}`);
381
+ continue;
382
+ case "subject":
383
+ writer.writeLine(`${key}: ${wordEncoding.encode(element, true)}`);
384
+ continue;
385
+ }
386
+ writer.writeLine(`${key}: ${element}`);
371
387
  }
372
388
  writer.writeLine("");
389
+ // check if we have any children...
373
390
  if ((_b = this.children) === null || _b === void 0 ? void 0 : _b.length) {
374
- const boundary = `--${this.contentType.boundary}`;
375
- for (const iterator of this.children) {
376
- writer.writeLine(boundary);
377
- yield iterator.save(writer);
378
- }
379
- writer.writeLine(boundary + "--");
380
- return;
391
+ const boundary = `--${this.contentType.boundary}`;
392
+ for (const iterator of this.children) {
393
+ writer.writeLine(boundary);
394
+ yield iterator.save(writer);
395
+ }
396
+ writer.writeLine(boundary + "--");
397
+ return;
381
398
  }
399
+ // check if we have text or binary
382
400
  if (this.blobData) {
383
- const base64 = yield RawBuffer.toBase64Async(this.blobData);
384
- let start = 0;
385
- const max = 80;
386
- for (;;) {
387
- if (start + max > base64.length) {
388
- writer.writeLine(base64.substring(start));
389
- break;
401
+ // convert to base64
402
+ const base64 = yield RawBuffer.toBase64Async(this.blobData);
403
+ let start = 0;
404
+ const max = 80;
405
+ for (;;) {
406
+ if (start + max > base64.length) {
407
+ writer.writeLine(base64.substring(start));
408
+ break;
409
+ }
410
+ writer.writeLine(base64.substring(start, start + max));
411
+ start += max;
390
412
  }
391
- writer.writeLine(base64.substring(start, start + max));
392
- start += max;
393
- }
394
- return;
413
+ return;
395
414
  }
396
415
  let text = this.text;
397
416
  switch (this.contentTransferEncoding) {
398
- case "quoted-printable":
399
- text = quotedPrintable.encode(RawBuffer.encode(text));
400
- writer.writeLine(text);
401
- break;
402
- case "base64":
403
- text = btoa(RawBuffer.encode(text, this.contentType.charset));
404
- writer.writeLine(text);
405
- break;
406
- default:
407
- writer.writeLine(text);
408
- break;
417
+ case "quoted-printable":
418
+ text = quotedPrintable.encode(RawBuffer.encode(text));
419
+ writer.writeLine(text);
420
+ break;
421
+ case "base64":
422
+ text = btoa(RawBuffer.encode(text, this.contentType.charset));
423
+ writer.writeLine(text);
424
+ break;
425
+ default:
426
+ writer.writeLine(text);
427
+ break;
409
428
  }
429
+ // writer.writeLine("");
410
430
  return;
411
- });
412
- }
413
- *enumerate() {
414
- yield this;
415
- if (!this.children) {
431
+ });
432
+ }
433
+ /** @returns {IterableIterator<MimeNode>} */
434
+ *enumerate() {
435
+ yield this;
436
+ if (!this.children) {
416
437
  return;
417
- }
418
- for (const iterator of this.children) {
438
+ }
439
+ for (const iterator of this.children) {
419
440
  yield* iterator.enumerate();
420
- }
421
441
  }
422
- });
423
442
  }
424
- };
425
- });
443
+ }
426
444
  //# sourceMappingURL=MimeNode.js.map