Search code examples
emailwso2imapbouncycastleesb

WSO2 - Use of IMAPMessage incompatible with javax.mail?


I'm using WSO2 ESB to check emails from an IMAP mailbox. Some of the emails are signed and encrypted with a 256 certificate. I'm using BouncyCastle to decrypt the message. I have a compatibility issue over mail.jar (javax.mail).

1/ I'm getting the email:

if (message instanceof IMAPMessage) {

2/ I'm casting the message to BC:

final SMIMEEnveloped m = new SMIMEEnveloped((MimeMessage) message);

3/ I'm getting this error on this cast:

java.lang.IncompatibleClassChangeError: Class com.sun.mail.imap.IMAPMessage does not implement the requested interface javax.mail.Part
    at org.bouncycastle.mail.smime.SMIMEEnveloped.getInputStream(Unknown Source)
    at org.bouncycastle.mail.smime.SMIMEEnveloped.<init>(Unknown Source)

I'm using the bcprov-jdk15on-1.52.jar which is included in WSO2 ESB. I use mail-1.4.jar for javax.mail and com.sun.mail classes.

I'm thinking of a mail.jar version conflict but I can't find out where the other class comes from.

Help will be appreciated !


Solution

  • I finally managed to retreive emails from IMAP. You must override some libs of WSO2: bcmail-jdk15on-1.52.jar and jsch-0.1.51.wso2v1.jar to make SMIME decode code work. Copy those libs to wso2esb-5.0.0/repository/components/lib.

    Hope that helps someone else.