Sample code for 30+ languages & platforms
PowerBuilder

Count the DKIM Signatures in a Message

See more DKIM / DomainKey Examples

Demonstrates the Chilkat Dkim.NumDkimSigs method, which returns the number of DKIM-Signature header fields in a MIME message. The only argument is a BinData holding the complete MIME.

Note: The file paths are relative to the application's current working directory. Absolute paths may also be used. Supply the paths appropriate to your own environment.

Background: A message can legitimately carry several DKIM signatures — the original sender's plus ones added by forwarders or mailing lists — so a verifier needs to know how many there are before checking each. This count is what supplies the valid index range for DkimVerify. Note that it counts header fields by name only, without validating them, so a malformed DKIM-Signature field is still included in the total.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Dkim
oleobject loo_MimeData
integer li_NumSigs

li_Success = 0

//  Demonstrates the Dkim.NumDkimSigs method, which returns the number of DKIM-Signature header
//  fields in a MIME message.  The only argument is a BinData holding the complete MIME.

loo_Dkim = create oleobject
li_rc = loo_Dkim.ConnectToNewObject("Chilkat.Dkim")
if li_rc < 0 then
    destroy loo_Dkim
    MessageBox("Error","Connecting to COM object failed")
    return
end if

//  Load the complete MIME message.
loo_MimeData = create oleobject
li_rc = loo_MimeData.ConnectToNewObject("Chilkat.BinData")

li_Success = loo_MimeData.LoadFile("qa_data/received.eml")
if li_Success = 0 then
    Write-Debug loo_MimeData.LastErrorText
    destroy loo_Dkim
    destroy loo_MimeData
    return
end if

//  Count the DKIM-Signature header fields.  The count includes malformed signatures, since the
//  fields are counted without validating their syntax.
li_NumSigs = loo_Dkim.NumDkimSigs(loo_MimeData)
Write-Debug "The message has " + string(li_NumSigs) + " DKIM-Signature header(s)."


destroy loo_Dkim
destroy loo_MimeData