mailfile 0.1.0
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 +21 -0
- package/README.md +203 -0
- package/dist/mailfile.cjs +2035 -0
- package/dist/mailfile.js +2037 -0
- package/dist/mailfile.min.js +30 -0
- package/package.json +84 -0
- package/src/cfb/index.js +4 -0
- package/src/cfb/read.js +221 -0
- package/src/cfb/write.js +262 -0
- package/src/errors.js +49 -0
- package/src/index.js +86 -0
- package/src/mapi/bag.js +195 -0
- package/src/mapi/index.js +6 -0
- package/src/mapi/tags.js +147 -0
- package/src/message.js +199 -0
- package/src/mime/build.js +100 -0
- package/src/mime/encodings.js +188 -0
- package/src/mime/headers.js +344 -0
- package/src/mime/index.js +12 -0
- package/src/mime/parse.js +153 -0
- package/src/msg/read.js +178 -0
- package/src/msg/write.js +124 -0
- package/src/rtf/deencapsulate.js +155 -0
- package/src/rtf/index.js +3 -0
- package/src/rtf/lzfu.js +67 -0
- package/src/util.js +59 -0
- package/types/cfb/index.d.ts +2 -0
- package/types/cfb/read.d.ts +70 -0
- package/types/cfb/write.d.ts +67 -0
- package/types/errors.d.ts +36 -0
- package/types/index.d.ts +73 -0
- package/types/mapi/bag.d.ts +77 -0
- package/types/mapi/index.d.ts +2 -0
- package/types/mapi/tags.d.ts +137 -0
- package/types/message.d.ts +94 -0
- package/types/mime/build.d.ts +27 -0
- package/types/mime/encodings.d.ts +52 -0
- package/types/mime/headers.d.ts +111 -0
- package/types/mime/index.d.ts +4 -0
- package/types/mime/parse.d.ts +43 -0
- package/types/msg/read.d.ts +26 -0
- package/types/msg/write.d.ts +6 -0
- package/types/rtf/deencapsulate.d.ts +23 -0
- package/types/rtf/index.d.ts +2 -0
- package/types/rtf/lzfu.d.ts +8 -0
- package/types/util.d.ts +25 -0
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A read-only view of one object's MAPI properties.
|
|
3
|
+
*
|
|
4
|
+
* Variable-length properties live in `__substg1.0_*` streams; fixed-length
|
|
5
|
+
* ones live in `__properties_version1.0`.
|
|
6
|
+
*/
|
|
7
|
+
export class PropertyBag {
|
|
8
|
+
/**
|
|
9
|
+
* @param {import('../cfb/read.js').CfbFile} cfb
|
|
10
|
+
* @param {object} storage Directory entry of the storage to read.
|
|
11
|
+
* @param {number} headerSize One of `HeaderSize.*`.
|
|
12
|
+
*/
|
|
13
|
+
constructor(cfb: import("../cfb/read.js").CfbFile, storage: object, headerSize: number);
|
|
14
|
+
/** @type {Record<string, Uint8Array>} keyed by 8-hex-digit tag */
|
|
15
|
+
vars: Record<string, Uint8Array>;
|
|
16
|
+
/** @type {Record<number, {type:number, lo:number, hi:number, i32:number}>} */
|
|
17
|
+
fixed: Record<number, {
|
|
18
|
+
type: number;
|
|
19
|
+
lo: number;
|
|
20
|
+
hi: number;
|
|
21
|
+
i32: number;
|
|
22
|
+
}>;
|
|
23
|
+
/** @type {object[]} Nested storages (recipients, attachments, embedded messages). */
|
|
24
|
+
subStorages: object[];
|
|
25
|
+
cfb: import("../cfb/read.js").CfbFile;
|
|
26
|
+
childMap: Record<string, import("../cfb/read.js").DirEntry>;
|
|
27
|
+
/** Encoding used for 8-bit string properties in this object. */
|
|
28
|
+
charset: any;
|
|
29
|
+
/**
|
|
30
|
+
* String property, preferring the Unicode variant.
|
|
31
|
+
* @param {number} id @returns {string}
|
|
32
|
+
*/
|
|
33
|
+
str(id: number): string;
|
|
34
|
+
/** @param {number} id @returns {Uint8Array|null} */
|
|
35
|
+
bin(id: number): Uint8Array | null;
|
|
36
|
+
/** @param {number} id @returns {number|null} */
|
|
37
|
+
int(id: number): number | null;
|
|
38
|
+
/** @param {number} id @returns {boolean|null} */
|
|
39
|
+
bool(id: number): boolean | null;
|
|
40
|
+
/** @param {number} id @returns {Date|null} */
|
|
41
|
+
date(id: number): Date | null;
|
|
42
|
+
/** @param {number} id @returns {boolean} */
|
|
43
|
+
has(id: number): boolean;
|
|
44
|
+
/** Every property id present on this object. @returns {number[]} */
|
|
45
|
+
ids(): number[];
|
|
46
|
+
/** Nested storages whose names match a prefix, in directory order. */
|
|
47
|
+
storagesMatching(re: any): any[];
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Accumulates properties and emits the streams for one object.
|
|
51
|
+
*/
|
|
52
|
+
export class PropertyWriter {
|
|
53
|
+
/**
|
|
54
|
+
* @param {import('../cfb/write.js').CfbNode} node Storage to write into.
|
|
55
|
+
* @param {number} headerSize One of `HeaderSize.*`.
|
|
56
|
+
*/
|
|
57
|
+
constructor(node: import("../cfb/write.js").CfbNode, headerSize: number);
|
|
58
|
+
node: import("../cfb/write.js").CfbNode;
|
|
59
|
+
headerSize: number;
|
|
60
|
+
entries: any[];
|
|
61
|
+
_entry(id: any, type: any, size: any, lo: any, hi: any): void;
|
|
62
|
+
/** @param {number} id @param {string} value */
|
|
63
|
+
str(id: number, value: string): this;
|
|
64
|
+
/** @param {number} id @param {Uint8Array} bytes */
|
|
65
|
+
bin(id: number, bytes: Uint8Array): this;
|
|
66
|
+
/** @param {number} id @param {number} v */
|
|
67
|
+
int32(id: number, v: number): this;
|
|
68
|
+
/** @param {number} id @param {boolean} v */
|
|
69
|
+
bool(id: number, v: boolean): this;
|
|
70
|
+
/** @param {number} id @param {Date} date */
|
|
71
|
+
time(id: number, date: Date): this;
|
|
72
|
+
/**
|
|
73
|
+
* Write `__properties_version1.0`.
|
|
74
|
+
* @param {(dv: DataView) => void} [headerFill] Fills the stream header.
|
|
75
|
+
*/
|
|
76
|
+
finish(headerFill?: (dv: DataView) => void): void;
|
|
77
|
+
}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/** @param {number} n @returns {string} */
|
|
2
|
+
export function hex4(n: number): string;
|
|
3
|
+
/** @param {number} n @returns {string} */
|
|
4
|
+
export function hex8(n: number): string;
|
|
5
|
+
/**
|
|
6
|
+
* Stream name for a variable-length property, e.g. `__substg1.0_0037001F`.
|
|
7
|
+
* @param {number} id
|
|
8
|
+
* @param {number} type
|
|
9
|
+
* @returns {string}
|
|
10
|
+
*/
|
|
11
|
+
export function tagName(id: number, type: number): string;
|
|
12
|
+
/**
|
|
13
|
+
* FILETIME (100ns ticks since 1601-01-01) -> Date.
|
|
14
|
+
* @param {number} lo @param {number} hi @returns {Date|null}
|
|
15
|
+
*/
|
|
16
|
+
export function filetimeToDate(lo: number, hi: number): Date | null;
|
|
17
|
+
/**
|
|
18
|
+
* Date -> FILETIME halves.
|
|
19
|
+
* @param {Date} date @returns {{lo: number, hi: number}}
|
|
20
|
+
*/
|
|
21
|
+
export function dateToFiletime(date: Date): {
|
|
22
|
+
lo: number;
|
|
23
|
+
hi: number;
|
|
24
|
+
};
|
|
25
|
+
export namespace PropId {
|
|
26
|
+
let SUBJECT: number;
|
|
27
|
+
let NORMALIZED_SUBJECT: number;
|
|
28
|
+
let BODY: number;
|
|
29
|
+
let RTF_COMPRESSED: number;
|
|
30
|
+
let HTML: number;
|
|
31
|
+
let MESSAGE_CLASS: number;
|
|
32
|
+
let TRANSPORT_HEADERS: number;
|
|
33
|
+
let CLIENT_SUBMIT_TIME: number;
|
|
34
|
+
let DELIVERY_TIME: number;
|
|
35
|
+
let LAST_MODIFICATION_TIME: number;
|
|
36
|
+
let CREATION_TIME: number;
|
|
37
|
+
let INTERNET_MESSAGE_ID: number;
|
|
38
|
+
let IN_REPLY_TO_ID: number;
|
|
39
|
+
let INTERNET_REFERENCES: number;
|
|
40
|
+
let DISPLAY_TO: number;
|
|
41
|
+
let DISPLAY_CC: number;
|
|
42
|
+
let DISPLAY_BCC: number;
|
|
43
|
+
let SENDER_NAME: number;
|
|
44
|
+
let SENDER_EMAIL: number;
|
|
45
|
+
let SENDER_ADDRTYPE: number;
|
|
46
|
+
let SENDER_SMTP: number;
|
|
47
|
+
let SENT_REP_NAME: number;
|
|
48
|
+
let SENT_REP_EMAIL: number;
|
|
49
|
+
let SENT_REP_ADDRTYPE: number;
|
|
50
|
+
let SENT_REP_SMTP: number;
|
|
51
|
+
let MESSAGE_FLAGS: number;
|
|
52
|
+
let HASATTACH: number;
|
|
53
|
+
let STORE_SUPPORT_MASK: number;
|
|
54
|
+
let INTERNET_CPID: number;
|
|
55
|
+
let MESSAGE_CODEPAGE: number;
|
|
56
|
+
let PRIORITY: number;
|
|
57
|
+
let IMPORTANCE: number;
|
|
58
|
+
let OBJECT_TYPE: number;
|
|
59
|
+
let DISPLAY_TYPE: number;
|
|
60
|
+
let ROWID: number;
|
|
61
|
+
let RECIPIENT_TYPE: number;
|
|
62
|
+
let DISPLAY_NAME: number;
|
|
63
|
+
let EMAIL_ADDRESS: number;
|
|
64
|
+
let ADDRTYPE: number;
|
|
65
|
+
let SMTP_ADDRESS: number;
|
|
66
|
+
let ATTACH_METHOD: number;
|
|
67
|
+
let ATTACH_DATA_BIN: number;
|
|
68
|
+
let ATTACH_LONG_FILENAME: number;
|
|
69
|
+
let ATTACH_FILENAME: number;
|
|
70
|
+
let ATTACH_EXTENSION: number;
|
|
71
|
+
let ATTACH_MIME_TAG: number;
|
|
72
|
+
let ATTACH_CONTENT_ID: number;
|
|
73
|
+
let ATTACH_SIZE: number;
|
|
74
|
+
let ATTACH_NUM: number;
|
|
75
|
+
let ATTACH_FLAGS: number;
|
|
76
|
+
let ATTACHMENT_HIDDEN: number;
|
|
77
|
+
let RENDERING_POSITION: number;
|
|
78
|
+
}
|
|
79
|
+
export namespace PropType {
|
|
80
|
+
let SHORT: number;
|
|
81
|
+
let LONG: number;
|
|
82
|
+
let FLOAT: number;
|
|
83
|
+
let DOUBLE: number;
|
|
84
|
+
let BOOLEAN: number;
|
|
85
|
+
let I8: number;
|
|
86
|
+
let STRING8: number;
|
|
87
|
+
let UNICODE: number;
|
|
88
|
+
let SYSTIME: number;
|
|
89
|
+
let BINARY: number;
|
|
90
|
+
let OBJECT: number;
|
|
91
|
+
}
|
|
92
|
+
export namespace RecipientType {
|
|
93
|
+
let TO: number;
|
|
94
|
+
let CC: number;
|
|
95
|
+
let BCC: number;
|
|
96
|
+
}
|
|
97
|
+
export namespace AttachMethod {
|
|
98
|
+
let NONE: number;
|
|
99
|
+
let BY_VALUE: number;
|
|
100
|
+
let BY_REFERENCE: number;
|
|
101
|
+
let EMBEDDED_MSG: number;
|
|
102
|
+
}
|
|
103
|
+
export namespace HeaderSize {
|
|
104
|
+
let TOP_LEVEL: number;
|
|
105
|
+
let EMBEDDED: number;
|
|
106
|
+
let RECIPIENT: number;
|
|
107
|
+
let ATTACHMENT: number;
|
|
108
|
+
}
|
|
109
|
+
/** CLSID written to the root entry of a .msg file. */
|
|
110
|
+
export const MSG_CLSID: Uint8Array<ArrayBuffer>;
|
|
111
|
+
/** Windows code page number -> WHATWG encoding label. */
|
|
112
|
+
export const CODEPAGES: {
|
|
113
|
+
20127: string;
|
|
114
|
+
28591: string;
|
|
115
|
+
28592: string;
|
|
116
|
+
28595: string;
|
|
117
|
+
28597: string;
|
|
118
|
+
28598: string;
|
|
119
|
+
28599: string;
|
|
120
|
+
28605: string;
|
|
121
|
+
65000: string;
|
|
122
|
+
65001: string;
|
|
123
|
+
1250: string;
|
|
124
|
+
1251: string;
|
|
125
|
+
1252: string;
|
|
126
|
+
1253: string;
|
|
127
|
+
1254: string;
|
|
128
|
+
1255: string;
|
|
129
|
+
1256: string;
|
|
130
|
+
1257: string;
|
|
131
|
+
1258: string;
|
|
132
|
+
932: string;
|
|
133
|
+
936: string;
|
|
134
|
+
949: string;
|
|
135
|
+
950: string;
|
|
136
|
+
874: string;
|
|
137
|
+
};
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A single email message, independent of its on-disk format.
|
|
3
|
+
*
|
|
4
|
+
* Fields are plain and mutable: read one in, change what you need, write the
|
|
5
|
+
* other out.
|
|
6
|
+
*/
|
|
7
|
+
export class Message {
|
|
8
|
+
/**
|
|
9
|
+
* Parse an Outlook `.msg` file.
|
|
10
|
+
* @param {Uint8Array} bytes
|
|
11
|
+
* @param {{lazy?: boolean}} [opts] `lazy` defers attachment byte extraction
|
|
12
|
+
* until `.data` is read — useful when you only want headers.
|
|
13
|
+
* @returns {Message}
|
|
14
|
+
*/
|
|
15
|
+
static fromMsg(bytes: Uint8Array, opts?: {
|
|
16
|
+
lazy?: boolean;
|
|
17
|
+
}): Message;
|
|
18
|
+
/**
|
|
19
|
+
* Parse an RFC 5322 `.eml` file.
|
|
20
|
+
* @param {Uint8Array} bytes
|
|
21
|
+
* @returns {Message}
|
|
22
|
+
*/
|
|
23
|
+
static fromEml(bytes: Uint8Array): Message;
|
|
24
|
+
/** @param {Partial<Message>} [data] */
|
|
25
|
+
constructor(data?: Partial<Message>);
|
|
26
|
+
/** @type {string} */
|
|
27
|
+
subject: string;
|
|
28
|
+
/** @type {Address} */
|
|
29
|
+
from: Address;
|
|
30
|
+
/** @type {Address[]} */
|
|
31
|
+
to: Address[];
|
|
32
|
+
/** @type {Address[]} */
|
|
33
|
+
cc: Address[];
|
|
34
|
+
/** @type {Address[]} */
|
|
35
|
+
bcc: Address[];
|
|
36
|
+
/** @type {Date|null} */
|
|
37
|
+
date: Date | null;
|
|
38
|
+
/** @type {string} */
|
|
39
|
+
messageId: string;
|
|
40
|
+
/** @type {string} */
|
|
41
|
+
inReplyTo: string;
|
|
42
|
+
/** @type {string} */
|
|
43
|
+
references: string;
|
|
44
|
+
/** @type {number|null} 0 low, 1 normal, 2 high. */
|
|
45
|
+
importance: number | null;
|
|
46
|
+
/** @type {string} MAPI message class, e.g. `IPM.Note`. */
|
|
47
|
+
messageClass: string;
|
|
48
|
+
/** @type {string} Plain-text body. */
|
|
49
|
+
text: string;
|
|
50
|
+
/** @type {string} HTML body. */
|
|
51
|
+
html: string;
|
|
52
|
+
/** @type {Attachment[]} */
|
|
53
|
+
attachments: Attachment[];
|
|
54
|
+
/** @type {Headers} Original internet headers, when the source had them. */
|
|
55
|
+
headers: Headers;
|
|
56
|
+
/**
|
|
57
|
+
* Raw MAPI property access — present only for messages read from `.msg`.
|
|
58
|
+
* Use it to reach properties this model does not surface (appointments,
|
|
59
|
+
* contacts, custom properties).
|
|
60
|
+
* @type {import('./mapi/bag.js').PropertyBag|null}
|
|
61
|
+
*/
|
|
62
|
+
props: import("./mapi/bag.js").PropertyBag | null;
|
|
63
|
+
/**
|
|
64
|
+
* Serialise to an RFC 5322 `.eml` document.
|
|
65
|
+
*
|
|
66
|
+
* Headers carried in from the source are preserved verbatim — minus the
|
|
67
|
+
* content headers, which are regenerated to match the body actually written.
|
|
68
|
+
* @returns {Uint8Array}
|
|
69
|
+
*/
|
|
70
|
+
toEml(): Uint8Array;
|
|
71
|
+
/**
|
|
72
|
+
* Serialise to an Outlook `.msg` file.
|
|
73
|
+
* @returns {Uint8Array}
|
|
74
|
+
*/
|
|
75
|
+
toMsg(): Uint8Array;
|
|
76
|
+
}
|
|
77
|
+
export type Address = {
|
|
78
|
+
name: string;
|
|
79
|
+
email: string;
|
|
80
|
+
};
|
|
81
|
+
export type Attachment = {
|
|
82
|
+
filename: string;
|
|
83
|
+
mime: string;
|
|
84
|
+
data: Uint8Array;
|
|
85
|
+
/**
|
|
86
|
+
* Content-ID, without angle brackets.
|
|
87
|
+
*/
|
|
88
|
+
cid?: string;
|
|
89
|
+
/**
|
|
90
|
+
* True when referenced from the HTML body by cid.
|
|
91
|
+
*/
|
|
92
|
+
inline?: boolean;
|
|
93
|
+
};
|
|
94
|
+
import { Headers } from './mime/headers.js';
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Build an `.eml` document.
|
|
3
|
+
*
|
|
4
|
+
* Structure is chosen from what is present: `multipart/alternative` for a
|
|
5
|
+
* text+html pair, wrapped in `multipart/related` when there are inline
|
|
6
|
+
* (cid-referenced) parts, wrapped again in `multipart/mixed` for ordinary
|
|
7
|
+
* attachments.
|
|
8
|
+
*
|
|
9
|
+
* @param {object} msg
|
|
10
|
+
* @param {Array<[string,string]>} [msg.headers] Emitted before the MIME headers.
|
|
11
|
+
* @param {string} [msg.text]
|
|
12
|
+
* @param {string} [msg.html]
|
|
13
|
+
* @param {Array<{filename: string, mime: string, data: Uint8Array, cid?: string, inline?: boolean}>} [msg.attachments]
|
|
14
|
+
* @returns {Uint8Array}
|
|
15
|
+
*/
|
|
16
|
+
export function buildEml(msg: {
|
|
17
|
+
headers?: Array<[string, string]>;
|
|
18
|
+
text?: string;
|
|
19
|
+
html?: string;
|
|
20
|
+
attachments?: Array<{
|
|
21
|
+
filename: string;
|
|
22
|
+
mime: string;
|
|
23
|
+
data: Uint8Array;
|
|
24
|
+
cid?: string;
|
|
25
|
+
inline?: boolean;
|
|
26
|
+
}>;
|
|
27
|
+
}): Uint8Array;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param {Uint8Array} bytes
|
|
3
|
+
* @returns {string}
|
|
4
|
+
*/
|
|
5
|
+
export function bytesToBase64(bytes: Uint8Array): string;
|
|
6
|
+
/**
|
|
7
|
+
* Tolerant base64 decoder: ignores whitespace and any non-alphabet bytes.
|
|
8
|
+
* @param {string} str
|
|
9
|
+
* @returns {Uint8Array}
|
|
10
|
+
*/
|
|
11
|
+
export function base64ToBytes(str: string): Uint8Array;
|
|
12
|
+
/**
|
|
13
|
+
* @param {string} str
|
|
14
|
+
* @param {number} width
|
|
15
|
+
* @returns {string}
|
|
16
|
+
*/
|
|
17
|
+
export function wrap(str: string, width: number): string;
|
|
18
|
+
/**
|
|
19
|
+
* @param {string} s
|
|
20
|
+
* @returns {Uint8Array}
|
|
21
|
+
*/
|
|
22
|
+
export function utf8Encode(s: string): Uint8Array;
|
|
23
|
+
/**
|
|
24
|
+
* Decode bytes using a named charset, falling back to windows-1252 for
|
|
25
|
+
* labels the runtime does not know. Real-world mail mislabels constantly,
|
|
26
|
+
* so this never throws.
|
|
27
|
+
* @param {Uint8Array} bytes
|
|
28
|
+
* @param {string} [charset]
|
|
29
|
+
* @returns {string}
|
|
30
|
+
*/
|
|
31
|
+
export function decodeBytes(bytes: Uint8Array, charset?: string): string;
|
|
32
|
+
/**
|
|
33
|
+
* @param {Uint8Array} bytes
|
|
34
|
+
* @returns {string}
|
|
35
|
+
*/
|
|
36
|
+
export function utf16Decode(bytes: Uint8Array): string;
|
|
37
|
+
/**
|
|
38
|
+
* @param {string} str
|
|
39
|
+
* @returns {Uint8Array}
|
|
40
|
+
*/
|
|
41
|
+
export function utf16Encode(str: string): Uint8Array;
|
|
42
|
+
/**
|
|
43
|
+
* @param {string} str
|
|
44
|
+
* @param {boolean} [isHeaderWord] Treat `_` as space (RFC 2047 Q encoding).
|
|
45
|
+
* @returns {Uint8Array}
|
|
46
|
+
*/
|
|
47
|
+
export function decodeQP(str: string, isHeaderWord?: boolean): Uint8Array;
|
|
48
|
+
/**
|
|
49
|
+
* @param {Uint8Array} bytes
|
|
50
|
+
* @returns {string}
|
|
51
|
+
*/
|
|
52
|
+
export function encodeQP(bytes: Uint8Array): string;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {object} Address
|
|
3
|
+
* @property {string} name Display name, already decoded.
|
|
4
|
+
* @property {string} email
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Decode RFC 2047 encoded words (`=?UTF-8?B?...?=`) anywhere in a string.
|
|
8
|
+
* @param {string} str
|
|
9
|
+
* @returns {string}
|
|
10
|
+
*/
|
|
11
|
+
export function decodeWords(str: string): string;
|
|
12
|
+
/**
|
|
13
|
+
* @param {string} s
|
|
14
|
+
* @returns {boolean}
|
|
15
|
+
*/
|
|
16
|
+
export function needsEncoding(s: string): boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Encode a string as one or more RFC 2047 words, if it needs it.
|
|
19
|
+
* @param {string} s
|
|
20
|
+
* @returns {string}
|
|
21
|
+
*/
|
|
22
|
+
export function encodeWord(s: string): string;
|
|
23
|
+
/**
|
|
24
|
+
* Fold a long header onto continuation lines.
|
|
25
|
+
* @param {string} name
|
|
26
|
+
* @param {string} value
|
|
27
|
+
* @returns {string}
|
|
28
|
+
*/
|
|
29
|
+
export function foldHeader(name: string, value: string): string;
|
|
30
|
+
/**
|
|
31
|
+
* @param {string} name
|
|
32
|
+
* @param {string} email
|
|
33
|
+
* @returns {string}
|
|
34
|
+
*/
|
|
35
|
+
export function formatAddress(name: string, email: string): string;
|
|
36
|
+
/**
|
|
37
|
+
* @param {string} str
|
|
38
|
+
* @returns {Address}
|
|
39
|
+
*/
|
|
40
|
+
export function parseAddress(str: string): Address;
|
|
41
|
+
/**
|
|
42
|
+
* @param {string} str
|
|
43
|
+
* @returns {Address[]}
|
|
44
|
+
*/
|
|
45
|
+
export function parseAddressList(str: string): Address[];
|
|
46
|
+
/**
|
|
47
|
+
* Parse a structured header into its value and parameters, reassembling
|
|
48
|
+
* RFC 2231 continuations and percent-encoding (`filename*0*=`, `filename*=`).
|
|
49
|
+
* @param {string} raw
|
|
50
|
+
* @returns {{value: string, params: Record<string, string>}}
|
|
51
|
+
*/
|
|
52
|
+
export function parseHeaderValue(raw: string): {
|
|
53
|
+
value: string;
|
|
54
|
+
params: Record<string, string>;
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* Emit a parameter, using RFC 2231 with an ASCII fallback when non-ASCII.
|
|
58
|
+
* @param {string} name
|
|
59
|
+
* @param {string} val
|
|
60
|
+
* @returns {string}
|
|
61
|
+
*/
|
|
62
|
+
export function encodeParamValue(name: string, val: string): string;
|
|
63
|
+
/**
|
|
64
|
+
* Format a Date as an RFC 5322 date-time in local time.
|
|
65
|
+
* @param {Date} d
|
|
66
|
+
* @returns {string}
|
|
67
|
+
*/
|
|
68
|
+
export function formatDate(d: Date): string;
|
|
69
|
+
/**
|
|
70
|
+
* Parse an RFC 5322 date, tolerating a trailing `(GMT)`-style comment.
|
|
71
|
+
* @param {string} str
|
|
72
|
+
* @returns {Date|null}
|
|
73
|
+
*/
|
|
74
|
+
export function parseDate(str: string): Date | null;
|
|
75
|
+
/**
|
|
76
|
+
* An ordered, case-insensitive, repeat-preserving header collection.
|
|
77
|
+
*/
|
|
78
|
+
export class Headers {
|
|
79
|
+
/**
|
|
80
|
+
* Parse a raw header block. Continuation lines are unfolded.
|
|
81
|
+
* @param {string} text
|
|
82
|
+
* @returns {Headers}
|
|
83
|
+
*/
|
|
84
|
+
static parse(text: string): Headers;
|
|
85
|
+
/** @param {Array<[string, string]>} [entries] */
|
|
86
|
+
constructor(entries?: Array<[string, string]>);
|
|
87
|
+
/** @type {Array<[string, string]>} */
|
|
88
|
+
entries: Array<[string, string]>;
|
|
89
|
+
/** @param {string} name @returns {string|null} First matching value. */
|
|
90
|
+
get(name: string): string | null;
|
|
91
|
+
/** @param {string} name @returns {string[]} Every matching value, in order. */
|
|
92
|
+
getAll(name: string): string[];
|
|
93
|
+
/** @param {string} name @returns {boolean} */
|
|
94
|
+
has(name: string): boolean;
|
|
95
|
+
/** Replace all occurrences with a single value. @param {string} name @param {string} value */
|
|
96
|
+
set(name: string, value: string): this;
|
|
97
|
+
/** Append without removing existing occurrences. @param {string} name @param {string} value */
|
|
98
|
+
add(name: string, value: string): this;
|
|
99
|
+
/** @param {string} name */
|
|
100
|
+
delete(name: string): this;
|
|
101
|
+
/** Header block as text, with folding applied. @returns {string} */
|
|
102
|
+
get raw(): string;
|
|
103
|
+
[Symbol.iterator](): ArrayIterator<[string, string]>;
|
|
104
|
+
}
|
|
105
|
+
export type Address = {
|
|
106
|
+
/**
|
|
107
|
+
* Display name, already decoded.
|
|
108
|
+
*/
|
|
109
|
+
name: string;
|
|
110
|
+
email: string;
|
|
111
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { buildEml } from "./build.js";
|
|
2
|
+
export { parseEml, parseNode } from "./parse.js";
|
|
3
|
+
export { Headers, decodeWords, encodeWord, foldHeader, formatAddress, formatDate, parseAddress, parseAddressList, parseDate, parseHeaderValue, encodeParamValue, needsEncoding } from "./headers.js";
|
|
4
|
+
export { base64ToBytes, bytesToBase64, decodeBytes, decodeQP, encodeQP, utf8Encode, utf16Decode, utf16Encode, wrap } from "./encodings.js";
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parse a MIME entity and its children.
|
|
3
|
+
* @param {Uint8Array} bytes
|
|
4
|
+
* @param {number} [depth]
|
|
5
|
+
* @returns {MimeNode}
|
|
6
|
+
*/
|
|
7
|
+
export function parseNode(bytes: Uint8Array, depth?: number): MimeNode;
|
|
8
|
+
/**
|
|
9
|
+
* Parse a complete `.eml` document.
|
|
10
|
+
* @param {Uint8Array} bytes
|
|
11
|
+
* @returns {ParsedEml}
|
|
12
|
+
*/
|
|
13
|
+
export function parseEml(bytes: Uint8Array): ParsedEml;
|
|
14
|
+
export type MimeNode = {
|
|
15
|
+
headers: Headers;
|
|
16
|
+
/**
|
|
17
|
+
* Lower-cased, without parameters.
|
|
18
|
+
*/
|
|
19
|
+
contentType: string;
|
|
20
|
+
params: Record<string, string>;
|
|
21
|
+
children: MimeNode[];
|
|
22
|
+
/**
|
|
23
|
+
* Decoded body, for leaf nodes only.
|
|
24
|
+
*/
|
|
25
|
+
content?: Uint8Array;
|
|
26
|
+
};
|
|
27
|
+
export type ParsedEml = {
|
|
28
|
+
/**
|
|
29
|
+
* Top-level headers.
|
|
30
|
+
*/
|
|
31
|
+
headers: Headers;
|
|
32
|
+
text: string;
|
|
33
|
+
html: string;
|
|
34
|
+
attachments: Array<{
|
|
35
|
+
filename: string;
|
|
36
|
+
mime: string;
|
|
37
|
+
data: Uint8Array;
|
|
38
|
+
cid: string;
|
|
39
|
+
inline: boolean;
|
|
40
|
+
}>;
|
|
41
|
+
root: MimeNode;
|
|
42
|
+
};
|
|
43
|
+
import { Headers } from './headers.js';
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Read a `.msg` file into plain message data.
|
|
3
|
+
* @param {Uint8Array} bytes
|
|
4
|
+
* @param {{lazy?: boolean}} [opts]
|
|
5
|
+
*/
|
|
6
|
+
export function readMsg(bytes: Uint8Array, opts?: {
|
|
7
|
+
lazy?: boolean;
|
|
8
|
+
}): {
|
|
9
|
+
messageClass: string;
|
|
10
|
+
subject: string;
|
|
11
|
+
messageId: string;
|
|
12
|
+
inReplyTo: string;
|
|
13
|
+
references: string;
|
|
14
|
+
date: Date;
|
|
15
|
+
importance: number;
|
|
16
|
+
text: string;
|
|
17
|
+
html: string;
|
|
18
|
+
to: any[];
|
|
19
|
+
cc: any[];
|
|
20
|
+
bcc: any[];
|
|
21
|
+
attachments: any[];
|
|
22
|
+
headers: Headers;
|
|
23
|
+
props: PropertyBag;
|
|
24
|
+
};
|
|
25
|
+
import { Headers } from '../mime/headers.js';
|
|
26
|
+
import { PropertyBag } from '../mapi/bag.js';
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param {string} rtf
|
|
3
|
+
* @returns {boolean} True if this RTF carries encapsulated HTML or text.
|
|
4
|
+
*/
|
|
5
|
+
export function isEncapsulated(rtf: string): boolean;
|
|
6
|
+
/**
|
|
7
|
+
* Walk the RTF and emit the original HTML.
|
|
8
|
+
*
|
|
9
|
+
* `\*\htmltag` destinations hold the real markup; `\htmlrtf`/`\htmlrtf0`
|
|
10
|
+
* brackets the RTF-only rendering text that must be dropped.
|
|
11
|
+
*
|
|
12
|
+
* @param {string} rtf RTF as raw bytes widened to chars (one char per byte).
|
|
13
|
+
* @param {(bytes: Uint8Array) => string} decode Code-page decoder.
|
|
14
|
+
* @returns {string}
|
|
15
|
+
*/
|
|
16
|
+
export function deencapsulate(rtf: string, decode: (bytes: Uint8Array) => string): string;
|
|
17
|
+
/**
|
|
18
|
+
* Convenience wrapper: decompressed RTF bytes in, HTML out.
|
|
19
|
+
* @param {Uint8Array} rtfBytes
|
|
20
|
+
* @param {(bytes: Uint8Array) => string} decode
|
|
21
|
+
* @returns {string|null} null when the RTF does not encapsulate HTML.
|
|
22
|
+
*/
|
|
23
|
+
export function rtfToHtml(rtfBytes: Uint8Array, decode: (bytes: Uint8Array) => string): string | null;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Decompress a PR_RTF_COMPRESSED stream.
|
|
3
|
+
* Handles both the compressed ("LZFu") and stored ("MELA") containers.
|
|
4
|
+
*
|
|
5
|
+
* @param {Uint8Array} bytes
|
|
6
|
+
* @returns {Uint8Array|null} RTF bytes, or null if this is not an RTF container.
|
|
7
|
+
*/
|
|
8
|
+
export function decompress(bytes: Uint8Array): Uint8Array | null;
|
package/types/util.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Guess a content type from a filename extension.
|
|
3
|
+
* @param {string} name
|
|
4
|
+
* @returns {string}
|
|
5
|
+
*/
|
|
6
|
+
export function guessMime(name: string): string;
|
|
7
|
+
/**
|
|
8
|
+
* Strip path separators and characters that are illegal in filenames.
|
|
9
|
+
* @param {string} s
|
|
10
|
+
* @returns {string}
|
|
11
|
+
*/
|
|
12
|
+
export function safeName(s: string): string;
|
|
13
|
+
/**
|
|
14
|
+
* An 8.3-style short name for PR_ATTACH_FILENAME.
|
|
15
|
+
* @param {string} name
|
|
16
|
+
* @returns {string}
|
|
17
|
+
*/
|
|
18
|
+
export function shortName(name: string): string;
|
|
19
|
+
/**
|
|
20
|
+
* Replace the extension on a filename.
|
|
21
|
+
* @param {string} name
|
|
22
|
+
* @param {string} ext Including the dot.
|
|
23
|
+
* @returns {string}
|
|
24
|
+
*/
|
|
25
|
+
export function replaceExt(name: string, ext: string): string;
|