Hi,
In my application I want to decode all my incoming mails.So I have
implemented a mailet through which all incoming mails will pass in the
beginning for getting decoded.In this mailet ,for character decoding an
incoming message , I am retrieving the text string from a bodypart and
character-decoding it using the "charset" obtained from body part. Then I am
creating a new body part with this decoded string . Then I am removing the
old bodypart and adding this new bodypart at that place. I am creating a new
ParameterList and setting "charset" as a parameter . Then I set this list to
the Content Type of new bodypart. The sample code of the method is as
follows:-

            MimeMessage message = mail.getMessage();
//mail is an object of class implementing Mail interface
            MimeMultipart multiPart = (MimeMultipart) message.getContent();
            mimeBodyPart = (MimeBodyPart) (((BodyPart)
multiPart.getBodyPart(i)));
//Creating mime Bodypart object from multipart.
            String strCharset = (new
ContentType(mimeBodyPart.getContentType())).getParameter("charset");
//Retrieving the charset

            InputStream is = mimeBodyPart.getInputStream();
            is.read(b);
//Reading the inputstream into a byte array.
            decodedString = new String(b,strCharset);
//Creating the decoded string.

            MimeBodyPart newBodyPart = new MimeBodyPart(new
InternetHeaders(is),decodedString.getBytes());        //Creating the new
bodypart here.
            ContentType newContentType = new
ContentType(newBodyPart.getContentType());
//Getting Content Type object of new bodypart.
            ParameterList parameterList=new ParameterList();
//Creating a new parameter list.
            parameterList.set("charset",strCharset);
//Setting 'charset' as a parameter in parameter list.
            newContentType.setParameterList(parameterList);
            multiPart.removeBodyPart(1);
//Removing the old body part at position 1
            multiPart.addBodyPart(newBodyPart[1], 1);
//Adding the new body part.


And finally I do message.setContent(multiPart) and message.saveChanges() to
save the changes made. So, the changes are saved to Mail object.  But when I
am retrieving the text in bodypart  within Mail object  at later  mailets
of my application ,I am getting corrupted data and if I am retrieving the
'charset' parameter later I am getting a different value.e.g. if initially
the value is "iso-8859-1" of 'charset', i am getting the 'charset' parameter
value as "us-ascii" later.  Why the message in Mail object is not retrieved
correctly?

Regards,

Sandeep Rath.


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

Reply via email to