Sample code for 30+ languages & platforms
Android™

Compute a Global Unique Key for an Email

See more Email Object Examples

Demonstrates the Chilkat Email.ComputeGlobalKey2 method, which computes a global unique key for the email — an MD5 digest formed from the message-id concatenated with other identifying fields. The first argument is the encoding of the returned key (such as hex or base64), and the second folds the key when true. This example loads an email and computes its key as hex.

Background: A "global key" is a compact fingerprint that identifies a specific message across systems. Because it is derived deterministically from the message's own headers, the same email yields the same key anywhere it is computed — ideal for de-duplicating messages, using as a database primary key, or detecting whether a message has already been processed.

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 ComputeGlobalKey2 method, which computes a global unique key for the
    //  email (an MD5 digest of the message-id and other fields).  The first argument is the encoding of the
    //  returned key (such as "hex" or "base64"), and the second folds the key when true.

    CkEmail email = new CkEmail();

    success = email.LoadEml("qa_data/eml/message.eml");
    if (success == false) {
        Log.i(TAG, email.lastErrorText());
        return true;
        }

    //  Compute the global key as a lowercase hex string.
    String key = email.computeGlobalKey2("hex",false);
    Log.i(TAG, "Global key: " + key);

    //  Note: The path "qa_data/..." is a relative local filesystem path,
    //  relative to the current working directory of the running application.

  }

  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."
  }
}