From 738ff861ea5bb9387e22d5cfd70334a7d3f6b88b Mon Sep 17 00:00:00 2001 From: mguessan Date: Tue, 23 Dec 2008 15:20:50 +0000 Subject: [PATCH] Disable galLookup on error (not supported by Exchange 2007) git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@245 3d1905a2-6b24-0410-a738-b14d5a86fcbd --- .../davmail/exchange/ExchangeSession.java | 47 ++++++++++--------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/src/java/davmail/exchange/ExchangeSession.java b/src/java/davmail/exchange/ExchangeSession.java index 778985dc..f8d283e6 100644 --- a/src/java/davmail/exchange/ExchangeSession.java +++ b/src/java/davmail/exchange/ExchangeSession.java @@ -83,6 +83,8 @@ public class ExchangeSession { private final ExchangeSessionFactory.PoolKey poolKey; + private boolean disableGalLookup = false; + ExchangeSessionFactory.PoolKey getPoolKey() { return poolKey; } @@ -304,7 +306,7 @@ public class ExchangeSession { String result = null; // get user mail URL from html body BufferedReader optionsPageReader = null; - GetMethod optionsMethod = new GetMethod(path+"?ae=Options&t=About"); + GetMethod optionsMethod = new GetMethod(path + "?ae=Options&t=About"); try { wdr.retrieveSessionInstance().executeMethod(optionsMethod); optionsPageReader = new BufferedReader(new InputStreamReader(optionsMethod.getResponseBodyAsStream())); @@ -317,7 +319,7 @@ public class ExchangeSession { if (line != null) { int start = line.toLowerCase().indexOf(MAILBOX_BASE) + MAILBOX_BASE.length(); int end = line.indexOf("<", start); - result = "/exchange/"+line.substring(start, end)+"/"; + result = "/exchange/" + line.substring(start, end) + "/"; } } catch (IOException e) { LOGGER.error("Error parsing options page at " + optionsMethod.getPath()); @@ -1200,26 +1202,29 @@ public class ExchangeSession { } public void galLookup(Map person) { - GetMethod getMethod = null; - try { - getMethod = new GetMethod(URIUtil.encodePathQuery("/public/?Cmd=gallookup&ADDR=" + person.get("EM"))); - int status = wdr.retrieveSessionInstance().executeMethod(getMethod); - if (status != HttpStatus.SC_OK) { - throw new IOException(status + "Unable to find users from: " + getMethod.getURI()); - } - Map> results = XMLStreamUtil.getElementContentsAsMap(getMethod.getResponseBodyAsStream(), "person", "alias"); - // add detailed information - if (results.size() > 0) { - Map fullperson = results.get(person.get("AN")); - for (Map.Entry entry : fullperson.entrySet()) { - person.put(entry.getKey(), entry.getValue()); + if (!disableGalLookup) { + GetMethod getMethod = null; + try { + getMethod = new GetMethod(URIUtil.encodePathQuery("/public/?Cmd=gallookup&ADDR=" + person.get("EM"))); + int status = wdr.retrieveSessionInstance().executeMethod(getMethod); + if (status != HttpStatus.SC_OK) { + throw new IOException(status + "Unable to find users from: " + getMethod.getURI()); + } + Map> results = XMLStreamUtil.getElementContentsAsMap(getMethod.getResponseBodyAsStream(), "person", "alias"); + // add detailed information + if (results.size() > 0) { + Map fullperson = results.get(person.get("AN")); + for (Map.Entry entry : fullperson.entrySet()) { + person.put(entry.getKey(), entry.getValue()); + } + } + } catch (IOException e) { + LOGGER.warn("Unable to gallookup person: " + person + ", disable GalLookup"); + disableGalLookup = true; + } finally { + if (getMethod != null) { + getMethod.releaseConnection(); } - } - } catch (IOException e) { - LOGGER.warn("Unable to gallookup person: " + person); - } finally { - if (getMethod != null) { - getMethod.releaseConnection(); } } }