mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-09-09 11:13:57 +08:00
fix mailparser/mailparser-tests.ts
This commit is contained in:
@@ -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);
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user