node package manager
Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »



This is the module for locally storing and indexing email.

It's built on sqlite3 and organizes email by message id, thread id, labels, and full-text search. Boxes--like Inbox, Outbox, and Sent--are handled as a special case of labels. Does not search inside attachments.


Create a new mail repo. Store everything in a given directory:

var ScrambleMailRepo = require('scramble-mail-repo');
var repo = new ScrambleMailRepo('/home/bob/my-mail');

Write an email into the repo. Raw RFC2822 format. See test/ for examples.

var sampleMail =
  "From: <>\n" +
  "To: <>\n" +
  "Subject: Yo\n\n"+

Search the repo, and print out the results.

// Full text search"fifth of november", printResults);
// Full text search includes From and To"", printResults);
// You can also search explicitly. "to:" queries include the CC header."", printResults);"to:root", printResults);
// Search for an exact string"\"remember, remember\"", printResults);
// Get the inbox"label:\\scramble\\inbox", printResults);
// Get all sent mail"label:\\scramble\\sent", printResults);
// Fetch a given thread 
repo.getThread("herp", printResults);
// Fetch a given message 
repo.getMessage("herp", printResults);

How it works

scramble-mail-repo stores raw email as flat files in simple directory layout, plus a single sqlite DB to index them. You specify a directory for everything to go into. Example contents:

      <scramble mail id 1>.txt
      <scramble mail id 2>.txt

The sqlite DB uses the fts4 extension for full-text search. See schema.sql for the full schema.