@carlgo11/simpleimfparser 0.0.1 → 0.0.2

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/LICENSE +21 -674
  2. package/README.md +59 -0
  3. package/dist/index.d.ts +14 -0
  4. package/dist/index.d.ts.map +1 -0
  5. package/dist/parsers/parseEnvelope.d.ts +8 -0
  6. package/dist/parsers/parseEnvelope.d.ts.map +1 -0
  7. package/dist/parsers/parseHeaders.d.ts +10 -0
  8. package/dist/parsers/parseHeaders.d.ts.map +1 -0
  9. package/dist/parsers/parseMessage.d.ts +11 -0
  10. package/dist/parsers/parseMessage.d.ts.map +1 -0
  11. package/dist/types/Attachment.d.ts +56 -0
  12. package/dist/types/Attachment.d.ts.map +1 -0
  13. package/dist/types/Email.d.ts +114 -0
  14. package/dist/types/Email.d.ts.map +1 -0
  15. package/dist/types/Envelope.d.ts +45 -0
  16. package/dist/types/Envelope.d.ts.map +1 -0
  17. package/dist/types/Sender.d.ts +75 -0
  18. package/dist/types/Sender.d.ts.map +1 -0
  19. package/dist/utils/streamToString.d.ts +8 -0
  20. package/dist/utils/streamToString.d.ts.map +1 -0
  21. package/package.json +14 -4
  22. package/.github/workflows/publish.yaml +0 -51
  23. package/.github/workflows/test.yaml +0 -14
  24. package/.gitignore +0 -6
  25. package/dist/index.js +0 -14
  26. package/dist/parsers/parseEnvelope.js +0 -12
  27. package/dist/parsers/parseHeaders.js +0 -68
  28. package/dist/parsers/parseMessage.js +0 -36
  29. package/dist/types/Attachment.js +0 -2
  30. package/dist/types/Email.js +0 -59
  31. package/dist/types/Envelope.js +0 -2
  32. package/dist/types/Sender.js +0 -2
  33. package/dist/utils/streamToString.js +0 -16
  34. package/src/index.js +0 -14
  35. package/src/index.ts +0 -14
  36. package/src/parsers/parseEnvelope.js +0 -12
  37. package/src/parsers/parseEnvelope.ts +0 -11
  38. package/src/parsers/parseHeaders.js +0 -68
  39. package/src/parsers/parseHeaders.ts +0 -65
  40. package/src/parsers/parseMessage.js +0 -36
  41. package/src/parsers/parseMessage.ts +0 -32
  42. package/src/types/Attachment.js +0 -2
  43. package/src/types/Attachment.ts +0 -6
  44. package/src/types/Email.js +0 -59
  45. package/src/types/Email.ts +0 -77
  46. package/src/types/Envelope.js +0 -2
  47. package/src/types/Envelope.ts +0 -9
  48. package/src/types/Sender.js +0 -2
  49. package/src/types/Sender.ts +0 -10
  50. package/src/utils/streamToString.js +0 -16
  51. package/src/utils/streamToString.ts +0 -15
  52. package/test/index.test.js +0 -38
  53. package/test/index.test.ts +0 -40
  54. package/test/parsers/parseHeaders.test.js +0 -32
  55. package/test/parsers/parseHeaders.test.ts +0 -32
  56. package/test/parsers/parseMessage.test.js +0 -35
  57. package/test/parsers/parseMessage.test.ts +0 -34
  58. package/tsconfig.json +0 -16
