use of microsoft.exchange.webservices.data.property.complex.FolderId in project iaf by ibissource.
the class ExchangeMailListener method configure.
public void configure() throws ConfigurationException {
try {
exchangeService = new ExchangeService(ExchangeVersion.Exchange2010_SP2);
CredentialFactory cf = new CredentialFactory(getAuthAlias(), getUserName(), getPassword());
ExchangeCredentials credentials = new WebCredentials(cf.getUsername(), cf.getPassword());
exchangeService.setCredentials(credentials);
if (StringUtils.isNotEmpty(getMailAddress())) {
exchangeService.autodiscoverUrl(getMailAddress());
} else {
exchangeService.setUrl(new URI(getUrl()));
}
FolderId inboxId;
if (StringUtils.isNotEmpty(getMailAddress())) {
Mailbox mailbox = new Mailbox(getMailAddress());
inboxId = new FolderId(WellKnownFolderName.Inbox, mailbox);
} else {
inboxId = new FolderId(WellKnownFolderName.Inbox);
}
FindFoldersResults findFoldersResultsIn;
FolderView folderViewIn = new FolderView(10);
if (StringUtils.isNotEmpty(getInputFolder())) {
SearchFilter searchFilterIn = new SearchFilter.IsEqualTo(FolderSchema.DisplayName, getInputFolder());
findFoldersResultsIn = exchangeService.findFolders(inboxId, searchFilterIn, folderViewIn);
if (findFoldersResultsIn.getTotalCount() == 0) {
throw new ConfigurationException("no (in) folder found with name [" + getInputFolder() + "]");
} else if (findFoldersResultsIn.getTotalCount() > 1) {
throw new ConfigurationException("multiple (in) folders found with name [" + getInputFolder() + "]");
}
} else {
findFoldersResultsIn = exchangeService.findFolders(inboxId, folderViewIn);
}
folderIn = findFoldersResultsIn.getFolders().get(0);
if (StringUtils.isNotEmpty(getFilter())) {
if (!getFilter().equalsIgnoreCase("NDR")) {
throw new ConfigurationException("illegal value for filter [" + getFilter() + "], must be 'NDR' or empty");
}
}
if (StringUtils.isNotEmpty(getOutputFolder())) {
SearchFilter searchFilterOut = new SearchFilter.IsEqualTo(FolderSchema.DisplayName, getOutputFolder());
FolderView folderViewOut = new FolderView(10);
FindFoldersResults findFoldersResultsOut = exchangeService.findFolders(inboxId, searchFilterOut, folderViewOut);
if (findFoldersResultsOut.getTotalCount() == 0) {
throw new ConfigurationException("no (out) folder found with name [" + getOutputFolder() + "]");
} else if (findFoldersResultsOut.getTotalCount() > 1) {
throw new ConfigurationException("multiple (out) folders found with name [" + getOutputFolder() + "]");
}
folderOut = findFoldersResultsOut.getFolders().get(0);
}
} catch (Exception e) {
throw new ConfigurationException(e);
}
}
Aggregations