node.js native language binding to libopendkim
git clone git@github.com:godsflaw/node-opendkim.git
cd node-opendkim
npm install
npm test -- --verbose
npm install --save node-opendkim
npm install --global node-opendkim
node-gyp rebuild
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);
}
}
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);
}
}
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
});
- OpenDKIM.new(): new instance of OpenDKIM object.
- opendkim.flush_cache(): Flush the key cache.
- opendkim.lib_feature(): Check for supported features.
- 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.
- opendkim.sign(): get ready to sign a message.
- opendkim.query_info(): get/set query info.
- opendkim.query_method(): get/set query method.
- opendkim.tmpdir(): get/set tmp dir.
- 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.
MIT © Christopher Mooney