Android™
Android™
Fetch the Flags Set on an IMAP Message
See more IMAP Examples
Demonstrates the Chilkat Imap.FetchFlags method, which returns the flags currently set on a single message as a space-separated string. The first argument is the message ID and the second (bUid) selects UID vs sequence number. This example fetches and prints the flags for one message identified by UID.
Background: The returned string is the server's current flag list for the message, such as
\Seen \Flagged. This is a quick way to check a single message's state — for example, to decide whether it still needs processing — without downloading the message itself. To read the same information from a message you already have as an Email object, use GetMailFlag instead.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.FetchFlags method, which returns the flags currently set on a single
// message as a space-separated string. The 1st argument is the message ID and the 2nd (bUid)
// selects UID vs sequence number.
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;
}
success = imap.SelectMailbox("Inbox");
if (success == false) {
Log.i(TAG, imap.lastErrorText());
return;
}
CkMessageSet msgSet = new CkMessageSet();
success = imap.QueryMbx("ALL",true,msgSet);
if (success == false) {
Log.i(TAG, imap.lastErrorText());
return;
}
if (msgSet.get_Count() > 0) {
int uid = msgSet.GetId(0);
// FetchFlags returns a string, so assign it to a string variable and check for success.
String flags = imap.fetchFlags(uid,true);
if (imap.get_LastMethodSuccess() == false) {
Log.i(TAG, imap.lastErrorText());
return;
}
Log.i(TAG, "UID " + String.valueOf(uid) + " flags: " + flags);
}
success = imap.Disconnect();
if (success == false) {
Log.i(TAG, imap.lastErrorText());
return;
}
}
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."
}
}