javax.mail.Store store =XoauthAuthenticator.connectToImap(XoauthAuthenticator.getSession(...), "
imap.googlemail.com", 993, <<email address>>);
From there, you're just using a standard-issue javax.mail.Store object, and you can use the javamail docs for that.
There are a couple code changes needed for the XoauthAuthenticator and XoauthSaslResponseBuilder classes.
For reference, I was able to put the below steps together using documentation here:
(especially note the "SASL Initial Client Request" section).
Assuming your application has already been granted 2LOA access to the "
https://mail.google.com/" scope, the following changes should work for you:
1) change the XoauthAuthenticator class constructor to not put the following 2 key/values into the props object. These are only used in 3-legged OAuth:
- XoauthSaslClientFactory.OAUTH_TOKEN_PROP
- XoauthSaslClientFactory.OAUTH_TOKEN_SECRET_PROP
2) Change the code in XoauthSaslResponseBuilder.buildResponse method that deals with putting the OAuthToken into the response.
First, remove the line:
parameters.put(OAuth.OAUTH_TOKEN, oauthToken);
Second, change the 'url' variable to append the "xoauth_requestor_id" parameter onto the URL so that the correct user's IMAP session is opened.
try {
url = String.format("%s?xoauth_requestor_id=%s", url, URLEncoder.encode(userEmail, "UTF-8"));
}
catch (UnsupportedEncodingException ex) {
// not going to happen - UTF-8 is guaranteed by every jvm
}
Good luck -
Vince.