forked from MQpeng/eml-parse-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.d.ts
212 lines (212 loc) · 5.49 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
export interface KeyValue extends Object {
[k: string]: any;
}
export interface EmailAddress {
name: string;
email: string;
}
/**
* parse result
*/
export interface ParsedEmlJson {
headers: EmlHeaders;
body?: string | (BoundaryConvertedData | null)[];
}
/**
* read result
*/
export interface ReadedEmlJson {
date: Date | string;
subject: string;
from: EmailAddress | EmailAddress[] | null;
to: EmailAddress | EmailAddress[] | null;
cc?: EmailAddress | EmailAddress[] | null;
headers: EmlHeaders;
multipartAlternative?: {
'Content-Type': string;
};
text?: string;
textheaders?: BoundaryHeaders;
html?: string;
htmlheaders?: BoundaryHeaders;
attachments?: Attachment[];
data?: string;
}
/**
* Attachment file
*/
export interface Attachment {
name: string;
contentType: string;
inline: boolean;
data: string | Uint8Array;
data64: string;
filename?: string;
mimeType?: string;
id?: string;
cid?: string;
}
/**
* EML headers
* @description `MIME-Version`, `Accept-Language`, `Content-Language` and `Content-Type` shuld Must exist when to build a EML file
*/
export interface EmlHeaders extends KeyValue {
Date?: string;
Subject?: string;
From?: string;
To?: string;
Cc?: string;
CC?: string;
'Content-Disposition'?: string | null;
'Content-Type'?: string | null;
'Content-Transfer-Encoding'?: string;
'MIME-Version'?: string;
'Content-ID'?: string;
'Accept-Language'?: string;
'Content-Language'?: string;
'Content-type'?: string | null;
'Content-transfer-encoding'?: string;
}
export interface Options {
headersOnly: boolean;
}
/**
* encode is not realized yet
*/
export interface BuildOptions extends Options {
encode?: boolean;
}
export declare type CallbackFn<T> = (error: any, result?: T) => void;
export declare type OptionOrNull = Options | null;
/**
* BoundaryRawData
*/
export interface BoundaryRawData {
boundary: string;
lines: string[];
}
/**
* Convert BoundaryRawData result
*/
export interface BoundaryConvertedData {
boundary: string;
part: {
headers: BoundaryHeaders;
body: string | Array<BoundaryConvertedData | string>;
};
}
export interface BoundaryHeaders extends KeyValue {
'Content-Type': string;
'Content-Transfer-Encoding'?: string;
'Content-Disposition'?: string;
}
/**
* @author superchow
* @emil superchow@live.cn
*/
import { Base64 } from 'js-base64';
import { convert, decode, encode } from './charset';
import { GB2312UTF8, mimeDecode } from './utils';
/**
* create a boundary
*/
declare function createBoundary(): string;
/**
* Builds e-mail address string, e.g. { name: 'PayPal', email: 'noreply@paypal.com' } => 'PayPal' <noreply@paypal.com>
* @param {String|EmailAddress|EmailAddress[]|null} data
*/
declare function toEmailAddress(data?: string | EmailAddress | EmailAddress[] | null): string;
/**
* Gets the boundary name
* @param {String} contentType
* @returns {String|undefined}
*/
declare function getBoundary(contentType: string): string | undefined;
/**
* Gets character set name, e.g. contentType='.....charset='iso-8859-2'....'
* @param {String} contentType
* @returns {String|undefined}
*/
declare function getCharset(contentType: string): string | undefined;
/**
* Gets name and e-mail address from a string, e.g. 'PayPal' <noreply@paypal.com> => { name: 'PayPal', email: 'noreply@paypal.com' }
* @param {String} raw
* @returns { EmailAddress | EmailAddress[] | null}
*/
declare function getEmailAddress(raw: string): EmailAddress | EmailAddress[] | null;
/**
* decode section
* @param {String} str
* @returns {String}
*/
declare function unquoteString(str: string): string;
/**
* Decodes 'quoted-printable'
* @param {String} value
* @param {String} charset
* @returns {String}
*/
declare function unquotePrintable(value: string, charset?: string): string;
/**
* Parses EML file content and returns object-oriented representation of the content.
* @param {String} eml
* @param {OptionOrNull | CallbackFn<ParsedEmlJson>} options
* @param {CallbackFn<ParsedEmlJson>} callback
* @returns {string | Error | ParsedEmlJson}
*/
declare function parse(
eml: string,
options?: OptionOrNull | CallbackFn<ParsedEmlJson>,
callback?: CallbackFn<ParsedEmlJson>
): string | Error | ParsedEmlJson;
/**
* Convert BoundaryRawData to BoundaryConvertedData
* @param {BoundaryRawData} boundary
* @returns {BoundaryConvertedData} Obj
*/
declare function completeBoundary(boundary: BoundaryRawData): BoundaryConvertedData | null;
/**
* buid EML file by ReadedEmlJson or EML file content
* @param {ReadedEmlJson} data
* @param {BuildOptions | CallbackFn<string> | null} options
* @param {CallbackFn<string>} callback
*/
declare function build(
data: ReadedEmlJson | string,
options?: BuildOptions | CallbackFn<string> | null,
callback?: CallbackFn<string>
): string | Error;
/**
* Parses EML file content and return user-friendly object.
* @param {String | ParsedEmlJson} eml EML file content or object from 'parse'
* @param { OptionOrNull | CallbackFn<ReadedEmlJson>} options EML parse options
* @param {CallbackFn<ReadedEmlJson>} callback Callback function(error, data)
*/
declare function read(
eml: string | ParsedEmlJson,
options?: OptionOrNull | CallbackFn<ReadedEmlJson>,
callback?: CallbackFn<ReadedEmlJson>
): ReadedEmlJson | Error | string;
/**
* if you need
* eml-format all api
*/
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,
};