* Generate the first response right away because Ntlm will
* return null if the NTLM authentication support isn't
* available and then we can fail cleanly without invoking
* the AUTHENTICATE command.
*/
Ntlm ntlm = new Ntlm(debug ? out : null);
int flags = 0;
String domain = null;
String type1Msg = null;
try {
flags = PropUtil.getIntProperty(props,
"mail." + name + ".auth.ntlm.flags", 0);
boolean useUnicode = PropUtil.getBooleanProperty(props,
"mail." + name + ".auth.ntlm.unicode", true);
domain = props.getProperty(
"mail." + name + ".auth.ntlm.domain", "");
type1Msg = ntlm.generateType1Msg(useUnicode, flags,
domain, getLocalHost());
if (type1Msg == null) {
if (debug)
out.println("IMAP DEBUG: Can't load NTLM authenticator");
throw new ProtocolException("Can't load NTLM authenticator");
}
} catch (IOException ex) {
throw new ProtocolException("Error generating NTLM response", ex);
}
try {
tag = writeCommand("AUTHENTICATE NTLM", null);
} catch (Exception ex) {
// Convert this into a BYE response
r = Response.byeResponse(ex);
done = true;
}
OutputStream os = getOutputStream(); // stream to IMAP server
boolean first = true;
while (!done) { // loop till we are done
try {
r = readResponse();
if (r.isContinuation()) {
// Server challenge ..
String s;
if (first) {
s = type1Msg;
first = false;
} else {
int lmCompatibility = PropUtil.getIntProperty(props,
"mail." + name + ".auth.ntlm.lmcompat", 3);
s = ntlm.generateType3Msg(u, p,
domain, getLocalHost(),
r.getRest(),
flags,
lmCompatibility);
}