npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mailcap

v0.1.2

Published

Mail capture and archival server for RethinkDB

Downloads

14

Readme

mailcap

npm version license

A mail capture and archival server for RethinkDB.

Mailcap makes it easy to store emails in a RethinkDB database.

  • Mailcap is an SMTP server so it can receive mail from any MTA.
  • Emails are parsed into a JSON format that is easy to search.
  • File attachments are saved efficiently using ReGrid

Getting Started

Install Mailcap
npm install -g mailcap
Create config.js
mailcap bootstrap
Edit config.js
module.exports = {
  port: 2525, // Port server listens on
  address: '', // Email address mail will be sent to
  table: 'email', // RethinkDB table to store mail in
  rethinkdb: {
    host: 'localhost', // RethinkDB host address
    db: 'test' // RethinkDB database name
  },
  regrid: {
    bucketName: 'email' // ReGrid bucket name
  }
}
Start the server
mailcap start

Storage format

Mailcap stores all email in the configured table. File attachments are stored separately in ReGrid.

Email Format Example
{
  addresses: [
    "[email protected]",
    "[email protected]"
  ],
  attachments: [
    {
      "contentType": "image/jpeg",
      "fileName": "swirly-ubuntu-wallpaper.jpg",
      "length": 331469
    }
  ],
  cc: [ ],
  createdAt: "Wed Mar 16 2016 03:28:55 GMT+00:00",
  from: [
    "[email protected]"
  ],
  headers: {
    content-type: 'multipart/mixed; boundary="----=_Part_87467_1755068617.1458098935181"',
    date: "Wed, 16 Mar 2016 03:28:55 +0000 (UTC)",
    from: "fromAddress <[email protected]>",
    message-id: "<[email protected]>",
    mime-version: "1.0",
    received: [
      "from localhost (localhost.localdomain [127.0.0.1]) by mail.example.com (Postfix) with ESMTP id ECC231C2B43 for <[email protected]>; Wed, 16 Mar 2016 03:29:00 +0000 (UTC)",
      "from mail.example.com ([127.0.0.1]) by localhost (mail.example.com [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id FM4FhPl1ZqLS for <[email protected]>; Wed, 16 Mar 2016 03:28:58 +0000 (UTC)",
      "from localhost (localhost.localdomain [127.0.0.1]) by mail.example.com (Postfix) with ESMTP id 86B501C2B42 for <[email protected]>; Wed, 16 Mar 2016 03:28:57 +0000 (UTC)",
      "from mail.example.com ([127.0.0.1]) by localhost (mail.example.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id 3PFEkD1lm_1C for <[email protected]>; Wed, 16 Mar 2016 03:28:56 +0000 (UTC)",
      "from mail.example.com (mail.example.com [xxx.xxx.xxx.xxx]) by mail.example.com (Postfix) with ESMTP id A9E291C2B43 for <[email protected]>; Wed, 16 Mar 2016 03:28:55 +0000 (UTC)"
    ],
    subject: "This is a test email",
    thread-index: "rX2hWYSOPicdVe5+pGD2LDwrQ2D/AA==",
    thread-topic: "This is a test email",
    to: "toAddress <[email protected]>",
    x-mailer: "Zimbra 8.6.0_GA_1191 (ZimbraWebClient - FF45 (Linux)/8.6.0_GA_1191)",
    x-originating-ip: "[xxx.xxx.xxx.xxx]",
    x-virus-scanned: "amavisd-new at mail.internalfx.com"
  },
  html: `<html><body>
  <p>Hello,</p>
  <p>Mailcap makes it easy to store emails in a RethinkDB database.</p>
  <p>Thanks</p>
  </body></html>`,
  id: "d9e31972-6eee-46bd-b63f-acee4b2cd462",
  messageId: "[email protected]",
  subject: "This is a test email",
  text: `Hello,

  Mailcap makes it easy to store emails in a RethinkDB database.

  Thanks
  `,
  to: [
    "[email protected]"
  ]
}

How to retrieve file attachments

File attachments are stored with a path (called a filename in ReGrid) of the id of the email and the attachments filename. Per the above email example, the file would be stored at d9e31972-6eee-46bd-b63f-acee4b2cd462/swirly-ubuntu-wallpaper.jpg.

The above file could be retrieved with the following code.

var fileName = 'd9e31972-6eee-46bd-b63f-acee4b2cd462/swirly-ubuntu-wallpaper.jpg'
var ReGrid = require('rethinkdb-regrid')

var bucket = ReGrid({db: 'example'})

// initBucket creates tables and indexes if they don't exist, returns a promise.
bucket.initBucket().then(function () {
  // We are now ready to read and write files

  var rstream = bucket.downloadFilename(fileName)
  rstream.pipe(fs.createWriteStream('./swirly-ubuntu-wallpaper.jpg'))

})