Sample code for 30+ languages & platforms
Android™

Get the IMAP UID of an Email

See more Email Object Examples

Demonstrates the Chilkat Email.GetImapUid method. When email headers are downloaded from an IMAP server using Chilkat IMAP, a ckx-imap-uid header field is added to the email, and GetImapUid returns its value. This example sets that header directly to illustrate how the method reads it.

Background: IMAP assigns each message in a mailbox a UID — a stable numeric identifier used to fetch, flag, move, or delete that specific message. Chilkat records it in the ckx-imap-uid header so it stays attached to the downloaded Email object. This is the IMAP counterpart to POP3's UIDL (see the Uidl property), letting an application correlate a local message back to its position on the server.

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);

    //  Demonstrates the GetImapUid method.  When an email is downloaded from an IMAP server
    //  (using Chilkat IMAP), a ckx-imap-uid header field is added, and GetImapUid returns its
    //  value.  Here we set the header directly to show how the method reads it.

    CkEmail email = new CkEmail();
    email.put_Subject("GetImapUid example");

    //  Normally the IMAP download sets this header; we set it here for demonstration.
    email.AddHeaderField("ckx-imap-uid","482");

    Log.i(TAG, "IMAP UID = " + String.valueOf(email.GetImapUid()));

  }

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