Basically, I wrote an application which reads emails from an inbox. I've always tested the application with e-mail sent from Gmail. But now when I am trying to read an e-mail which was sent from Outlook, I am not getting any content back.
I logged the contenttypes from both the e-mails:
Gmail returns: multipart/alternative; boundary=047d7b342bf2b6847f04d11df78a
Outlook returns: text/html; charset=iso-8859-1 
Note: These are the same e-mails, just sent from different mail clients.
Mail from Gmail will be an instance of Multipart. While Outlook email will be an instance of String.
My code:
The method which checks if the message is an instanceof Multipart or String.
public void getContent(Message msg) throws IOException, Exception {
    Object contt = msg.getContent();
    System.out.println("Contenttype: " + msg.getContentType());
    if (contt instanceof Multipart) {
        checkDisposition = true;
        handleMultipart((Multipart) contt);
    } else if (contt instanceof String) {   
       handlePart((Part) msg);
    }
    prepareEmail(mpMessage);
}
If the message is multipart this method will be called:
public void handleMultipart(Multipart multipart)
        throws MessagingException, IOException, Exception {
    mpMessage = getText(multipart.getBodyPart(0));
    for (int z = 1, n = multipart.getCount(); z < n; z++) {
        handlePart(multipart.getBodyPart(z));
    }
}
If the message isn't this will be called directly:
public void handlePart(Part part)
        throws MessagingException, IOException, Exception {
    Object con = messageCopy.getContent();
    String disposition = part.getDisposition();
    String contentType = part.getContentType();
    if (checkDisposition) {
        if (disposition == null) {
            System.out.println("Disposition is null");
        } else if (disposition.equalsIgnoreCase(Part.ATTACHMENT)) {
            System.out.println("Attachment: " + part.getFileName()
                    + " : " + contentType);
            input = part.getInputStream();
            bytes = IOUtils.toByteArray(input);
        } else if (disposition.equalsIgnoreCase(Part.INLINE)) {
            System.out.println("Inline: "
                    + part.getFileName()
                    + " : " + contentType);
        } else {
            System.out.println("Other: " + disposition);
        }
    }else{
        mpMessage = part.getContent().toString(); //returns nothing
        System.out.println("mpMessage handlePart "+mpMessage); //returns nothing
        System.out.println("mpMessage handlePart "+part.getLineCount()); //returns 0
        System.out.println("mpMessage handlePart "+part.getContentType()); //returns text/html chartset=iso-8859-1
        System.out.println("mpMessage handlePart "+part.getSize()); // returns 22334
        part.writeTo(System.out); //See below
    }
}
The method which returns the text from the parts:
private String getText(Part p) throws
        MessagingException, IOException {
    System.out.println("getText contentType "+p.getContentType());
//This part gets called if trying to read an Outlook mail, its not clear for me how to  retrieve the text from the part. Since `p.getContent()` returns nothing
    if (p.isMimeType("text/*")) {
        String s = (String) p.getContent();
        System.out.println();
        return String.valueOf(s);
    }
    if (p.isMimeType("multipart/alternative")) {
        Multipart mp = (Multipart) p.getContent();
        String text = null;
        for (int i = 0; i < mp.getCount(); i++) {
            Part bp = mp.getBodyPart(i);
            if (bp.isMimeType("text/plain")) {
                String s = getText(bp);
                if (s != null) {
                    return s;
                }
            }
        }
        return text;
    }
    return null;
}
part.writeTo(System.out) returns:
Received: from AMSPRD0710HT005.eurprd07.prod.outlook.com Server (TLS) id 00000; Thu, 20 Dec 2012 09:28:23 +0000 Received: from AMSPRD0710MB354.eurprd07.prod.outlook.com ([00.000.0000]) by AMSPRD0710HT005.eurprd07.prod.outlook.com ([00.000.0000]) with mapi id 14.16.0245.002; Thu, 20 Dec 2012 09:28:05 +0000 From: test To: support Subject: Verwerkingsverslag Kenmerk: 0824496 Thread-Topic: Verwerkingsverslag Kenmerk: 0824496 Thread-Index: Ac3elFC2qYsSo+SOT2ii4HnbCCqgVw== Date: Thu, 20 Dec 2012 10:28:05 +0100 Message-ID:...
And so on.
The content of the message itself gets returned as HTML code, not just normal text.
How do I retrieve the plain text from the Outlook email, instead of the HTML code? Or how do I retrieve the content of the part in handlePart?
Any help is appreciated,
Thanks!