Pascal (Lazarus/Delphi)
Pascal (Lazarus/Delphi)
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 Pascal (Lazarus/Delphi) Downloads
program ChilkatDemo;
// Demonstrates using the Chilkat Pascal wrapper via the C bridge DLL.
// Builds as a console application under Lazarus (FPC) or Delphi.
{$IFDEF FPC}
{$MODE DELPHI}
{$ENDIF}
{$APPTYPE CONSOLE}
uses
{$IFDEF UNIX}
cthreads,
{$ENDIF}
SysUtils,
CkDllLoader,
Chilkat.BinData,
Chilkat.Dkim;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
success: Boolean;
dkim: TDkim;
mimeData: TBinData;
numSigs: Integer;
begin
success := False;
// 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.
dkim := TDkim.Create;
// Load the complete MIME message.
mimeData := TBinData.Create;
success := mimeData.LoadFile('qa_data/received.eml');
if (success = False) then
begin
WriteLn(mimeData.LastErrorText);
Exit;
end;
// Count the DKIM-Signature header fields. The count includes malformed signatures, since the
// fields are counted without validating their syntax.
numSigs := dkim.NumDkimSigs(mimeData);
WriteLn('The message has ' + numSigs + ' DKIM-Signature header(s).');
dkim.Free;
mimeData.Free;
end;
// ---------------------------------------------------------------------------
begin
try
RunDemo;
except
on E: Exception do
WriteLn('Unhandled exception: ', E.ClassName, ': ', E.Message);
end;
WriteLn;
{$IFDEF MSWINDOWS}
WriteLn('Press Enter to exit...');
ReadLn;
{$ENDIF}
end.