Skip to content

A `StreamStack` subclass that parses raw e-mail messages.

Notifications You must be signed in to change notification settings

eburi/node-mail-stack

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

node-mail-stack

A StreamStack subclass that parses raw e-mail messages.

This module implements RFC 5322. Specifically, it parses the e-mail headers into an Object and fires a "headers" events. Then the body of the message is emitted as 'data' events, and can be .pipe()ed into other node WritableStream instances.

Usage

var smtp = require('smtp')
var mail = require('mail-stack');

smtp.createServer(function(conn) {
  conn.on('DATA', function(message) {
    message.accepted = true;

    var mailParser = new mail.Parser(message);
    mailParser.on('headers', function(headers) {
      // 'headers' is an Array, with 'key' and 'value' properties
      // for each entry. Duplicate values are handled fine.
      // Header names are also attached directly to the 'headers'
      // object for programmatic convenience:   headers.From  -> 'sender@example.com'
      console.log(headers);

      // Any 'data' events from the parser are part of the message body.
      mailParser.pipe(process.stdout, {end:false});
    });
  });
});

See the examples/ directory for some more usage examples.

About

A `StreamStack` subclass that parses raw e-mail messages.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%