Android™
Android™
Count the Attached Messages in an Email
See more Email Object Examples
Demonstrates the read-only Chilkat Email.NumAttachedMessages property, which is the number of embedded emails represented by message/rfc822 MIME parts. These are counted separately from ordinary attachments and related items, and their indexes are zero-based. This example builds an inner email, attaches it to an outer email as a nested message, and prints the count.
Background: When you "forward as attachment," many mail clients embed the original message as a complete nested email rather than quoting its text. In MIME this appears as a
message/rfc822 part — an entire email (its own headers and body) tucked inside the carrier message. Chilkat distinguishes three kinds of enclosed content: ordinary attachments (NumAttachments), inline related items (NumRelatedItems), and these nested messages (NumAttachedMessages). Use GetAttachedEmail to pull an embedded message into its own Email object.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 read-only Email.NumAttachedMessages property, which is the
// number of embedded emails (message/rfc822 MIME parts) contained in the email.
// Create an inner email that we'll attach as a complete nested message.
CkEmail innerEmail = new CkEmail();
innerEmail.put_Subject("I am an attached message");
innerEmail.put_Body("This entire email is nested inside another email.");
innerEmail.put_From("alice@example.com");
innerEmail.AddTo("Bob","bob@example.com");
// Create the outer email and attach the inner email directly as a
// message/rfc822 part. AttachEmail attaches a copy of the inner email.
CkEmail email = new CkEmail();
email.put_Subject("Outer email with an attached message");
email.put_Body("See the attached email.");
success = email.AttachEmail(innerEmail);
Log.i(TAG, "NumAttachedMessages = " + 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."
}
}