Coder Social home page Coder Social logo

download-email-attachments's Introduction

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

download-email-attachments's People

Contributors

gr2m avatar jo avatar lucidntr avatar tlvince avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

download-email-attachments's Issues

Endpoint for download complete

Hello,
I was wondering if there is any endpoint for attachment download complete in download-email-attachments.
I am trying to run another service when all files on my email get downloaded (for the specified time).

Any help would be appreciated.
Thanks
Sid

Provide password via readline (or similar)

Right now, my email password would appear either in the command line (and therefore its history).

many tools have a (parameterless) commant line argument (think mysql -u user -p) that will let you enter a password, without printing it.
In other cases (for scripting, for example) it is added as a "read password from that file over there" argument.

Option 'since' is not optional

node version: v12.22.5
download-email-attachments version: 2.0.1

omitting the 'since'-option results in the following error:

Error: Search option argument must be a Date object or a parseable date string
    at buildSearchQuery (/home/user/newProject/node_modules/download-email-attachments/node_modules/imap/lib/Connection.js:1911:21)
    at Connection._search (/home/user/newProject/node_modules/download-email-attachments/node_modules/imap/lib/Connection.js:568:15)
    at Connection.search (/home/user/newProject/node_modules/download-email-attachments/node_modules/imap/lib/Connection.js:557:8)
    at processMails (/home/user/newProject/node_modules/download-email-attachments/lib/find-emails.js:244:10)
    at /home/user/newProject/node_modules/download-email-attachments/lib/find-emails.js:155:7
    at Connection.<anonymous> (/home/user/newProject/node_modules/download-email-attachments/node_modules/imap/lib/Connection.js:423:7)
    at Connection._resTagged (/home/user/newProject/node_modules/download-email-attachments/node_modules/imap/lib/Connection.js:1521:22)
    at Parser.<anonymous> (/home/user/newProject/node_modules/download-email-attachments/node_modules/imap/lib/Connection.js:193:10)
    at Parser.emit (events.js:314:20)
    at Parser._resTagged (/home/user/newProject/node_modules/download-email-attachments/node_modules/imap/lib/Parser.js:175:10)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.