wrapAsync with nodes on end emitter in a method


#1

Hi,

in a method i´d like to return a parsed email. This is one of many things i have tried:

var mail = "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

mailparser.write(mail); 
mailparser.end();
var onMail  = Meteor.wrapAsync(mailparser.on, mailparser);

return onMail('end')

This is the a example from mailparser on github

var MailParser = require("mailparser").MailParser,
mailparser = new MailParser();

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    
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?
});

// send the email source to the parser
mailparser.write(email);
mailparser.end();

Please help me.

thanks