Skip to content

opendkim.eom()

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

DESCRIPTION

Denote end-of-message for a message. When verifying, process signatures in order; when signing, compute all signatures. opendkim.eom() is called after the entire body of the message has been passed to the API via zero or more calls to opendkim.body().

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

ARGUMENTS

Type: undefined

RETURN VALUES

  • Returns opendkim object
  • If passed {testkey: true}, returns a bool indicating if the key is a test key
  • On failure, an exception is thrown that indicates the cause of the problem.

NOTES

  • By default, when verifying, this function processes all signatures, in order. If the DKIM_LIBFLAGS_VERIFYONE flag is set on the library, then processing will stop after one good signature is found. There may be other signatures before or after that one in the message whose evaluation might be meaningful to the calling application. In that case, the calling application should use the final handling callback (see opendkim.set_final() to get an opportunity to process all of the signatures and possibly reorder them as per the application's preference. With the above flag set, this function will use the signatures as reordered by that function (or in arrival order if no reordering is done) and act on the first valid one, or the first one if none are valid.

EXAMPLE (async/await)

const OpenDKIM = require('node-opendkim');                                                               
                                                                                                         
async function verify(header, body) {                                                                    
  var opendkim = new OpenDKIM();                                                                         
                                                                                                         
  try {                                                                                                  
    await opendkim.verify({id: undefined});                                                              
    await opendkim.header({                                                                              
      header: header,                                                                                    
      length: header.length                                                                              
    });                                                                                                  
    await opendkim.eoh();                                                                                
    await opendkim.body({                                                                                
      body: body,                                                                                        
      length: body.length                                                                                
    });                                                                                                  
    await opendkim.eom();                                                                                
  } catch (err) {                                                                                        
    console.log(opendkim.sig_geterrorstr(opendkim.sig_geterror()));                                     
    console.log(err);                                                                                    
  }                                                                                                      
}                                                                                                        

EXAMPLE (sync)

const OpenDKIM = require('node-opendkim');                                                               
                                                                                                         
function verify_sync(header, body) {                                                                     
  var opendkim = new OpenDKIM();                                                                         
                                                                                                         
  try {                                                                                                  
    opendkim.verify_sync({id: undefined});                                                               
    opendkim.header_sync({                                                                               
      header: header,                                                                                    
      length: header.length                                                                              
    });                                                                                                  
    opendkim.eoh_sync();                                                                                 
    opendkim.body_sync({                                                                                 
      body: body,                                                                                        
      length: body.length                                                                                
    });                                                                                                  
    opendkim.eom_sync();                                                                                 
  } catch (err) {                                                                                        
    console.log(opendkim.sig_geterrorstr(opendkim.sig_geterror()));                                     
    console.log(err);                                                                                    
  }                                                                                                      
}                                                                                                        

EXAMPLE (errback)

const OpenDKIM = require('node-opendkim');                                                               
                                                                                                         
function verify(opendkim, header, body, callback) {                                                                
  opendkim.verify({id: undefined}, function (err, result) {                                              
    if (err) {                                                                                           
      return callback(err, result);                                                                      
    }                                                                                                    
                                                                                                         
    var header_obj = {                                                                                   
      header: header,                                                                                    
      length: header.length                                                                              
    };                                                                                                   
                                                                                                         
    opendkim.header(header_obj, function (err, result) {                                                 
      if (err) {                                                                                         
        return callback(err, result);                                                                    
      }                                                                                                  
                                                                                                         
      opendkim.eoh(function (err, result) {                                                              
        if (err) {                                                                                       
          return callback(err, result);                                                                  
        }                                                                                                
                                                                                                         
        var body_obj = {                                                                                 
          body: body,                                                                                    
          length: body.length                                                                            
        };                                                                                               
                                                                                                         
        opendkim.body(body_obj, function (err, result) {                                                 
          if (err) {                                                                                     
            return callback(err, result);                                                                
          }                                                                                              
                                                                                                         
          opendkim.eom(function (err, result) {                                                          
            if (err) {                                                                                   
              return callback(err, result);                                                              
            }                                                                                            
                                                                                                         
            return callback(err, result);                                                                
        });                                                                                              
      });                                                                                                
    });                                                                                                  
  });                                                                                                    
}                                                                                                        

var opendkim = new OpenDKIM();

verify(opendkim, header, body, function (err, result) {                                                            
  if (err) {                                                                                             
    return console.log(opendkim.sig_geterrorstr(opendkim.sig_geterror()));
  }                                                                                                      
                                                                                                         
  // success                                                                                             
});