fix mailparser/mailparser-tests.ts

This commit is contained in:
vvakame
2015-08-29 00:33:27 +09:00
parent 4dc47448f7
commit f9f932198f
+11 -13
View File
@@ -1,3 +1,5 @@
/// <reference path="./mailparser.d.ts" />
import mailparser_mod = require("mailparser");
import MailParser = mailparser_mod.MailParser;
import ParsedMail = mailparser_mod.ParsedMail;
@@ -12,25 +14,25 @@ mailparser.on("headers", function(headers){
});
mailparser.on("end", function(mail){
mail; // object structure for parsed e-mail
mail; // object structure for parsed e-mail
});
// Decode a simple e-mail
// This example decodes an e-mail from a string
var email = "From: 'Sender Name' <sender@example.com>\r\n"+
"To: 'Receiver Name' <receiver@example.com>\r\n"+
"Subject: Hello world!\r\n"+
"\r\n"+
"How are you today?";
// setup an event listener when the parsing finishes
// setup an event listener when the parsing finishes
mailparser.on("end", function(mail_object){
console.log("From:", mail_object.from); //[{address:'sender@example.com',name:'Sender Name'}]
console.log("Subject:", mail_object.subject); // Hello world!
console.log("Text body:", mail_object.text); // How are you today?
console.log("From:", mail_object.from); //[{address:'sender@example.com',name:'Sender Name'}]
console.log("Subject:", mail_object.subject); // Hello world!
console.log("Text body:", mail_object.text); // How are you today?
});
// send the email source to the parser
// send the email source to the parser
mailparser.write(email);
mailparser.end();
@@ -42,7 +44,7 @@ import fs = require("fs");
mailparser.on("end", function(mail_object){
console.log("Subject:", mail_object.subject);
});
fs.createReadStream("email.eml").pipe(mailparser);
@@ -63,7 +65,3 @@ mp.on("attachment", function(attachment, mail){
var output = fs.createWriteStream(attachment.generatedFileName);
attachment.stream.pipe(output);
});