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");
}