Skip to content

opendkim.eoh()

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

DESCRIPTION

Denote end-of-headers for a message. opendkim.eoh() is called when the delimiter between the message's headers and its body is encountered. That is, when one is done processing the header section.

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

ARGUMENTS

Type: undefined

RETURN VALUES

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

NOTES

  • This function may throw DKIM_STAT_NOSIG when verifying if no signature was present in the message headers. This is simply advisory; you must continue executing down to the opendkim.eom() call to determine whether or not a signature should have been present.
  • This function can throw DKIM_STAT_SYNTAX when verifying if a header that must be signed was not included in a received signature, or if the message appeared to contain no sender header field. In the latter case, the dkim handle is rendered unusable by future calls to opendkim.body() or opendkim.eom().
  • This function can throw DKIM_STAT_CANTVRFY when verifying if all discovered signatures were either marked to be ignored, contained syntax errors, or failed verification attempts. This is only tested if the DKIM_LIBFLAG_EOHCHECK library flag is set.
  • This function can throw DKIM_STAT_SYNTAX in either mode if the input message does not conform to the header field count checks imposed by the DKIM_LIBFLAG_STRICTHDRS library flag.
  • This function can throw DKIM_STAT_NORESOURCE for a verifying handle if an attempt to construct a DNS query based on the selector and domain in a signature exceeded the maximum allowable query size.

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