Skip to content

Instantly share code, notes, and snippets.

@chibenwa
Last active September 13, 2019 04:01
Show Gist options
  • Select an option

  • Save chibenwa/abd12fd6c0b06cadd1de591e3ac792b9 to your computer and use it in GitHub Desktop.

Select an option

Save chibenwa/abd12fd6c0b06cadd1de591e3ac792b9 to your computer and use it in GitHub Desktop.
Demonstrate use of commons-net with delegation on top of James, for writing Java administration scripts
public void authenticate(String targetUser, String authenticatorId, String password) throws IOException {
Preconditions.checkState(imapClient.getState() == IMAP.IMAPState.NOT_AUTH_STATE);
String loginString = targetUser + "\0" + authenticatorId + "\0" + password;
String b64 = Base64.getEncoder().encodeToString(loginString.getBytes(StandardCharsets.UTF_8));
boolean success = imapClient.doCommand(IMAPCommand.AUTHENTICATE, "\"PLAIN\" " + b64 + "\r\n");
if (!success) {
throw new IOException("Authentication failed");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment