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

@onionpay/dea

v2.0.2

Published

Download email attachments via IMAP

Downloads

4

Readme

download-email-attachments

Download email attachments via IMAP

Build Status

download-email-attachments downloads all attachements of an email account to a directory and optionally do some postprocessing. It can either be required as module or used as a command line tool.

Command Line Interface

# install download-email-attachments globally
npm install -g download-email-attachments

# download all attachments of [email protected] (password: secret) since beginning of 2015-01-12
download-email-attachments "[email protected]":[email protected]:123 \
  --directory ./files \
  --filename-template "{day}-{filename}" \
  --filename-filter ".xlsx?$" \
  --timeout 3000 \
  --since 2015-01-12

Using as module

var onEnd = function (result) {
  if (result.error) {
    console.log(result.error)
    return
  }
  console.log("done")
  console.log(result.latestTime)
}

var downloadEmailAttachments = require('download-email-attachments');
downloadEmailAttachments({
  invalidChars: /[^A-Z]/g, //Regex of Characters that are invalid and will be replaced by X
  account: '"[email protected]":[email protected]:123', // all options and params besides account are optional
  directory: './files',
  filenameTemplate: '{day}-{filename}',
  filenameFilter: /.xlsx?$/,
  timeout: 3000,
  log: {
    warn: console.warn,
    debug: console.info,
    error: console.error,
    info: console.info
  },
  since: '2015-01-12',
  lastSyncIds: ['234', '234', '5345'], // ids already dowloaded and ignored, helpful because since is only supporting dates without time
  attachmentHandler: function (attachmentData, callback, errorCB) {
    console.log(attachmentData)
    callback()
  }
}, onEnd)

Options

You have to pass an imap account with password, the format is:

username:password@host:port
  • username If username contains @ or :, put it in quotes, e.g. `"[email protected]":[email protected]
  • password If password contains @ or :, put it in quotes, e.g. `joe:"123:@456"@example.com
  • host This is the imap domain
  • port Optional, defaults to 993

--directory / directory

Optional. Defaults to ./

Directory where attachments shall be downloaded to.

--filename-template / filenameTemplate

Optional. Defaults to {filename}

Filenames the attachments shall be saved as. Using / will create subfolders. The following placeholders are available

  • {filename}, e.g. data.xls
  • {basename}, e.g. data
  • {extension}, e.g. xls
  • {day}, e.g. 2015-01-01
  • {recipientAddress}, e.g. [email protected]
  • {senderAddress}, e.g. [email protected]
  • {id}, unique content ID, e.g. c361f45d-98b6-9b18-96ac-f66aee2cb760
  • {nr}, starts at 1 and increments for every stored file.

--filename-filter / filenameFilter

Optional

Pass a regular expression, only attachments matching it will be downloaded.

--timeout / timeout

Optional, defaults to 10000

Timeout in millisecond to wait for data from the imap server until closing the connection.

--since / since

Optional. Defaults to today's date in YYYY-MM-DD format

Local setup

git clone [email protected]:gr2m/download-email-attachments.git
cd download-email-attachments
npm install

Run all tests

npm test

Note: There is no full stack test yet, because of the complexity of stubbing an imap server. If someone could help here, that'd be much appreciated! Ping me

License

MIT