Last active
September 13, 2019 04:01
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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