1
+ /// <reference path="./mailparser.d.ts" />
2
+
1
3
import mailparser_mod = require( "mailparser" ) ;
2
4
import MailParser = mailparser_mod . MailParser ;
3
5
import ParsedMail = mailparser_mod . ParsedMail ;
@@ -12,25 +14,25 @@ mailparser.on("headers", function(headers){
12
14
} ) ;
13
15
14
16
mailparser . on ( "end" , function ( mail ) {
15
- mail ; // object structure for parsed e-mail
17
+ mail ; // object structure for parsed e-mail
16
18
} ) ;
17
-
19
+
18
20
19
21
// Decode a simple e-mail
20
22
// This example decodes an e-mail from a string
21
-
23
+
22
24
var email = "From: 'Sender Name' <sender@example.com>\r\n" +
23
25
"To: 'Receiver Name' <receiver@example.com>\r\n" +
24
26
"Subject: Hello world!\r\n" +
25
27
"\r\n" +
26
28
"How are you today?" ;
27
- // setup an event listener when the parsing finishes
29
+ // setup an event listener when the parsing finishes
28
30
mailparser . on ( "end" , function ( mail_object ) {
29
- console . log ( "From:" , mail_object . from ) ; //[{address:'sender@example.com',name:'Sender Name' }]
30
- console . log ( "Subject:" , mail_object . subject ) ; // Hello world!
31
- console . log ( "Text body:" , mail_object . text ) ; // How are you today?
31
+ console . log ( "From:" , mail_object . from ) ; //[{address:'sender@example.com',name:'Sender Name' }]
32
+ console . log ( "Subject:" , mail_object . subject ) ; // Hello world!
33
+ console . log ( "Text body:" , mail_object . text ) ; // How are you today?
32
34
} ) ;
33
- // send the email source to the parser
35
+ // send the email source to the parser
34
36
mailparser . write ( email ) ;
35
37
mailparser . end ( ) ;
36
38
@@ -42,7 +44,7 @@ import fs = require("fs");
42
44
mailparser . on ( "end" , function ( mail_object ) {
43
45
console . log ( "Subject:" , mail_object . subject ) ;
44
46
} ) ;
45
-
47
+
46
48
fs . createReadStream ( "email.eml" ) . pipe ( mailparser ) ;
47
49
48
50
@@ -63,7 +65,3 @@ mp.on("attachment", function(attachment, mail){
63
65
var output = fs . createWriteStream ( attachment . generatedFileName ) ;
64
66
attachment . stream . pipe ( output ) ;
65
67
} ) ;
66
-
67
-
68
-
69
-
0 commit comments