@@ -1,36 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.default = parseMessage;
7
- const node_stream_1 = require("node:stream");
8
- const parseHeaders_1 = __importDefault(require("./parseHeaders"));
9
- const streamToString_1 = __importDefault(require("../utils/streamToString"));
10
- /**
11
- * Parses the raw email message (headers + body).
12
- * @param rawData - Raw IMF email (string or stream)
13
- * @returns Parsed email components
14
- */
15
- async function parseMessage(rawData) {
16
- let rawEmail;
17
- if (typeof rawData === 'string') {
18
- rawEmail = rawData;
19
- }
20
- else if (rawData instanceof node_stream_1.Readable) {
21
- rawEmail = await (0, streamToString_1.default)(rawData);
22
- }
23
- else {
24
- throw new TypeError('Invalid rawData type. Expected a string or a Readable stream.');
25
- }
26
- const headerBoundary = rawEmail.indexOf('\r\n\r\n');
27
- const rawHeaders = rawEmail.slice(0, headerBoundary);
28
- const body = rawEmail.slice(headerBoundary + 4);
29
- if (body.length === 0) {
30
- throw new Error('Header and Body must be separated by \\r\\n\\r\\n');
31
- }
32
- return {
33
- headers: (0, parseHeaders_1.default)(rawHeaders),
34
- body,
35
- };
36
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,59 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Email = void 0;
4
- class Email {
5
- envelope;
6
- headers;
7
- body;
8
- attachments;
9
- constructor(envelope, headers, body, attachments) {
10
- this.envelope = envelope;
11
- this.headers = headers;
12
- this.body = body;
13
- this.attachments = attachments || [];
14
- }
15
- /**
16
- * Get a header value (case-insensitive).
17
- */
18
- getHeader(name) {
19
- return this.headers[name.toLowerCase()];
20
- }
21
- /**
22
- * Add or update a header.
23
- */
24
- addHeader(name, value) {
25
- const key = name.toLowerCase();
26
- if (this.headers[key]) {
27
- if (Array.isArray(this.headers[key])) {
28
- this.headers[key].push(value);
29
- }
30
- else {
31
- this.headers[key] = [this.headers[key], value];
32
- }
33
- }
34
- else {
35
- this.headers[key] = value;
36
- }
37
- }
38
- /**
39
- * Remove a header.
40
- */
41
- removeHeader(name) {
42
- delete this.headers[name.toLowerCase()];
43
- }
44
- /**
45
- * Get the email body (prefers text, fallback to HTML).
46
- */
47
- getBody() {
48
- return this.body || '';
49
- }
50
- toString() {
51
- let _headers = '';
52
- Object.entries(this.headers).forEach(([k, v]) => _headers += `${camelize(k)}: ${v}\r\n`);
53
- return `${_headers}\r\n\r\n${this.body}`;
54
- }
55
- }
56
- exports.Email = Email;
57
- function camelize(str) {
58
- return str.replace(/(\w)(\w*)/g, function (g0, g1, g2) { return g1.toUpperCase() + g2.toLowerCase(); });
59
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,16 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = streamToString;
4
- /**
5
- * Converts a Readable Stream to a string.
6
- * @param stream - Input stream
7
- * @returns Promise resolving to the string content
8
- */
9
- async function streamToString(stream) {
10
- return new Promise((resolve, reject) => {
11
- let data = '';
12
- stream.on('data', chunk => (data += chunk));
13
- stream.on('end', () => resolve(data));
14
- stream.on('error', reject);
15
- });
16
- }
package/src/index.js DELETED
@@ -1,14 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.default = parseEmail;
7
- const Email_1 = require("./types/Email");
8
- const parseEnvelope_1 = __importDefault(require("./parsers/parseEnvelope"));
9
- const parseMessage_1 = __importDefault(require("./parsers/parseMessage"));
10
- async function parseEmail(rawData, envelope) {
11
- const parsedEnvelope = await (0, parseEnvelope_1.default)(envelope);
12
- const { headers, body } = await (0, parseMessage_1.default)(rawData);
13
- return new Email_1.Email(parsedEnvelope, headers, body);
14
- }
package/src/index.ts DELETED
@@ -1,14 +0,0 @@
1
- import { Readable } from 'node:stream';
2
- import { Email } from './types/Email';
3
- import parseEnvelope from './parsers/parseEnvelope';
4
- import parseMessage from './parsers/parseMessage';
5
-
6
- export default async function parseEmail(
7
- rawData: string | Readable,
8
- envelope: object,
9
- ): Promise<Email> {
10
- const parsedEnvelope = await parseEnvelope(envelope);
11
- const { headers, body } = await parseMessage(rawData);
12
-
13
- return new Email(parsedEnvelope, headers, body);
14
- }
@@ -1,12 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = parseEnvelope;
4
- /**
5
- * Parses envelope metadata from the SMTP transaction.
6
- * @param envelope - Envelope data object
7
- * @returns Parsed Envelope object
8
- */
9
- async function parseEnvelope(envelope) {
10
- // TODO: Implement envelope parsing logic
11
- return envelope;
12
- }
@@ -1,11 +0,0 @@
1
- import Envelope from '../types/Envelope';
2
-
3
- /**
4
- * Parses envelope metadata from the SMTP transaction.
5
- * @param envelope - Envelope data object
6
- * @returns Parsed Envelope object
7
- */
8
- export default async function parseEnvelope(envelope: Object): Promise<Envelope> {
9
- // TODO: Implement envelope parsing logic
10
- return envelope as Envelope;
11
- }
@@ -1,68 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = parseHeaders;
4
- /**
5
- * Parses headers from a raw IMF header string.
6
- * @param rawHeaders - The raw headers as a string
7
- * @returns A dictionary of headers (handling duplicates)
8
- */
9
- function parseHeaders(rawHeaders) {
10
- const headers = {};
11
- const lines = rawHeaders.split(/\r\n|\n/);
12
- let currentKey = null;
13
- let currentValue = '';
14
- for (const line of lines) {
15
- if (line.startsWith(' ') || line.startsWith('\t')) {
16
- // Handle folded headers (continuation lines)
17
- if (currentKey) {
18
- if (Array.isArray(headers[currentKey])) {
19
- headers[currentKey][headers[currentKey].length - 1] += ' ' + line.trim();
20
- }
21
- else {
22
- headers[currentKey] += ' ' + line.trim();
23
- }
24
- }
25
- else {
26
- throw new Error('Header folding found without a preceding header field.');
27
- }
28
- }
29
- else {
30
- // Store previous header before starting a new one
31
- if (currentKey) {
32
- if (headers[currentKey]) {
33
- if (Array.isArray(headers[currentKey])) {
34
- headers[currentKey].push(currentValue);
35
- }
36
- else {
37
- headers[currentKey] = [headers[currentKey], currentValue];
38
- }
39
- }
40
- else {
41
- headers[currentKey] = currentValue;
42
- }
43
- }
44
- // Extract new header key-value pair
45
- const match = line.match(/^([!#$%&'*+\-.0-9A-Z^_`a-z|~]+):\s*(.*)$/);
46
- if (!match) {
47
- throw new Error(`Invalid header format: "${line}"`);
48
- }
49
- currentKey = match[1].toLowerCase(); // Convert key to lowercase
50
- currentValue = match[2];
51
- }
52
- }
53
- // Store the last header
54
- if (currentKey) {
55
- if (headers[currentKey]) {
56
- if (Array.isArray(headers[currentKey])) {
57
- headers[currentKey].push(currentValue);
58
- }
59
- else {
60
- headers[currentKey] = [headers[currentKey], currentValue];
61
- }
62
- }
63
- else {
64
- headers[currentKey] = currentValue;
65
- }
66
- }
67
- return headers;
68
- }
@@ -1,65 +0,0 @@
1
- /**
2
- * Parses headers from a raw IMF header string.
3
- * @param rawHeaders - The raw headers as a string
4
- * @returns A dictionary of headers (handling duplicates)
5
- */
6
- export default function parseHeaders(rawHeaders: string): Record<string, string | string[]> {
7
- const headers: Record<string, string | string[]> = {};
8
- const lines = rawHeaders.split(/\r\n|\n/);
9
-
10
- let currentKey: string | null = null;
11
- let currentValue: string = '';
12
-
13
- for (const line of lines) {
14
- if (line.startsWith(' ') || line.startsWith('\t')) {
15
- // Handle folded headers (continuation lines)
16
- if (currentKey) {
17
- if (Array.isArray(headers[currentKey])) {
18
- (headers[currentKey] as string[])[(headers[currentKey] as string[]).length - 1] += ' ' + line.trim();
19
- } else {
20
- headers[currentKey] += ' ' + line.trim();
21
- }
22
- } else {
23
- throw new Error('Header folding found without a preceding header field.');
24
- }
25
- } else {
26
- // Store previous header before starting a new one
27
- if (currentKey) {
28
- if (headers[currentKey]) {
29
- if (Array.isArray(headers[currentKey])) {
30
- (headers[currentKey] as string[]).push(currentValue);
31
- } else {
32
- headers[currentKey] = [headers[currentKey] as string, currentValue];
33
- }
34
- } else {
35
- headers[currentKey] = currentValue;
36
- }
37
- }
38
-
39
- // Extract new header key-value pair
40
- const match = line.match(/^([!#$%&'*+\-.0-9A-Z^_`a-z|~]+):\s*(.*)$/);
41
-
42
- if (!match) {
43
- throw new Error(`Invalid header format: "${line}"`);
44
- }
45
-
46
- currentKey = match[1].toLowerCase(); // Convert key to lowercase
47
- currentValue = match[2];
48
- }
49
- }
50
-
51
- // Store the last header
52
- if (currentKey) {
53
- if (headers[currentKey]) {
54
- if (Array.isArray(headers[currentKey])) {
55
- (headers[currentKey] as string[]).push(currentValue);
56
- } else {
57
- headers[currentKey] = [headers[currentKey] as string, currentValue];
58
- }
59
- } else {
60
- headers[currentKey] = currentValue;
61
- }
62
- }
63
-
64
- return headers;
65
- }
@@ -1,36 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.default = parseMessage;
7
- const node_stream_1 = require("node:stream");
8
- const parseHeaders_1 = __importDefault(require("./parseHeaders"));
9
- const streamToString_1 = __importDefault(require("../utils/streamToString"));
10
- /**
11
- * Parses the raw email message (headers + body).
12
- * @param rawData - Raw IMF email (string or stream)
13
- * @returns Parsed email components
14
- */
15
- async function parseMessage(rawData) {
16
- let rawEmail;
17
- if (typeof rawData === 'string') {
18
- rawEmail = rawData;
19
- }
20
- else if (rawData instanceof node_stream_1.Readable) {
21
- rawEmail = await (0, streamToString_1.default)(rawData);
22
- }
23
- else {
24
- throw new TypeError('Invalid rawData type. Expected a string or a Readable stream.');
25
- }
26
- const headerBoundary = rawEmail.indexOf('\r\n\r\n');
27
- const rawHeaders = rawEmail.slice(0, headerBoundary);
28
- const body = rawEmail.slice(headerBoundary + 4);
29
- if (body.length === 0) {
30
- throw new Error('Header and Body must be separated by \\r\\n\\r\\n');
31
- }
32
- return {
33
- headers: (0, parseHeaders_1.default)(rawHeaders),
34
- body,
35
- };
36
- }
@@ -1,32 +0,0 @@
1
- import { Readable } from 'node:stream';
2
- import parseHeaders from './parseHeaders';
3
- import streamToString from '../utils/streamToString';
4
-
5
- /**
6
- * Parses the raw email message (headers + body).
7
- * @param rawData - Raw IMF email (string or stream)
8
- * @returns Parsed email components
9
- */
10
- export default async function parseMessage(rawData: string | Readable): Promise<{ headers: Record<string, string | string[]>, body: string }> {
11
- let rawEmail: string;
12
-
13
- if (typeof rawData === 'string') {
14
- rawEmail = rawData;
15
- } else if (rawData instanceof Readable) {
16
- rawEmail = await streamToString(rawData);
17
- } else {
18
- throw new TypeError('Invalid rawData type. Expected a string or a Readable stream.');
19
- }
20
-
21
- const headerBoundary = rawEmail.indexOf('\r\n\r\n');
22
- const rawHeaders = rawEmail.slice(0, headerBoundary);
23
- const body = rawEmail.slice(headerBoundary + 4)
24
- if (body.length === 0) {
25
- throw new Error('Header and Body must be separated by \\r\\n\\r\\n');
26
- }
27
-
28
- return {
29
- headers: parseHeaders(rawHeaders),
30
- body,
31
- };
32
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,6 +0,0 @@
1
- export default interface Attachment {
2
- filename: string;
3
- contentType: string;
4
- size: number;
5
- content: Buffer;
6
- }
@@ -1,59 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Email = void 0;
4
- class Email {
5
- envelope;
6
- headers;
7
- body;
8
- attachments;
9
- constructor(envelope, headers, body, attachments) {
10
- this.envelope = envelope;
11
- this.headers = headers;
12
- this.body = body;
13
- this.attachments = attachments || [];
14
- }
15
- /**
16
- * Get a header value (case-insensitive).
17
- */
18
- getHeader(name) {
19
- return this.headers[name.toLowerCase()];
20
- }
21
- /**
22
- * Add or update a header.
23
- */
24
- addHeader(name, value) {
25
- const key = name.toLowerCase();
26
- if (this.headers[key]) {
27
- if (Array.isArray(this.headers[key])) {
28
- this.headers[key].push(value);
29
- }
30
- else {
31
- this.headers[key] = [this.headers[key], value];
32
- }
33
- }
34
- else {
35
- this.headers[key] = value;
36
- }
37
- }
38
- /**
39
- * Remove a header.
40
- */
41
- removeHeader(name) {
42
- delete this.headers[name.toLowerCase()];
43
- }
44
- /**
45
- * Get the email body (prefers text, fallback to HTML).
46
- */
47
- getBody() {
48
- return this.body || '';
49
- }
50
- toString() {
51
- let _headers = '';
52
- Object.entries(this.headers).forEach(([k, v]) => _headers += `${camelize(k)}: ${v}\r\n`);
53
- return `${_headers}\r\n\r\n${this.body}`;
54
- }
55
- }
56
- exports.Email = Email;
57
- function camelize(str) {
58
- return str.replace(/(\w)(\w*)/g, function (g0, g1, g2) { return g1.toUpperCase() + g2.toLowerCase(); });
59
- }
@@ -1,77 +0,0 @@
1
- import Envelope from './Envelope';
2
-
3
- export class Email {
4
- envelope: Envelope;
5
- headers: Record<string, string | string[]>;
6
- body: string;
7
- attachments?: Attachment[];
8
-
9
- constructor(
10
- envelope: Envelope,
11
- headers: Record<string, string | string[]>,
12
- body: string,
13
- attachments?: Attachment[],
14
- ) {
15
- this.envelope = envelope;
16
- this.headers = headers;
17
- this.body = body;
18
- this.attachments = attachments || [];
19
- }
20
-
21
- /**
22
- * Get a header value (case-insensitive).
23
- */
24
- getHeader(name: string): string | string[] | undefined {
25
- return this.headers[name.toLowerCase()];
26
- }
27
-
28
- /**
29
- * Add or update a header.
30
- */
31
- addHeader(name: string, value: string): void {
32
- const key = name.toLowerCase();
33
- if (this.headers[key]) {
34
- if (Array.isArray(this.headers[key])) {
35
- (this.headers[key] as string[]).push(value);
36
- } else {
37
- this.headers[key] = [this.headers[key] as string, value];
38
- }
39
- } else {
40
- this.headers[key] = value;
41
- }
42
- }
43
-
44
- /**
45
- * Remove a header.
46
- */
47
- removeHeader(name: string): void {
48
- delete this.headers[name.toLowerCase()];
49
- }
50
-
51
- /**
52
- * Get the email body (prefers text, fallback to HTML).
53
- */
54
- getBody(): string {
55
- return this.body || '';
56
- }
57
-
58
- toString(): string {
59
- let _headers = ''
60
- Object.entries(this.headers).forEach(([k, v]) => _headers += `${camelize(k)}: ${v}\r\n`)
61
-
62
-
63
- return `${_headers}\r\n\r\n${this.body}`;
64
- }
65
- }
66
-
67
- function camelize(str: string):string {
68
- return str.replace(/(\w)(\w*)/g,
69
- function(g0,g1,g2){return g1.toUpperCase() + g2.toLowerCase();});
70
- }
71
-
72
- export interface Attachment {
73
- filename: string;
74
- contentType: string;
75
- size: number;
76
- content: Buffer;
77
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,9 +0,0 @@
1
- import Sender from './Sender';
2
-
3
- export default interface Envelope {
4
- id: string;
5
- from: string;
6
- to: string[];
7
- receivedTime: Date;
8
- sender: Sender;
9
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,10 +0,0 @@
1
- export default interface Sender {
2
- ip: string;
3
- rDNS?: string;
4
- helo?: string;
5
- tls: boolean;
6
- authenticated?: {
7
- method: string;
8
- username?: string;
9
- };
10
- }
@@ -1,16 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = streamToString;
4
- /**
5
- * Converts a Readable Stream to a string.
6
- * @param stream - Input stream
7
- * @returns Promise resolving to the string content
8
- */
9
- async function streamToString(stream) {
10
- return new Promise((resolve, reject) => {
11
- let data = '';
12
- stream.on('data', chunk => (data += chunk));
13
- stream.on('end', () => resolve(data));
14
- stream.on('error', reject);
15
- });
16
- }
@@ -1,15 +0,0 @@
1
- import { Readable } from 'node:stream';
2
-
3
- /**
4
- * Converts a Readable Stream to a string.
5
- * @param stream - Input stream
6
- * @returns Promise resolving to the string content
7
- */
8
- export default async function streamToString(stream: Readable): Promise<string> {
9
- return new Promise((resolve, reject) => {
10
- let data = '';
11
- stream.on('data', chunk => (data += chunk));
12
- stream.on('end', () => resolve(data));
13
- stream.on('error', reject);
14
- });
15
- }
@@ -1,38 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const node_test_1 = require("node:test");
7
- const faker_1 = require("@faker-js/faker");
8
- const node_assert_1 = __importDefault(require("node:assert"));
9
- const src_1 = __importDefault(require("../src"));
10
- const node_stream_1 = require("node:stream");
11
- (0, node_test_1.describe)('simpleIMFParser', () => {
12
- (0, node_test_1.it)('Should parse valid message (string)', async () => {
13
- const headers = {
14
- 'Subject': faker_1.faker.lorem.sentence(),
15
- 'MESSAGE-ID': `${faker_1.faker.string.uuid()}@${faker_1.faker.internet.domainName()}`,
16
- 'from': `"${faker_1.faker.person.fullName()}" <${faker_1.faker.internet.email()}>`,
17
- 'To': `${faker_1.faker.person.fullName()} <${faker_1.faker.internet.email()}>`,
18
- };
19
- const headersString = Object.entries(headers).map(([key, value]) => `${key}: ${value}`).join('\r\n');
20
- const body = faker_1.faker.lorem.paragraphs(5, '\r\n');
21
- const full_email = `${headersString}\r\n\r\n${body}`;
22
- const email = await (0, src_1.default)(full_email, {});
23
- node_assert_1.default.ok(email.toString());
24
- });
25
- (0, node_test_1.it)('Should parse valid message (stream)', async () => {
26
- const headers = {
27
- 'from': `"${faker_1.faker.person.fullName()}" <${faker_1.faker.internet.email()}>`,
28
- 'To': `${faker_1.faker.person.fullName()} <${faker_1.faker.internet.email({ allowSpecialCharacters: true })}>`,
29
- 'Subject': faker_1.faker.lorem.sentence(),
30
- 'MESSAGE-ID': `${faker_1.faker.string.uuid()}@${faker_1.faker.internet.domainName()}`,
31
- };
32
- const headersString = Object.entries(headers).map(([key, value]) => `${key}: ${value}`).join('\r\n');
33
- const body = faker_1.faker.lorem.paragraphs(5, '\r\n');
34
- const full_email = `${headersString}\r\n\r\n${body}`;
35
- const email = await (0, src_1.default)(node_stream_1.Readable.from(full_email), {});
36
- node_assert_1.default.ok(email.toString());
37
- });
38
- });