You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-user@james.apache.org by Craig Harris <ha...@SummerEyes.com> on 2005/02/17 08:31:04 UTC

Problem: BodyPart setContent( string, "text/html" ) results in "text/plain"?

James 2.2.0, Phoenix 4.0.1

In a mailet that extends GenericMailet, in the service method, I have the following: 

    ...
    MimeMessage msg = newMail.getMessage( );
    if ( msg.getContent( ) instanceof Multipart) {
        Multipart mpart = (Multipart) msg.getContent( );
        for (int ix=0, iNumParts=mpart.getCount(); ix < iNumParts; ix++) {
            BodyPart part = mpart.getBodyPart( ix );

            if (part.getContentType( ).startsWith( "text/html" )) {

                String htmlString = generatePartContent( ... );    // a function that produces html text
                log( "before setContent: part.getContentType() = " +part.getContentType( ) );        // text/html;... here   
                part.setContent( htmlString, part.getContentType() );
                log( "after  setContent: part.getContentType() = " +part.getContentType( ) );        // text/plain  here

    ...

before the part.setContent statement, the part's content type is reported as :

    text/html;
 charset="iso-8859-1"

after the setContent call, it is reported as "text/plain"


I seem to have lost both the "html" as well as the charset information.  

Bizarre, no?  Anyone have similar experience???


-- Craig Harris
harris@SummerEyes.com

Re: Problem: BodyPart setContent( string, "text/html" ) results in "text/plain"?

Posted by Danny Angus <da...@gmail.com>.
this is a JavaMail issue, nothing to do with James.

However, try 
 part.setContent( htmlString, "text/html" );

instead of
 part.setContent( htmlString, part.getContentType() );

which, in your example is equivalent to
 part.setContent( htmlString, "text/html;\n  charset=\"iso-8859-1\"");

and read the javadocs for Part, particularly the bit about appropriate
handlers being available.

I suspect that it is simply failing to recognise the type because you
are also mentioning the charset.

d.

On Thu, 17 Feb 2005 02:31:04 -0500, Craig Harris <ha...@summereyes.com> wrote:
> James 2.2.0, Phoenix 4.0.1
> 
> In a mailet that extends GenericMailet, in the service method, I have the following:
> 
>     ...
>     MimeMessage msg = newMail.getMessage( );
>     if ( msg.getContent( ) instanceof Multipart) {
>         Multipart mpart = (Multipart) msg.getContent( );
>         for (int ix=0, iNumParts=mpart.getCount(); ix < iNumParts; ix++) {
>             BodyPart part = mpart.getBodyPart( ix );
> 
>             if (part.getContentType( ).startsWith( "text/html" )) {
> 
>                 String htmlString = generatePartContent( ... );    // a function that produces html text
>                 log( "before setContent: part.getContentType() = " +part.getContentType( ) );        // text/html;... here
>                 part.setContent( htmlString, part.getContentType() );
>                 log( "after  setContent: part.getContentType() = " +part.getContentType( ) );        // text/plain  here
> 
>     ...
> 
> before the part.setContent statement, the part's content type is reported as :
> 
>     text/html;
>  charset="iso-8859-1"
> 
> after the setContent call, it is reported as "text/plain"
> 
> I seem to have lost both the "html" as well as the charset information.
> 
> Bizarre, no?  Anyone have similar experience???
> 
> 
> -- Craig Harris
> harris@SummerEyes.com
> 
>

---------------------------------------------------------------------
To unsubscribe, e-mail: server-user-unsubscribe@james.apache.org
For additional commands, e-mail: server-user-help@james.apache.org