Home > database >  issue with getDefaultInstance and javax.mail.Session, java.io.InputStream
issue with getDefaultInstance and javax.mail.Session, java.io.InputStream

Time:06-28

I have looking around for answer to these two errors, and have not found the solution.

Cannot resolve method 'getDefaultInstance' in 'Session'
'MimeMessage(javax.mail.Session, java.io.InputStream)' in 'javax.mail.internet.MimeMessage' cannot be applied to '(android.se.omapi.Session, android.net.Uri)'

Am I missing something as to using the package?

public void getBodySignature(Uri uri) throws Exception {
        Properties properties = System.getProperties();

        Session session = Session.getDefaultInstance(properties, null);
        MimeMessage msg = new MimeMessage(session, uri);
        SMIMESigned signedMessage;
        // multipart/signed message
        // two parts- one part for the content that was signed and one part for the actual signature.
        if (msg.isMimeType("multipart/signed")) {
            signedMessage = new SMIMESigned((MimeMultipart) msg.getContent());
        } else if (msg.isMimeType("text/plain") || msg.isMimeType("application/pkcs7-signature")) {
            // in this case the content is wrapped in the signature block.
            signedMessage = new SMIMESigned(msg);
        } else {
            throw new IllegalArgumentException("Not a signed message!");
        }

CodePudding user response:

Your Session import is the wrong one. Replace the import for android.se.omapi.Session with javax.mail.Session. If that causes other issues, because you need both imports, then for one of them you to use the fully qualified name. For instance:

javax.mail.Session session = javax.mail.Session.getDefaultInstance(properties, null);

The other issue is the Uri argument. There is no MimeMessage constructor that takes a URI or Uri argument. I assume that you have an existing message as a file and want to read from it. You'd need to convert the Uri to an InputStream. I couldn't find anything for that in https://developer.android.com/reference/android/net/Uri. I'd see if you can get rid of the Uri argument completely and replace it with an InputStream or something that can be converted to an InputStream.

  • Related