Sample code for 30+ languages & platforms
Android™

Load a MessageSet from a Compact String

See more IMAP Examples

Demonstrates the Chilkat MessageSet.FromCompactString method, which clears the set and loads message identifiers from compact IMAP message-set syntax. The only argument is the compact string: a colon specifies an inclusive ascending range, and commas separate values or ranges. This example loads 1:5,8:10 and prints the result as a comma-separated list.

Background: Compact message-set syntax is how IMAP itself expresses groups of messages — 1:5,8:10 is far more concise than listing every id. FromCompactString is the inverse of ToCompactString: it parses that text into a set you can pass to Imap methods. Duplicates are removed, identifiers are sorted ascending, and the existing HasUids setting is preserved. Note the string carries only the numbers — it does not record whether they are UIDs or sequence numbers.

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 MessageSet.FromCompactString method, which loads a set of message
    //  identifiers from compact IMAP message-set syntax.  The only argument is the compact string.
    //  A colon specifies an inclusive range, and commas separate values or ranges.

    CkMessageSet msgSet = new CkMessageSet();

    //  Load a compact message set.  "1:5,8:10" expands to 1,2,3,4,5,8,9,10.
    success = msgSet.FromCompactString("1:5,8:10");
    if (success == false) {
        Log.i(TAG, msgSet.lastErrorText());
        return;
        }

    Log.i(TAG, "Count: " + String.valueOf(msgSet.get_Count()));

    //  Show the loaded identifiers in comma-separated form.
    String csv = msgSet.toCommaSeparatedStr();
    Log.i(TAG, csv);

  }

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