Skip to content

opendkim.verify()

Christopher Mooney edited this page Feb 12, 2018 · 5 revisions

DESCRIPTION

Create a new handle for verifying a (possibly) signed message. opendkim.verify() is called when preparing to process a new message that may be signed already in order to be able to verify its contents against the signature.

For more information:
http://www.opendkim.org/libopendkim/dkim_verify.html

ARGUMENTS

Type: Object

  • id: (default: undefined) An opaque, printable string for identifying this message, suitable for use in logging or debug output.

RETURN VALUES

  • On failure, an exception is thrown that indicates the cause of the problem.

NOTES

  • The handle returned by this function may not be used in a later call to opendkim.getsighdr()

EXAMPLE (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);                                                                                    
  }                                                                                                      
}                                                                                                        

EXAMPLE (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);                                                                                    
  }                                                                                                      
}                                                                                                        

EXAMPLE (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                                                                                             
});