GithubHelp home page GithubHelp logo

node-opendkim's Introduction

NPM

Codefresh build status

node-opendkim

node.js native language binding to libopendkim

Install/Test Locally (from source)

git clone [email protected]:godsflaw/node-opendkim.git
cd node-opendkim
npm install
npm test -- --verbose

Install Locally (npm)

npm install --save node-opendkim

Install Globally (npm)

npm install --global node-opendkim

Compile (Development)

node-gyp rebuild


Usage

Verify (async/await)

const OpenDKIM = require('node-opendkim');

async function verify(message) {
  var opendkim = new OpenDKIM();

  try {
    await opendkim.verify({id: undefined});
    await opendkim.chunk({
      message: message,
      length: message.length
    });
    await opendkim.chunk_end();
  } catch (err) {
    console.log(opendkim.sig_geterrorstr(opendkim.sig_geterror()));
    console.log(err);
  }
}

Verify (sync)

const OpenDKIM = require('node-opendkim');

function verify_sync(message) {
  var opendkim = new OpenDKIM();

  try {
    opendkim.verify_sync({id: undefined});
    opendkim.chunk_sync({
      message: message,
      length: message.length
    });
    opendkim.chunk_end_sync();
  } catch (err) {
    console.log(opendkim.sig_geterrorstr(opendkim.sig_geterror()));
    console.log(err);
  }
}

Verify (errback)

const OpenDKIM = require('node-opendkim');

function verify(opendkim, message, callback) {
  opendkim.verify({id: undefined}, function (err, result) {
    if (err) {
      return callback(err, result);
    }

    var options = {
      message: message,
      length: message.length
    };

    opendkim.chunk(options, function (err, result) {
      if (err) {
        return callback(err, result);
      }

      opendkim.chunk_end(function (err, result) {
        if (err) {
          return callback(err, result);
        }

        return callback(err, result);
      });
    });
  });
}

var opendkim = new OpenDKIM();

verify(opendkim, message, function (err, result) {
  if (err) {
    return console.log(opendkim.sig_geterrorstr(opendkim.sig_geterror()));
  }

  // success
});

API Administration

API Processing

API Signing

API Utility

API Verifying


License

MIT © Christopher Mooney

node-opendkim's People

Contributors

godsflaw avatar desttinghim avatar bhenze avatar leroycep avatar nabetse00 avatar

Stargazers

Colin avatar

Watchers

Kevin Goess avatar  avatar James M. Luedke avatar Charles Lindsay avatar James Cloos avatar  avatar Tony Maszeroski avatar  avatar

node-opendkim's Issues

ISSUE-67: version bump 0.1.0

Description

Version bump to 0.1.0 given the async interface changes. Update the documentation in the wiki and in the readme.md.

PR must contain

  • a first commit title that starts with 'ISSUE-N:'
  • documentation

Bounty

None

ISSUE-42: add continuous integration testing

Add CI to this project. Build this project inside a docker container and use a service like codefresh to build that container, our code, and run unit tests. Then make sure all of this is pulled into the pull request process.

ISSUE-8: rework the tests into smaller files

The tests are also outgrowing their test files. We should rework them down better to be smaller and easier to parse. I'm thinking of making directories for major categories of the API like processing and then under that making tests that are names something like: 00-header.js, 01-eoh.js, ....

ISSUE-54: Make all blocking calls Promises that can async/await

Description

Many of the low level calls must do DNS lookups or CPU intensive work. These actions will block the node.js event loop. For this reason, we should lean on lower level threads handling the work of the addon, while allowing node.js's event loop to move on while libopendkim is working.

Since this code is already being used in plugins like haraka-plugin-opendkim in an imperative calling style, I think it would be best to make the interface return Promises. By doing so, we allow the caller to use async/await and significantly reduce the work needed to conform to a callback interface.

PR must contain

  • a first commit title that starts with 'ISSUE-N:'
  • code
  • tests
  • documentation

Example PR

#50

More Information

http://www.opendkim.org/libopendkim/

Bounty

None

ISSUE-36: Make sure NOSIG comes back as an error

When a signature is missing, we want that to error. The caller can make a pass, fail, none, etc. determination based on that error. The swift exit in these cases makes it so the caller can just start streaming a message at node-opendkim and at the earliest point where we know there is no signature, it will exit. It takes the burden of message parsing for the DKIM-Signature header off the user, and leaves it in libopendkim.

ISSUE-44: fix npm install not compiling code in docker container

For some reason, we have to manually call node-gyp rebuild after npm install in the docker container. We should not have to do this, as npm install should be smart enough to detect the binding.gyp file and know it needs to manually run a node-gyp install.

Also, if possible, slim down this container.

ISSUE-59: adjust ava concurrency limits

Description

ava, the test runner, seems to want maximum concurrency when running tests. With codefresh, this is causing the OOM killer to kick in and test runs to fail. Adjust this down to a more optimal concurrency limit.

PR must contain

  • a first commit title that starts with 'ISSUE-N:'
  • code
  • tests
  • documentation

Example PR

#50

More Information

http://www.opendkim.org/libopendkim/

Bounty

None

ISSUE-1: Fix this deprecated warning

  CXX(target) Release/obj.target/opendkim/src/opendkim.o
../src/opendkim.cc:63:37: warning: 'NewInstance' is deprecated [-Wdeprecated-declarations]
    info.GetReturnValue().Set(cons->NewInstance());
                                    ^
/Users/user/.node-gyp/6.4.0/include/node/v8.h:3243:52: note: 'NewInstance' has been explicitly marked
      deprecated here
  V8_DEPRECATED("Use maybe version", Local<Object> NewInstance() const);
                                                   ^
1 warning generated.
  SOLINK_MODULE(target) Release/opendkim.node

ISSUE-15: add various test messages

In order to really test all the verify and processing functions, we need real test data that represents real messages. These should come in all the various forms of no signature, good signatures, bad signatures, etc.

ISSUE-16: fix memory leak on errors

This pattern is everywhere:

  // data                                                                       
  char *data = NULL;                                                            
  if (!_value_to_char(info[0], "data", &data)) {                                
    Nan::ThrowTypeError("set_option(): data is undefined");                     
    return;                                                                     
  }                                                                             
                                                                                
  // length                                                                     
  int length = 0;                                                               
  length = _value_to_int(info[0], "length");                                    
  if (length == 0) {                                                            
    Nan::ThrowTypeError("set_option(): length must be defined and non-zero");   
    return;                                                                     
  }                                                                             

The problem is, that if we throw an error on length, we don't free the memory for data. We need to audit the code for this pattern, and come up with an elegant solution so as not to bloat memory on error.

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.