Sample code for 30+ languages & platforms
Android™

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 Android™ Downloads

Android™
// Important: Don't forget to include the call to System.loadLibrary
// as shown at the bottom of this code sample.
package com.test;

import android.app.Activity;
import com.chilkatsoft.*;

import android.widget.TextView;
import android.os.Bundle;

public class SimpleActivity extends Activity {

  private static final String TAG = "Chilkat";

  // Called when the activity is first created.
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    boolean 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.

    CkDkim dkim = new CkDkim();

    //  Load the complete MIME message.
    CkBinData mimeData = new CkBinData();
    success = mimeData.LoadFile("qa_data/received.eml");
    if (success == false) {
        Log.i(TAG, mimeData.lastErrorText());
        return;
        }

    //  Count the DKIM-Signature header fields.  The count includes malformed signatures, since the
    //  fields are counted without validating their syntax.
    int numSigs = dkim.NumDkimSigs(mimeData);
    Log.i(TAG, "The message has " + String.valueOf(numSigs) + " DKIM-Signature header(s).");

  }

  static {
      System.loadLibrary("chilkat");

      // Note: If the incorrect library name is passed to System.loadLibrary,
      // then you will see the following error message at application startup:
      //"The application <your-application-name> has stopped unexpectedly. Please try again."
  }
}