Sample code for 30+ languages & platforms
Android™

Unobfuscate a Spammy Email

See more Email Object Examples

Demonstrates the Chilkat Email.UnSpamify method, which unobfuscates an email by undoing common spammer tricks — it removes comments from HTML bodies and unobfuscates hyperlinked URLs. This example cleans an HTML body whose link was broken up by an inserted comment.

Background: Spammers deliberately scramble HTML to slip past filters — inserting empty comments in the middle of words or URLs (exa<!--x-->mple.com), or otherwise obfuscating links — so the message renders normally to a human but confuses naive keyword matching. UnSpamify reverses those tricks, producing a normalized body that is easier to analyze, classify, or scan for the real destination of its links.

Chilkat Android™ Downloads

Android™
// 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);

    //  Demonstrates the UnSpamify method, which unobfuscates an email by undoing common spammer
    //  tricks: it removes comments from HTML bodies and unobfuscates hyperlinked URLs.

    CkEmail email = new CkEmail();
    email.put_Subject("UnSpamify example");

    //  An HTML body with an obfuscating comment inserted into a hyperlink.
    email.SetHtmlBody("<html><body>Visit <a href=\"http://exa<!--x-->mple.com\">our site</a>.</body></html>");

    //  Undo the obfuscation.
    email.UnSpamify();

    String cleaned = email.getHtmlBody();
    Log.i(TAG, cleaned);

  }

  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."
  }
}