0.1.0 • Published 7 years ago
node-opendkim v0.1.0
node-opendkim
node.js native language binding to libopendkim
Install/Test Locally (from source)
git clone git@github.com: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
- OpenDKIM.new(): new instance of OpenDKIM object.
- opendkim.flush_cache(): Flush the key cache.
- opendkim.lib_feature(): Check for supported features.
API Processing
- opendkim.chunk(): Process a message chunk.
- opendkim.chunk_end(): called when done with chunk.
- opendkim.header(): Process a header.
- opendkim.eoh(): Identify end of headers.
- opendkim.body(): Process a body chunk.
- opendkim.eom(): Identify end of message.
API Signing
- opendkim.sign(): get ready to sign a message.
API Utility
- opendkim.query_info(): get/set query info.
- opendkim.query_method(): get/set query method.
- opendkim.tmpdir(): get/set tmp dir.
API Verifying
- opendkim.get_signature(): sets the signature info handle.
- opendkim.ohdrs(): Retrieve the original header set from the "z=" tag in a received signature if present.
- opendkim.sig_getcanonlen(): get the canonicalized message length from the signature handle and message.
- opendkim.sig_getdomain(): get the domain from the signature handle.
- opendkim.sig_geterror(): Retrieve the error code associated with a rejected/disqualified signature.
- opendkim.sig_geterrorstr(): get the error string specified by the error code.
- opendkim.sig_getidentity(): get the identity from the signature handle.
- opendkim.sig_getselector(): get the selector from the signature handle.
- opendkim.verify(): get ready to verify a message.
License
MIT © Christopher Mooney