Android™
Android™
List IMAP Mailboxes
See more IMAP Examples
Demonstrates the Chilkat Imap.MbxList method, which lists matching mailboxes and appends them to a Mailboxes object. The first argument selects subscribed-only, the second is a reference name, the third is the mailbox name pattern, and the fourth is the Mailboxes object. This example lists all mailboxes and prints each name. (The object is not cleared on success, so avoid reusing one across calls to prevent duplicates.)
Background: This corresponds to the IMAP
LIST command (or LSUB when subscribed-only is requested). The pattern uses IMAP wildcards: * matches across hierarchy levels while % matches within a single level, so Archive/% lists just the direct children of Archive. Each returned mailbox also carries flags you can inspect — for example HasInferiors (has sub-folders) and IsSelectable — which is how a client renders a folder tree.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;
// Demonstrates the Imap.MbxList method, which lists matching mailboxes and appends them to a
// Mailboxes object. The 1st argument selects subscribed-only, the 2nd is a reference name,
// the 3rd is the mailbox pattern, and the 4th is the Mailboxes object.
CkImap imap = new CkImap();
imap.put_Ssl(true);
imap.put_Port(993);
success = imap.Connect("imap.example.com");
if (success == false) {
Log.i(TAG, imap.lastErrorText());
return;
}
success = imap.Login("user@example.com","myPassword");
if (success == false) {
Log.i(TAG, imap.lastErrorText());
return;
}
// List all mailboxes. The first argument false requests all (not subscribed-only); "*" matches any name.
CkMailboxes mailboxes = new CkMailboxes();
success = imap.MbxList(false,"","*",mailboxes);
if (success == false) {
Log.i(TAG, imap.lastErrorText());
return;
}
int n = mailboxes.get_Count();
Log.i(TAG, "Mailboxes: " + String.valueOf(n));
int i;
for (i = 0; i <= n - 1; i++) {
Log.i(TAG, mailboxes.getName(i));
}
success = imap.get_Disconnect();ERROR: ";" expected
}
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."
}
}