NullPointerException in Header.writeTo with missing Content-Type
----------------------------------------------------------------

                 Key: MIME4J-36
                 URL: https://issues.apache.org/jira/browse/MIME4J-36
             Project: Mime4j
          Issue Type: Bug
            Reporter: Aljoscha Rittner


I get a NPE with very simple mails. 

java.lang.NullPointerException
        at org.apache.james.mime4j.message.Header.writeTo(Header.java:148)
        at org.apache.james.mime4j.message.Message.writeTo(Message.java:86)

IMHO, a missing Content-Type is legal (in this case, the body is text/plain).

The writeTo Method in Header needs an extra if-clause for missing Content-Type 
header.

org.apache.james.mime4j.message.Header
...

    public void writeTo(OutputStream out) throws IOException {
        ///////////////////   NPE in case of missing Content-Type declaration:
        String charString = ((ContentTypeField) 
getField(Field.CONTENT_TYPE)).getCharset();  
        
        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(out, 
CharsetUtil.getCharset(charString)),8192);
        writer.write(toString()+ "\r\n");
        writer.flush();
    }

best regards,
  josh.


-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to