Java can't create MIME Header?

OK, I’m using a Java agent to loop through and convert an number of Base64 strings to the images they represent. I’m having trouble setting the headerVal. Below is the block of code. Logging shows I’m getting the body as it is already a MIMEEntity, but even thought I create the header, (twice) it’s not their either time - so both lines where I say the header is null print. I finally get a null pointer exception on the header.setHeaderVal(“image/png”) line. Can someone please tell me what I’m missing here?

Cheers,

Brian

MIMEEntity body;

if(doc.hasItem(“body”)){

	System.out.println("has MIME body"); 

	body = doc.getMIMEEntity("body"); 

} else {

	System.out.println("before create MIME body"); 

	body = doc.createMIMEEntity(); 

}

if(body == null){

	body = doc.createMIMEEntity(); 

	System.out.println("body was null"); 

}

System.out.println(“after body item”);

allObjects.addElement(body);

if (body == null){

	System.out.println("hmm, body is null"); 

}

System.out.println(“before header”);

//MIMEHeader header = null;

MIMEHeader header = body.createHeader(“Content-Type”);

System.out.println(“after header”);

if(header == null ){

	System.out.println("header was null???"); 

	header = body.createHeader("Content-Type"); 

	System.out.println("after header null create"); 

}

allObjects.addElement(header);

if(header == null ){

	System.out.println("header was null AGAIN???"); 

	header = body.createHeader("Content-Type"); 

	System.out.println("after header null create AGAIN"); 

}

System.out.println(“after header add object”);

header.setHeaderVal(“image/png”);