Android™
Android™
Unpack an HTML Email to Files
See more Email Object Examples
Demonstrates the Chilkat Email.UnpackHtml method, which unpacks an HTML email into an HTML file plus separate related files (images and style sheets). Links in the HTML are rewritten to reference the unpacked files. The arguments are the unpack directory, the HTML filename, and the subdirectory for the related parts. This example loads an HTML email and unpacks it.
Background: An HTML email keeps its images and style sheets inside the message (referenced by
cid:), which a browser cannot open directly. Unpacking writes each part out as a real file and rewrites the references into ordinary paths, so the saved HTML displays correctly — useful for archiving a message as a browsable folder or previewing it outside a mail client. The UnpackUseRelPaths property controls whether the rewritten links use relative or absolute paths; for a single self-contained file, see CreateTempMht, and for web serving see AspUnpack.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 UnpackHtml method, which unpacks an HTML email into an HTML file plus
// separate related files (images, style sheets). Links in the HTML are rewritten to
// reference the unpacked files. Arguments: unpackDir, htmlFilename, partsSubdir.
CkEmail email = new CkEmail();
success = email.LoadEml("qa_data/eml/html_with_images.eml");
if (success == false) {
Log.i(TAG, email.lastErrorText());
return true;
}
// Unpack the HTML body and its related files to the filesystem.
success = email.UnpackHtml("qa_output/unpacked","message.html","parts");
if (success == false) {
Log.i(TAG, email.lastErrorText());
return true;
}
Log.i(TAG, "Unpacked the HTML email to disk.");
// Note: Paths such as "qa_data/..." and "qa_output/..." are relative local
// filesystem paths, relative to the current working directory of the running application.
}
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."
}
}