0

I'm getting the following error when trying to connect to the imap store using JavaMail in an Android app:

IMAP DEBUG: Can't load SASL authenticator: java.lang.NoSuchMethodException: [class com.sun.mail.imap.protocol.IMAPProtocol, class java.lang.String, class java.util.Properties, boolean, class java.io.PrintStream, class java.lang.String]

The issue I am having appears to the the same as the one describe here: ProGuard java.lang.NoSuchMethodException

...but the solution of adding the line to the proguard did not help.

public class OAuth2SaslClientFactory implements SaslClientFactory {
    private static final Logger logger =
    Logger.getLogger(OAuth2SaslClientFactory.class.getName());

    public static final String OAUTH_TOKEN_PROP =
      "mail.imaps.sasl.mechanisms.oauth2.oauthToken";

    public SaslClient createSaslClient(String[] mechanisms,
                                 String authorizationId,
                                 String protocol,
                                 String serverName,
                                 Map<String, ?> props,
                                 CallbackHandler callbackHandler) {
    boolean matchedMechanism = false;
    for (int i = 0; i < mechanisms.length; ++i) {
         if ("XOAUTH2".equalsIgnoreCase(mechanisms[i])) {
           matchedMechanism = true;
            break;
         }
      }
      if (!matchedMechanism) {
         logger.info("Failed to match any mechanisms");
         return null;
      }
      return new OAuth2SaslClient((String) props.get(OAUTH_TOKEN_PROP),
                            callbackHandler);
   }

   public String[] getMechanismNames(Map<String, ?> props) {
      return new String[] {"XOAUTH2"};
   }
}

public OAuth2Provider() {
      super("Google OAuth2 Provider", 1.0,
            "Provides the XOAUTH2 SASL Mechanism");
          put("SaslClientFactory.XOAUTH2",
                  "com.app.OAuth2SaslClientFactory");
}
Community
  • 1
  • 1
user2120910
  • 404
  • 1
  • 5
  • 16

2 Answers2

0

I wasn't able to determine exactly what in the proguard was missing, but I did end getting the project to run by adding the following line to the proguard file:

-dontshrink
user2120910
  • 404
  • 1
  • 5
  • 16
-1

Have you tried using JavaMail 1.5.2, which includes built-in OAuth2 support, and thus doesn't require any of that code you've included above?

Bill Shannon
  • 29,579
  • 6
  • 38
  • 40