eml-parser-qaap 1.1.15

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 Bean
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,55 @@
1
+ # eml-parse-vqaap
2
+
3
+ # srjikMou
4
+
5
+ [RFC 822](https://www.w3.org/Protocols/rfc822/) EML file format parser and builder, Can be used in browser environment
6
+
7
+ > fork from `eml-parse-vqaap`(used in Browser env) & `eml-format` (used in NodeJs env)
8
+
9
+ 1. fix `eml-parse-vqaap` for parsing html from the eml with `quoted-printable`
10
+ 2. add `data` with `base64` in attachment
11
+
12
+ ## start guide
13
+
14
+ ```javascript
15
+ import { parseEml, readEml, GBKUTF8, decode } from 'eml-parse-vqaap';
16
+
17
+ // const eml = await axios(http | ajax).get()
18
+ // `.eml` file
19
+ readEml(eml, (err, ReadEmlJson) => {});
20
+ ```
21
+
22
+ ## @types
23
+
24
+ ```typescript
25
+ interface Attachment {
26
+ name: string;
27
+ contentType: string;
28
+ inline: boolean;
29
+ data: string | Uint8Array;
30
+ data64: string;
31
+ filename?: string;
32
+ mimeType?: string;
33
+ id?: string;
34
+ cid?: string;
35
+ }
36
+
37
+ interface ReadEmlJson {
38
+ attachments: Attachment;
39
+ date: Date | string;
40
+ subject: string;
41
+ from: EmailAddress | EmailAddress[] | null;
42
+ to: EmailAddress | EmailAddress[] | null;
43
+ cc?: EmailAddress | EmailAddress[] | null;
44
+ headers: EmlHeaders;
45
+ multipartAlternative?: {
46
+ 'Content-Type': string;
47
+ };
48
+ text?: string;
49
+ textheaders?: BoundaryHeaders;
50
+ html?: string; // email html data
51
+ htmlheaders?: BoundaryHeaders;
52
+ attachments?: Attachment[];
53
+ data?: string;
54
+ }
55
+ ```
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Creates a Tokenizer object for tokenizing address field strings
3
+ *
4
+ * @constructor
5
+ * @param {String} str Address field string
6
+ */
7
+ export declare class Tokenizer {
8
+ str: string;
9
+ operatorCurrent: string;
10
+ operatorExpecting: string;
11
+ node: any;
12
+ escaped: boolean;
13
+ list: any[];
14
+ operators: any;
15
+ constructor(str: any);
16
+ /**
17
+ * Tokenizes the original input string
18
+ *
19
+ * @return {Array} An array of operator|text tokens
20
+ */
21
+ tokenize(): any[];
22
+ /**
23
+ * Checks if a character is an operator or text and acts accordingly
24
+ *
25
+ * @param {String} chr Character from the address field
26
+ */
27
+ checkChar(chr: any): void;
28
+ }
29
+ /**
30
+ * Parses structured e-mail addresses from an address field
31
+ *
32
+ * Example:
33
+ *
34
+ * 'Name <address@domain>'
35
+ *
36
+ * will be converted to
37
+ *
38
+ * [{name: 'Name', address: 'address@domain'}]
39
+ *
40
+ * @param {String} str Address field
41
+ * @return {Array} An array of address objects
42
+ */
43
+ export declare function addressparser(str: any, options?: any): {
44
+ name?: string;
45
+ address?: string;
46
+ }[];
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Encodes an unicode string into an Uint8Array object as UTF-8
3
+ *
4
+ * @param {String} str String to be encoded
5
+ * @return {Uint8Array} UTF-8 encoded typed array
6
+ */
7
+ export declare const encode: (str: string, fromCharset?: string) => Uint8Array;
8
+ export declare const arr2str: (arr: Uint8Array) => string;
9
+ /**
10
+ * Decodes a string from Uint8Array to an unicode string using specified encoding
11
+ *
12
+ * @param {Uint8Array} buf Binary data to be decoded
13
+ * @param {String} Binary data is decoded into string using this charset
14
+ * @return {String} Decoded string
15
+ */
16
+ export declare function decode(buf: Uint8Array, fromCharset?: string): string;
17
+ /**
18
+ * Convert a string from specific encoding to UTF-8 Uint8Array
19
+ *
20
+ * @param {String|Uint8Array} data Data to be encoded
21
+ * @param {String} Source encoding for the string (optional for data of type String)
22
+ * @return {Uint8Array} UTF-8 encoded typed array
23
+ */
24
+ export declare const convert: (data: string | Uint8Array, fromCharset?: string | undefined) => Uint8Array;
@@ -0,0 +1,76 @@
1
+ /**
2
+ * @author superchow
3
+ * @emil superchow@live.cn
4
+ */
5
+ import { Base64 } from 'js-base64';
6
+ import { convert, decode, encode } from './charset';
7
+ import { GB2312UTF8, mimeDecode, getBoundary } from './utils';
8
+ import { EmailAddress, ParsedEmlJson, ReadedEmlJson, BuildOptions, CallbackFn, OptionOrNull, BoundaryRawData, BoundaryConvertedData } from './interface';
9
+ /**
10
+ * create a boundary
11
+ */
12
+ declare function createBoundary(): string;
13
+ /**
14
+ * Builds e-mail address string, e.g. { name: 'PayPal', email: 'noreply@paypal.com' } => 'PayPal' <noreply@paypal.com>
15
+ * @param {String|EmailAddress|EmailAddress[]|null} data
16
+ */
17
+ declare function toEmailAddress(data?: string | EmailAddress | EmailAddress[] | null): string;
18
+ /**
19
+ * Gets character set name, e.g. contentType='.....charset='iso-8859-2'....'
20
+ * @param {String} contentType
21
+ * @returns {String|undefined}
22
+ */
23
+ declare function getCharset(contentType: string): string | undefined;
24
+ /**
25
+ * Gets name and e-mail address from a string, e.g. 'PayPal' <noreply@paypal.com> => { name: 'PayPal', email: 'noreply@paypal.com' }
26
+ * @param {String} raw
27
+ * @returns { EmailAddress | EmailAddress[] | null}
28
+ */
29
+ declare function getEmailAddress(rawStr: string): EmailAddress | EmailAddress[] | null;
30
+ /**
31
+ * decode section
32
+ * @param {String} str
33
+ * @returns {String}
34
+ */
35
+ declare function unquoteString(str: string): string;
36
+ /**
37
+ * Decodes 'quoted-printable'
38
+ * @param {String} value
39
+ * @param {String} charset
40
+ * @param {String} qEncoding whether the encoding is RFC-2047’s Q-encoding, meaning special handling of underscores.
41
+ * @returns {String}
42
+ */
43
+ declare function unquotePrintable(value: string, charset?: string, qEncoding?: boolean): string;
44
+ /**
45
+ * Parses EML file content and returns object-oriented representation of the content.
46
+ * @param {String} eml
47
+ * @param {OptionOrNull | CallbackFn<ParsedEmlJson>} options
48
+ * @param {CallbackFn<ParsedEmlJson>} callback
49
+ * @returns {string | Error | ParsedEmlJson}
50
+ */
51
+ declare function parse(eml: string, options?: OptionOrNull | CallbackFn<ParsedEmlJson>, callback?: CallbackFn<ParsedEmlJson>): string | Error | ParsedEmlJson;
52
+ /**
53
+ * Convert BoundaryRawData to BoundaryConvertedData
54
+ * @param {BoundaryRawData} boundary
55
+ * @returns {BoundaryConvertedData} Obj
56
+ */
57
+ declare function completeBoundary(boundary: BoundaryRawData): BoundaryConvertedData | null;
58
+ /**
59
+ * buid EML file by ReadedEmlJson or EML file content
60
+ * @param {ReadedEmlJson} data
61
+ * @param {BuildOptions | CallbackFn<string> | null} options
62
+ * @param {CallbackFn<string>} callback
63
+ */
64
+ declare function build(data: ReadedEmlJson | string, options?: BuildOptions | CallbackFn<string> | null, callback?: CallbackFn<string>): string | Error;
65
+ /**
66
+ * Parses EML file content and return user-friendly object.
67
+ * @param {String | ParsedEmlJson} eml EML file content or object from 'parse'
68
+ * @param { OptionOrNull | CallbackFn<ReadedEmlJson>} options EML parse options
69
+ * @param {CallbackFn<ReadedEmlJson>} callback Callback function(error, data)
70
+ */
71
+ declare function read(eml: string | ParsedEmlJson, options?: OptionOrNull | CallbackFn<ReadedEmlJson>, callback?: CallbackFn<ReadedEmlJson>): ReadedEmlJson | Error | string;
72
+ /**
73
+ * if you need
74
+ * eml-format all api
75
+ */
76
+ export { getEmailAddress, toEmailAddress, createBoundary, getBoundary, getCharset, unquoteString, unquotePrintable, mimeDecode, Base64, convert, encode, decode, completeBoundary, parse as parseEml, read as readEml, build as buildEml, GB2312UTF8 as GBKUTF8, };
@@ -0,0 +1,103 @@
1
+ export interface KeyValue extends Object {
2
+ [k: string]: any;
3
+ }
4
+ export interface EmailAddress {
5
+ name: string;
6
+ email: string;
7
+ }
8
+ /**
9
+ * parse result
10
+ */
11
+ export interface ParsedEmlJson {
12
+ headers: EmlHeaders;
13
+ body?: string | (BoundaryConvertedData | null)[];
14
+ }
15
+ /**
16
+ * read result
17
+ */
18
+ export interface ReadedEmlJson {
19
+ date: Date | string;
20
+ subject: string;
21
+ from: EmailAddress | EmailAddress[] | null;
22
+ to: EmailAddress | EmailAddress[] | null;
23
+ cc?: EmailAddress | EmailAddress[] | null;
24
+ headers: EmlHeaders;
25
+ multipartAlternative?: {
26
+ 'Content-Type': string;
27
+ };
28
+ text?: string;
29
+ textheaders?: BoundaryHeaders;
30
+ html?: string;
31
+ htmlheaders?: BoundaryHeaders;
32
+ attachments?: Attachment[];
33
+ data?: string;
34
+ }
35
+ /**
36
+ * Attachment file
37
+ */
38
+ export interface Attachment {
39
+ name: string;
40
+ contentType: string;
41
+ inline: boolean;
42
+ data: string | Uint8Array;
43
+ data64: string;
44
+ filename?: string;
45
+ mimeType?: string;
46
+ id?: string;
47
+ qaapId?: string;
48
+ cid?: string;
49
+ }
50
+ /**
51
+ * EML headers
52
+ * @description `MIME-Version`, `Accept-Language`, `Content-Language` and `Content-Type` shuld Must exist when to build a EML file
53
+ */
54
+ export interface EmlHeaders extends KeyValue {
55
+ Date?: string;
56
+ Subject?: string;
57
+ From?: string;
58
+ To?: string;
59
+ Cc?: string;
60
+ CC?: string;
61
+ 'Content-Disposition'?: string | null;
62
+ 'Content-Type'?: string | null;
63
+ 'Content-Transfer-Encoding'?: string;
64
+ 'MIME-Version'?: string;
65
+ 'Content-ID'?: string;
66
+ 'Accept-Language'?: string;
67
+ 'Content-Language'?: string;
68
+ 'Content-type'?: string | null;
69
+ 'Content-transfer-encoding'?: string;
70
+ }
71
+ export interface Options {
72
+ headersOnly: boolean;
73
+ }
74
+ /**
75
+ * encode is not realized yet
76
+ */
77
+ export interface BuildOptions extends Options {
78
+ encode?: boolean;
79
+ }
80
+ export declare type CallbackFn<T> = (error: any, result?: T) => void;
81
+ export declare type OptionOrNull = Options | null;
82
+ /**
83
+ * BoundaryRawData
84
+ */
85
+ export interface BoundaryRawData {
86
+ boundary: string;
87
+ lines: string[];
88
+ }
89
+ /**
90
+ * Convert BoundaryRawData result
91
+ */
92
+ export interface BoundaryConvertedData {
93
+ boundary: string;
94
+ part: {
95
+ headers: BoundaryHeaders;
96
+ body: string | Array<BoundaryConvertedData | string>;
97
+ };
98
+ }
99
+ export interface BoundaryHeaders extends KeyValue {
100
+ 'Content-Type': string;
101
+ 'Content-Transfer-Encoding'?: string;
102
+ 'Content-Disposition'?: string;
103
+ }
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Gets the boundary name
3
+ * @param contentType - string
4
+ */
5
+ export declare function getBoundary(contentType: string): string | undefined;
6
+ export declare function getCharsetName(charset: string): string;
7
+ export declare function guid(): string;
8
+ export declare function wrap(s: string, i: number): string;
9
+ /**
10
+ * Decodes mime encoded string to an unicode string
11
+ *
12
+ * @param {String} str Mime encoded string
13
+ * @param {String} [fromCharset='UTF-8'] Source encoding
14
+ * @return {String} Decoded unicode string
15
+ */
16
+ export declare function mimeDecode(str?: string, fromCharset?: string): string;
17
+ /**
18
+ * adjust string Or Error
19
+ * @param param
20
+ */
21
+ export declare function isStringOrError(param: any): boolean;
22
+ /**
23
+ * converting strings from gbk to utf-8
24
+ */
25
+ export declare const GB2312UTF8: {
26
+ Dig2Dec: (s: string) => number;
27
+ Hex2Utf8: (s: string) => string;
28
+ Dec2Dig: (n1: number) => string;
29
+ Str2Hex: (s: string) => string;
30
+ GB2312ToUTF8: (s1: string) => string;
31
+ UTF8ToGB2312: (str1: string) => string;
32
+ };