Android™
Android™
Remove a Single Attached Message from an Email
See more Email Object Examples
Demonstrates the Chilkat Email.RemoveAttachedMessage method, which removes the Nth message/rfc822 sub-part (an attached email) from the message. Indexing begins at 0. This example attaches an email, removes it, and prints the attached-message count before and after.
Background: Attached messages (forwarded emails carried as
message/rfc822 parts) are counted and indexed separately from ordinary file attachments and related items. RemoveAttachedMessage targets just one nested email by index — useful, for example, when trimming a bundled digest or stripping a forwarded original before re-sending.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 RemoveAttachedMessage method, which removes the Nth message/rfc822
// sub-part (attached email) of the email. The index is zero-based.
// Build an inner email and attach it to an outer email.
CkEmail innerEmail = new CkEmail();
innerEmail.put_Subject("Embedded message");
innerEmail.put_From("alice@example.com");
CkEmail email = new CkEmail();
email.put_Subject("Has an attached message");
success = email.AttachEmail(innerEmail);
if (success == false) {
Log.i(TAG, email.lastErrorText());
return true;
}
Log.i(TAG, "NumAttachedMessages before = " + String.valueOf(email.get_NumAttachedMessages()));
// Remove the first attached message (index 0).
email.RemoveAttachedMessage(0);
Log.i(TAG, "NumAttachedMessages after = " + String.valueOf(email.get_NumAttachedMessages()));
}
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."
}
}