Sample code for 30+ languages & platforms
Java

Check if a MIME Entity is multipart/alternative

See more MIME Examples

Demonstrates the Chilkat Mime.IsMultipartAlternative method, which returns whether the Content-Type is exactly multipart/alternative. It takes no arguments.

Note: The file path is relative to the application's current working directory. Absolute paths may also be used. Supply the path to your own file.

Background: Recognizing multipart/alternative matters because its children are the same content in different formats — you display one (usually the last renderable), not all of them. That is the opposite of multipart/mixed, where every child is shown.

Chilkat Java Downloads

Java
import com.chilkatsoft.*;

public class ChilkatExample {

  static {
    try {
        System.loadLibrary("chilkat");
    } catch (UnsatisfiedLinkError e) {
      System.err.println("Native code library failed to load.\n" + e);
      System.exit(1);
    }
  }

  public static void main(String argv[])
  {
    boolean success = false;

    //  Demonstrates the Mime.IsMultipartAlternative method, which returns whether the Content-Type is multipart/alternative.  It takes no arguments.

    CkMime mime = new CkMime();
    success = mime.LoadMimeFile("qa_data/multipart_message.eml");
    if (success == false) {
        System.out.println(mime.lastErrorText());
        return;
        }

    if (mime.IsMultipartAlternative()) {
        System.out.println("This is a multipart/alternative entity.");
        }
    else {
        System.out.println("This is not multipart/alternative.");
        }
  }
}