Merge "Add support for SMTP AUTH LOGIN to AuthSMTPClient"

This commit is contained in:
Shawn Pearce
2011-03-27 14:29:42 -07:00
committed by Android Code Review

View File

@@ -103,10 +103,12 @@ public class AuthSMTPClient extends SMTPClient {
if (types.contains("CRAM-MD5")) {
return authCram(smtpUser, smtpPass, "MD5");
}
if (types.contains("LOGIN")) {
return authLogin(smtpUser, smtpPass);
}
if (types.contains("PLAIN")) {
return authPlain(smtpUser, smtpPass);
}
throw new IOException("Unsupported AUTH: " + authTypes);
}
@@ -135,6 +137,21 @@ public class AuthSMTPClient extends SMTPClient {
return SMTPReply.isPositiveCompletion(sendCommand(cmd));
}
private boolean authLogin(String smtpUser, String smtpPass) throws UnsupportedEncodingException,
IOException {
if (sendCommand("AUTH", "LOGIN") != 334) {
return false;
}
String cmd = encodeBase64(smtpUser.getBytes(UTF_8));
if(sendCommand(cmd) != 334) {
return false;
}
cmd = encodeBase64(smtpPass.getBytes(UTF_8));
return SMTPReply.isPositiveCompletion(sendCommand(cmd));
}
private static final char[] hexchar =
{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};