Skip to content

opendkim.ohdrs()

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

DESCRIPTION

This call retrieves the contents of the z= tag in the signature. This must be called after opendkim.get_signature.

ARGUMENTS

Type: undefined

RETURN VALUES

  • throws an error if
    • The function was called before opendkim.get_signature()
  • returns an array of the headers in the z= tag

NOTES

  • If there is no z= tag, an empty array is returned.

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();                                                                          
    var zheaders = opendkim.ohdrs();                                                                     
    for (var i = 0; i < zheaders.length; i++) {                                                          
      console.log(zheaders[i]);                                                                          
    }                                                                                                    
  } 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();                                                                           
    var zheaders = opendkim.ohdrs();                                                                     
    for (var i = 0; i < zheaders.length; i++) {                                                          
      console.log(zheaders[i]);                                                                          
    }                                                                                                    
  } 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);                                                                  
        }                                                                                                
                                                                                                         
        var zheaders = opendkim.ohdrs();                                                                 
                                                                                                         
        return callback(err, zheaders);                                                                  
      });                                                                                                
    });                                                                                                  
  });                                                                                                    
}                                                                                                        

var opendkim = new OpenDKIM();
                                                                                                         
verify(opendkim, message, function (err, zheaders) {                                                               
  if (err) {                                                                                             
    return console.log(opendkim.sig_geterrorstr(opendkim.sig_geterror()));                                                                                              
  }                                                                                                      
                                                                                                         
  // success                                                                                             
  for (var i = 0; i < zheaders.length; i++) {                                                            
    console.log(zheaders[i]);                                                                            
  }                                                                                                      
});