forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mailparser.d.ts
90 lines (75 loc) · 3.92 KB
/
mailparser.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
// Type definitions for mailparser v0.5.2
// Project: https://www.npmjs.com/package/mailparser
// Definitions by: Peter Snider <https://github.com/psnider/>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference path='../node/node.d.ts' />
declare module 'mailparser' {
import StreamModule = require("stream");
import Stream = StreamModule.Stream;
import WritableStream = NodeJS.WritableStream;
import EventEmitter = NodeJS.EventEmitter;
interface Options {
debug?: boolean; // if set to true print all incoming lines to console
streamAttachments?: boolean; // if set to true, stream attachments instead of including them
unescapeSMTP?: boolean; // if set to true replace double dots in the beginning of the file
defaultCharset?: string; // the default charset for text/plain and text/html content, if not set reverts to Latin-1
showAttachmentLinks?: boolean; // if set to true, show inlined attachment links <a href="cid:...">filename</a>
}
interface EmailAddress {
address: string;
name: string;
}
interface Attachment {
contentType: string;
fileName: string;
contentDisposition: string; // e.g. 'attachment'
contentId: string; // e.g. '5.1321281380971@localhost'
transferEncoding: string; // e.g. 'base64'
length: number; // length of the attachment in bytes
generatedFileName: string; // e.g. 'image.png'
checksum: string; // the md5 hash of the file, e.g. 'e4cef4c6e26037bcf8166905207ea09b'
content: Buffer; // possibly a SlowBuffer
stream: Stream; // a stream to read the attachment if streamAttachments is set to true
}
// emitted with the 'end' event
interface ParsedMail {
headers: any; // unprocessed headers in the form of - {key: value} - if there were multiple fields with the same key then the value is an array
from: EmailAddress[]; // should be only one though)
to: EmailAddress[];
cc?: EmailAddress[];
bcc?: EmailAddress[];
subject: string; // the subject line
references?: string[]; // an array of reference message id values (not set if no reference values present)
inReplyTo?: string[]; // an array of In-Reply-To message id values (not set if no in-reply-to values present)
priority?: string; // priority of the e-mail, always one of the following: normal (default), high, low
text: string; // text body
html: string; // html body
date?: Date; // If date could not be resolved or is not found this field is not set. Check the original date string from headers.date
attachments?: Attachment[];
}
class MailParser extends StreamModule.Writable {
constructor(options?: Options);
on(event: string, callback: (any: any) => void): this;
// from WritableStream
writable: boolean;
write(buffer: Buffer, cb?: Function): boolean;
write(str: string, cb?: Function): boolean;
write(str: string, encoding?: string, cb?: Function): boolean;
end(): void;
end(buffer: Buffer, cb?: Function): void;
end(str: string, cb?: Function): void;
end(str: string, encoding?: string, cb?: Function): void;
// from EventEmitter
static listenerCount(emitter: EventEmitter, event: string): number;
addListener(event: string, listener: Function): this;
on(event: string, listener: Function): this;
once(event: string, listener: Function): this;
removeListener(event: string, listener: Function): this;
removeAllListeners(event?: string): this;
setMaxListeners(n: number): this;
getMaxListeners(): number;
listeners(event: string): Function[];
emit(event: string, ...args: any[]): boolean;
listenerCount(type: string): number;
}
}