Android™ Requires Chilkat v11.0.0+
Android™
Verify each DKIM signature in email downloaded over IMAP
See more DKIM Examples
Download the first ten messages (or all messages in a smaller inbox) as complete MIME, including attachments, while preserving their unread flags. The verifier looks up the selector’s TXT record when it needs a key. Inspect VerifyInfo immediately after each attempt for the signing domain, selector, and any body-hash mismatch.
Verify each signature independently, in top-to-bottom order. A passing signature authenticates the signing domain’s responsibility for the signed content. Identifying the author and checking DMARC alignment with the visible From address are separate steps. A missing DNS key or unavailable resolver can also prevent verification. DKIM specification.
Chilkat Android™ Downloads
// 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;
// Assumes Chilkat is unlocked. See Global Unlock Sample.
CkImap imap = new CkImap();
imap.put_Ssl(true);
imap.put_Port(993);
imap.put_RequireSslCertVerify(true);
imap.put_PeekMode(true);
imap.put_AutoDownloadAttachments(true);
success = imap.Connect("imap.example.com");
if (success != true) {
Log.i(TAG, imap.lastErrorText());
return;
}
success = imap.Login("IMAP_USERNAME","IMAP_PASSWORD");
if (success != true) {
Log.i(TAG, imap.lastErrorText());
return;
}
success = imap.SelectMailbox("INBOX");
if (success != true) {
Log.i(TAG, imap.lastErrorText());
return;
}
// Select the first ten sequence positions, then fetch by stable UID.
CkMessageSet messages = new CkMessageSet();
success = imap.QueryMbx("1:10",true,messages);
if (success != true) {
Log.i(TAG, imap.lastErrorText());
return;
}
int i = 0;
CkDkim verifier = new CkDkim();
CkBinData message = new CkBinData();
while ((i < messages.get_Count())) {
int uid = messages.GetId(i);
Log.i(TAG, "Message UID " + String.valueOf(uid));
success = imap.FetchSingleBd(uid,true,message);
if (success != true) {
Log.i(TAG, imap.lastErrorText());
}
else {
int count = verifier.NumDkimSigs(message);
if (count == 0) {
Log.i(TAG, "No DKIM signatures.");
}
int sig = 0;
while ((sig < count)) {
success = verifier.DkimVerify(sig,message);
// Read diagnostics before the next verification replaces them.
CkJsonObject info = new CkJsonObject();
boolean haveInfo = info.Load(verifier.verifyInfo());
if (success == true) {
Log.i(TAG, "Signature " + String.valueOf(sig) + " verified.");
}
else {
if ((haveInfo == true) and (info.StringOfEquals("bodyHashVerified","no",true) == true)) {
Log.i(TAG, "Signature " + String.valueOf(sig) + ": the body hash differs.");
}
else {
Log.i(TAG, "Signature " + String.valueOf(sig) + " could not be verified.");
}
Log.i(TAG, verifier.lastErrorText());
}
if ((haveInfo == true) and (info.JsonTypeOf("domain") == 1)) {
Log.i(TAG, "Signing domain: " + info.stringOf("domain") + " Selector: " + info.stringOf("selector"));
}
sig = sig + 1;
}
}
i = i + 1;
}
success = imap.Disconnect();
}
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."
}
}