Android™
Android™
Send a Raw IMAP Command (Binary)
See more IMAP Examples
Demonstrates the Chilkat Imap.RawCommandBd method, which sends raw IMAP command bytes and receives the raw response bytes. The first argument is a BinData holding the command — without an IMAP tag or trailing CRLF, which Chilkat supplies — and the second is a BinData that receives the response.
Background: This is an escape hatch for rare server extensions the API does not otherwise expose. It is intended for commands with a single-line response that do not change
Imap object state such as the selected mailbox or message count. For everyday operations, use the dedicated methods, which parse responses and maintain object state for you.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.RawCommandBd method, which sends raw IMAP command bytes and receives
// the raw response bytes. The 1st argument is a BinData containing the command (without a tag
// or trailing CRLF -- Chilkat supplies both), and the 2nd is a BinData that receives the
// response.
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;
}
// Build the raw command. Do not include an IMAP tag or a trailing CRLF.
CkBinData bdCmd = new CkBinData();
bdCmd.AppendString("CAPABILITY","utf-8");
CkBinData bdResp = new CkBinData();
success = imap.RawCommandBd(bdCmd,bdResp);
if (success == false) {
Log.i(TAG, imap.lastErrorText());
return;
}
// Interpret the response bytes as a UTF-8 string.
String respStr = bdResp.getString("utf-8");
Log.i(TAG, respStr);
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."
}
}