Re: encrypted javamail MimeMultipart

On Jun 11, 2:40 pm, "euneve...@xxxxxxxxxxx" <euneve...@xxxxxxxxxxx>
On Jun 11, 1:06 pm, Martin Gregorie <mar...@xxxxxxxxxxxxxxxxxxxxxx>

On Thu, 10 Jun 2010 19:04:36 -0700, Roedy Green wrote:
On Thu, 10 Jun 2010 02:04:40 -0700 (PDT), "euneve...@xxxxxxxxxxx"
<euneve...@xxxxxxxxxxx> wrote, quoted or indirectly quoted someone who
said :

How can I cast this to a MimeMultipart ?

I have not done this myself, but it seems to me you need four steps:

1. get the armoured encrypted message characters, with headers stripped

2. strip off the armouring so you have an array of bytes.

3. run this through the decryption algorithm.

4. convert the decrypted bytes back into characters via some encoding..

(4) should become:
    - create a ByteArrayInputStream from the decrypted byte array
    - pass that to a MimeMessage constructor.

    At this point you can use the standard MimeMessage and MultiPart
    methods to parse the message and extract its content.

martin@   | Martin Gregorie
gregorie. | Essex, UK
org       |- Hide quoted text -

- Show quoted text -

Thanks Martin but maybe you can help me:

As I said I'm new to this Javamail api and am looking for a succinct
way to obtain the attachment

I can do

MimeMessage msg = new MimeMessage(session, new

The resulting msg has three headers which looks right

But when I do
if (msg.getContent() instanceof Multipart) {


It transpires it's NOT an object of type Multipart ... so what can I
do ???

I think at this stage it's basic javamail I require but am struggling.

Thanks.- Hide quoted text -

- Show quoted text -

In other words when I try this
Multipart multipart = (Multipart) content;
Exception in thread "main" java.lang.ClassCastException: