Skip to content

Instantly share code, notes, and snippets.

@crearo
Created January 19, 2016 09:45
Show Gist options
  • Save crearo/4c8e15c89d4f895e2987 to your computer and use it in GitHub Desktop.
Save crearo/4c8e15c89d4f895e2987 to your computer and use it in GitHub Desktop.
private void fetchContacts() {
ZcsService zcsService = new ZcsService("https://webmail.daiict.ac.in/service/soap", 2, true);
AccountSelector accountSelector = new AccountSelector();
accountSelector.setBy(AccountBy.OPT5_NAME);
accountSelector.setValue(username);
AuthRequest authRequest = new AuthRequest();
authRequest.setAccount(accountSelector);
authRequest.setCsrfTokenSecured(true);
authRequest.setPersistAuthTokenCookie(true);
authRequest.setPassword(pwd);
try {
AuthResponse authResponse = zcsService.authRequest(authRequest, null);
HeaderAccountInfo headerAccountInfo = new HeaderAccountInfo();
headerAccountInfo.setValue(username);
headerAccountInfo.setBy("name");
HeaderContext headerContext = new HeaderContext();
headerContext.setAccount(headerAccountInfo);
headerContext.setAuthToken(authResponse.getAuthToken());
headerContext.setCsrfToken(authResponse.getCsrfToken());
zimbra.Context context = new zimbra.Context();
context.setContext(headerContext);
zimbramail.AutoCompleteRequest autoCompleteRequest = new zimbramail.AutoCompleteRequest();
autoCompleteRequest.setName(searchText);
autoCompleteRequest.setNeedExp(true);
AutoCompleteResponse autoCompleteResponse = zcsService.autoCompleteRequest(autoCompleteRequest, context);
AutoCompleteMatch autoCompleteMatch[] = autoCompleteResponse.getMatch();
addresses = new String[autoCompleteMatch.length];
for (int i = 0; i < addresses.length; i++) {
addresses[i] = autoCompleteMatch[i].getEmail();
}
result = true;
} catch (IOException e) {
addresses = null;
e.printStackTrace();
result = false;
} catch (XmlPullParserException e) {
addresses = null;
e.printStackTrace();
result = false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment