diff --git a/src/java/davmail/caldav/CaldavConnection.java b/src/java/davmail/caldav/CaldavConnection.java index 9a66197c..d2feb4c1 100644 --- a/src/java/davmail/caldav/CaldavConnection.java +++ b/src/java/davmail/caldav/CaldavConnection.java @@ -258,13 +258,12 @@ public class CaldavConnection extends AbstractConnection { sendHttpResponse(itemResult.status, buildEtagHeader(itemResult.etag), null, "", true); } else if (request.isDelete()) { - int status; if (request.getFolderPath().endsWith("inbox")) { - status = session.processItem(request.getFolderPath(), lastPath); + session.processItem(request.getFolderPath(), lastPath); } else { - status = session.deleteItem(request.getFolderPath(), lastPath); + session.deleteItem(request.getFolderPath(), lastPath); } - sendHttpResponse(status); + sendHttpResponse(HttpStatus.SC_OK); } else if (request.isGet()) { if (request.path.endsWith("/")) { // GET request on a folder => build ics content of all folder events @@ -1410,9 +1409,8 @@ public class CaldavConnection extends AbstractConnection { * Get request folder path. * * @return exchange folder path - * @throws IOException on error */ - public String getFolderPath() throws IOException { + public String getFolderPath() { return getFolderPath(null); } diff --git a/src/java/davmail/exchange/ExchangeSession.java b/src/java/davmail/exchange/ExchangeSession.java index 3564ca72..ae044e2a 100644 --- a/src/java/davmail/exchange/ExchangeSession.java +++ b/src/java/davmail/exchange/ExchangeSession.java @@ -2580,17 +2580,16 @@ public abstract class ExchangeSession { * @return HTTP status * @throws IOException on error */ - public abstract int deleteItem(String folderPath, String itemName) throws IOException; + public abstract void deleteItem(String folderPath, String itemName) throws IOException; /** * Mark event processed named eventName in folder * * @param folderPath Exchange folder path * @param itemName item name - * @return HTTP status * @throws IOException on error */ - public abstract int processItem(String folderPath, String itemName) throws IOException; + public abstract void processItem(String folderPath, String itemName) throws IOException; private static int dumpIndex; diff --git a/src/java/davmail/exchange/dav/DavExchangeSession.java b/src/java/davmail/exchange/dav/DavExchangeSession.java index 3d81bb46..8cb0f1bd 100644 --- a/src/java/davmail/exchange/dav/DavExchangeSession.java +++ b/src/java/davmail/exchange/dav/DavExchangeSession.java @@ -1278,13 +1278,13 @@ public class DavExchangeSession extends ExchangeSession { } @Override - public int deleteItem(String folderPath, String itemName) throws IOException { + public void deleteItem(String folderPath, String itemName) throws IOException { String eventPath = URIUtil.encodePath(getFolderPath(folderPath) + '/' + convertItemNameToEML(itemName)); - return DavGatewayHttpClientFacade.executeDeleteMethod(httpClient, eventPath); + DavGatewayHttpClientFacade.executeDeleteMethod(httpClient, eventPath); } @Override - public int processItem(String folderPath, String itemName) throws IOException { + public void processItem(String folderPath, String itemName) throws IOException { String eventPath = URIUtil.encodePath(getFolderPath(folderPath) + '/' + convertItemNameToEML(itemName)); // do not delete calendar messages, mark read and processed ArrayList list = new ArrayList(); @@ -1292,7 +1292,6 @@ public class DavExchangeSession extends ExchangeSession { list.add(Field.createDavProperty("read", "1")); PropPatchMethod patchMethod = new PropPatchMethod(eventPath, list); DavGatewayHttpClientFacade.executeMethod(httpClient, patchMethod); - return HttpStatus.SC_OK; } /** diff --git a/src/java/davmail/exchange/ews/EwsExchangeSession.java b/src/java/davmail/exchange/ews/EwsExchangeSession.java index 32439b2b..ea45ed71 100644 --- a/src/java/davmail/exchange/ews/EwsExchangeSession.java +++ b/src/java/davmail/exchange/ews/EwsExchangeSession.java @@ -487,23 +487,23 @@ public class EwsExchangeSession extends ExchangeSession { protected static final HashSet FOLDER_PROPERTIES = new HashSet(); static { - FOLDER_PROPERTIES.add(ExtendedFieldURI.PR_URL_COMP_NAME); - FOLDER_PROPERTIES.add(ExtendedFieldURI.PR_LAST_MODIFICATION_TIME); - FOLDER_PROPERTIES.add(ExtendedFieldURI.PR_CONTAINER_CLASS); - FOLDER_PROPERTIES.add(ExtendedFieldURI.PR_LOCAL_COMMIT_TIME_MAX); - FOLDER_PROPERTIES.add(ExtendedFieldURI.PR_CONTENT_UNREAD); - FOLDER_PROPERTIES.add(ExtendedFieldURI.PR_SUBFOLDERS); + FOLDER_PROPERTIES.add(Field.get("urlcompname")); + FOLDER_PROPERTIES.add(Field.get("lastmodified")); + FOLDER_PROPERTIES.add(Field.get("folderclass")); + FOLDER_PROPERTIES.add(Field.get("ctag")); + FOLDER_PROPERTIES.add(Field.get("unread")); + FOLDER_PROPERTIES.add(Field.get("hassubs")); } protected Folder buildFolder(EWSMethod.Item item) { Folder folder = new Folder(); folder.folderId = new FolderId(item); - folder.displayName = item.get(ExtendedFieldURI.PR_URL_COMP_NAME.getResponseName()); - folder.folderClass = item.get(ExtendedFieldURI.PR_CONTAINER_CLASS.getResponseName()); - folder.etag = item.get(ExtendedFieldURI.PR_LAST_MODIFICATION_TIME.getResponseName()); - folder.ctag = item.get(ExtendedFieldURI.PR_LOCAL_COMMIT_TIME_MAX.getResponseName()); - folder.unreadCount = item.getInt(ExtendedFieldURI.PR_CONTENT_UNREAD.getResponseName()); - folder.hasChildren = item.getBoolean(ExtendedFieldURI.PR_SUBFOLDERS.getResponseName()); + folder.displayName = item.get(Field.get("urlcompname").getResponseName()); + folder.folderClass = item.get(Field.get("folderclass").getResponseName()); + folder.etag = item.get(Field.get("lastmodified").getResponseName()); + folder.ctag = item.get(Field.get("ctag").getResponseName()); + folder.unreadCount = item.getInt(Field.get("unread").getResponseName()); + folder.hasChildren = item.getBoolean(Field.get("hassubs").getResponseName()); // noInferiors not implemented return folder; } @@ -534,11 +534,11 @@ public class EwsExchangeSession extends ExchangeSession { for (EWSMethod.Item item : findFolderMethod.getResponseItems()) { Folder folder = buildFolder(item); if (parentFolderPath.length() > 0) { - folder.folderPath = parentFolderPath + '/' + item.get(ExtendedFieldURI.PR_URL_COMP_NAME.getResponseName()); + folder.folderPath = parentFolderPath + '/' + item.get(Field.get("urlcompname").getResponseName()); } else if (folderIdMap.get(folder.folderId.value) != null) { folder.folderPath = folderIdMap.get(folder.folderId.value); } else { - folder.folderPath = item.get(ExtendedFieldURI.PR_URL_COMP_NAME.getResponseName()); + folder.folderPath = item.get(Field.get("urlcompname").getResponseName()); } folders.add(folder); if (recursive && folder.hasChildren) { @@ -629,7 +629,7 @@ public class EwsExchangeSession extends ExchangeSession { // rename folder if (!path.folderName.equals(targetPath.folderName)) { Set updates = new HashSet(); - updates.add(new FieldUpdate(UnindexedFieldURI.FOLDER_DISPLAYNAME, targetPath.folderName)); + updates.add(new FieldUpdate(Field.get("folderDisplayName"), targetPath.folderName)); UpdateFolderMethod updateFolderMethod = new UpdateFolderMethod(folderId, updates); executeMethod(updateFolderMethod); } @@ -982,18 +982,17 @@ public class EwsExchangeSession extends ExchangeSession { } @Override - public int deleteItem(String folderPath, String itemName) throws IOException { + public void deleteItem(String folderPath, String itemName) throws IOException { String urlcompname = convertItemNameToEML(itemName); List responses = searchItems(folderPath, EVENT_REQUEST_PROPERTIES, equals("urlcompname", urlcompname), FolderQueryTraversal.SHALLOW); if (!responses.isEmpty()) { DeleteItemMethod deleteItemMethod = new DeleteItemMethod(new ItemId(responses.get(0)), DeleteType.HardDelete); executeMethod(deleteItemMethod); } - return HttpStatus.SC_OK; } @Override - public int processItem(String folderPath, String itemName) throws IOException { + public void processItem(String folderPath, String itemName) throws IOException { String urlcompname = convertItemNameToEML(itemName); List responses = searchItems(folderPath, EVENT_REQUEST_PROPERTIES, equals("urlcompname", urlcompname), FolderQueryTraversal.SHALLOW); if (!responses.isEmpty()) { @@ -1006,7 +1005,6 @@ public class EwsExchangeSession extends ExchangeSession { new ItemId(responses.get(0)), buildProperties(localProperties)); executeMethod(updateItemMethod); } - return HttpStatus.SC_OK; } @Override @@ -1101,7 +1099,7 @@ public class EwsExchangeSession extends ExchangeSession { parentFolderId, FOLDER_PROPERTIES, new TwoOperandExpression(TwoOperandExpression.Operator.IsEqualTo, - ExtendedFieldURI.PR_URL_COMP_NAME, folderName) + Field.get("urlcompname"), folderName) ); executeMethod(findFolderMethod); EWSMethod.Item item = findFolderMethod.getResponseItem(); @@ -1111,15 +1109,13 @@ public class EwsExchangeSession extends ExchangeSession { return folderId; } - protected int executeMethod(EWSMethod ewsMethod) throws IOException { - int status; + protected void executeMethod(EWSMethod ewsMethod) throws IOException { try { - status = httpClient.executeMethod(ewsMethod); + httpClient.executeMethod(ewsMethod); ewsMethod.checkSuccess(); } finally { ewsMethod.releaseConnection(); } - return status; } protected String convertDate(String exchangeDateValue) throws DavMailException { diff --git a/src/java/davmail/exchange/ews/ExtendedFieldURI.java b/src/java/davmail/exchange/ews/ExtendedFieldURI.java index 3d7f81e2..d842ff4b 100644 --- a/src/java/davmail/exchange/ews/ExtendedFieldURI.java +++ b/src/java/davmail/exchange/ews/ExtendedFieldURI.java @@ -22,12 +22,15 @@ package davmail.exchange.ews; * Extended MAPI property. */ public class ExtendedFieldURI implements FieldURI { + + @SuppressWarnings({"UnusedDeclaration"}) protected enum PropertyType { ApplicationTime, ApplicationTimeArray, Binary, BinaryArray, Boolean, CLSID, CLSIDArray, Currency, CurrencyArray, Double, DoubleArray, Error, Float, FloatArray, Integer, IntegerArray, Long, LongArray, Null, Object, ObjectArray, Short, ShortArray, SystemTime, SystemTimeArray, String, StringArray } + @SuppressWarnings({"UnusedDeclaration"}) protected static enum DistinguishedPropertySetType { Meeting, Appointment, Common, PublicStrings, Address, InternetHeaders, CalendarAssistant, UnifiedMessaging, Task } @@ -81,6 +84,7 @@ public class ExtendedFieldURI implements FieldURI { * * @param distinguishedPropertySetId distinguished property set id * @param propertyName property name + * @param propertyType property type */ public ExtendedFieldURI(DistinguishedPropertySetType distinguishedPropertySetId, String propertyName, PropertyType propertyType) { this.distinguishedPropertySetId = distinguishedPropertySetId; @@ -158,23 +162,5 @@ public class ExtendedFieldURI implements FieldURI { } } - public static final ExtendedFieldURI PR_INSTANCE_KEY = new ExtendedFieldURI(0xff6, PropertyType.Binary); - public static final ExtendedFieldURI PR_MESSAGE_SIZE = new ExtendedFieldURI(0xe08, PropertyType.Integer); - public static final ExtendedFieldURI PR_INTERNET_ARTICLE_NUMBER = new ExtendedFieldURI(0xe23, PropertyType.Integer); - public static final ExtendedFieldURI JUNK_FLAG = new ExtendedFieldURI(0x1083, PropertyType.Integer); - public static final ExtendedFieldURI PR_FLAG_STATUS = new ExtendedFieldURI(0x1090, PropertyType.Integer); - public static final ExtendedFieldURI PR_MESSAGE_FLAGS = new ExtendedFieldURI(0x0e07, PropertyType.Integer); - public static final ExtendedFieldURI PR_ACTION_FLAG = new ExtendedFieldURI(0x1081, PropertyType.Integer); - public static final ExtendedFieldURI PR_URL_COMP_NAME = new ExtendedFieldURI(0x10f3, PropertyType.String); - public static final ExtendedFieldURI PR_CONTAINER_CLASS = new ExtendedFieldURI(0x3613, PropertyType.String); - - public static final ExtendedFieldURI PR_LAST_MODIFICATION_TIME = new ExtendedFieldURI(0x3008, PropertyType.SystemTime); - public static final ExtendedFieldURI PR_LOCAL_COMMIT_TIME_MAX = new ExtendedFieldURI(0x670a, PropertyType.SystemTime); - public static final ExtendedFieldURI PR_SUBFOLDERS = new ExtendedFieldURI(0x360a, PropertyType.Boolean); - public static final ExtendedFieldURI PR_CONTENT_UNREAD = new ExtendedFieldURI(0x3603, PropertyType.Integer); - - // message properties - public static final ExtendedFieldURI PR_READ = new ExtendedFieldURI(0xe69, PropertyType.Boolean); - } diff --git a/src/java/davmail/exchange/ews/Field.java b/src/java/davmail/exchange/ews/Field.java index d9cc3a13..b6daf08e 100644 --- a/src/java/davmail/exchange/ews/Field.java +++ b/src/java/davmail/exchange/ews/Field.java @@ -37,6 +37,12 @@ public class Field { FIELD_MAP.put("urlcompname", new ExtendedFieldURI(0x10f3, ExtendedFieldURI.PropertyType.String)); FIELD_MAP.put("lastmodified", new ExtendedFieldURI(0x3008, ExtendedFieldURI.PropertyType.SystemTime)); + // folder + FIELD_MAP.put("ctag", new ExtendedFieldURI(0x670a, ExtendedFieldURI.PropertyType.SystemTime)); // PR_LOCAL_COMMIT_TIME_MAX + FIELD_MAP.put("unread", new ExtendedFieldURI(0x3603, ExtendedFieldURI.PropertyType.Integer)); // PR_CONTENT_UNREAD + FIELD_MAP.put("hassubs", new ExtendedFieldURI(0x360a, ExtendedFieldURI.PropertyType.Boolean)); // PR_SUBFOLDERS + FIELD_MAP.put("folderDisplayName", new UnindexedFieldURI("folder:DisplayName")); + FIELD_MAP.put("permanenturl", new ExtendedFieldURI(0x670E, ExtendedFieldURI.PropertyType.String)); //PR_FLAT_URL_NAME FIELD_MAP.put("instancetype", new ExtendedFieldURI(ExtendedFieldURI.DistinguishedPropertySetType.PublicStrings, "urn:schemas:calendar:instancetype")); diff --git a/src/java/davmail/exchange/ews/FolderQueryTraversal.java b/src/java/davmail/exchange/ews/FolderQueryTraversal.java index a8ec10d2..5677ca7f 100644 --- a/src/java/davmail/exchange/ews/FolderQueryTraversal.java +++ b/src/java/davmail/exchange/ews/FolderQueryTraversal.java @@ -34,5 +34,6 @@ public final class FolderQueryTraversal extends AttributeOption { /** * Recursive search. */ + @SuppressWarnings({"UnusedDeclaration"}) public static final FolderQueryTraversal DEEP = new FolderQueryTraversal("Deep"); } \ No newline at end of file diff --git a/src/java/davmail/exchange/ews/ItemId.java b/src/java/davmail/exchange/ews/ItemId.java index 9a013c0b..365c1404 100644 --- a/src/java/davmail/exchange/ews/ItemId.java +++ b/src/java/davmail/exchange/ews/ItemId.java @@ -28,17 +28,6 @@ public class ItemId { protected final String id; protected final String changeKey; - /** - * Create Item id. - * - * @param id item id - * @param changeKey item change key - */ - public ItemId(String id, String changeKey) { - this.id = id; - this.changeKey = changeKey; - } - /** * Build Item id from response item. * diff --git a/src/java/davmail/exchange/ews/UnindexedFieldURI.java b/src/java/davmail/exchange/ews/UnindexedFieldURI.java index ef3dc3a9..8432e2f7 100644 --- a/src/java/davmail/exchange/ews/UnindexedFieldURI.java +++ b/src/java/davmail/exchange/ews/UnindexedFieldURI.java @@ -72,7 +72,4 @@ public class UnindexedFieldURI implements FieldURI { return fieldName; } - public static final UnindexedFieldURI DATE_TIME_SENT = new UnindexedFieldURI("item:DateTimeSent"); - public static final UnindexedFieldURI FOLDER_DISPLAYNAME = new UnindexedFieldURI("folder:DisplayName"); - } diff --git a/src/java/davmail/http/DavGatewayHttpClientFacade.java b/src/java/davmail/http/DavGatewayHttpClientFacade.java index 9159b8e4..b22b3d24 100644 --- a/src/java/davmail/http/DavGatewayHttpClientFacade.java +++ b/src/java/davmail/http/DavGatewayHttpClientFacade.java @@ -332,10 +332,9 @@ public final class DavGatewayHttpClientFacade { * * @param httpClient Http client instance * @param path Path to be deleted - * @return Http status * @throws IOException on error */ - public static int executeDeleteMethod(HttpClient httpClient, String path) throws IOException { + public static void executeDeleteMethod(HttpClient httpClient, String path) throws IOException { DeleteMethod deleteMethod = new DeleteMethod(path); deleteMethod.setFollowRedirects(false); @@ -344,7 +343,6 @@ public final class DavGatewayHttpClientFacade { if (status != HttpStatus.SC_OK && status != HttpStatus.SC_NOT_FOUND) { throw DavGatewayHttpClientFacade.buildHttpException(deleteMethod); } - return HttpStatus.SC_OK; } /** @@ -413,12 +411,13 @@ public final class DavGatewayHttpClientFacade { /** * Enable NTLM authentication on http client + * * @param httpClient HttpClient instance */ public static void addNTLM(HttpClient httpClient) { // register the jcifs based NTLMv2 implementation AuthPolicy.registerAuthScheme(AuthPolicy.NTLM, NTLMv2Scheme.class); - + ArrayList authPrefs = new ArrayList(); authPrefs.add(AuthPolicy.NTLM); authPrefs.add(AuthPolicy.DIGEST); @@ -453,7 +452,7 @@ public final class DavGatewayHttpClientFacade { acceptNTLM = true; } if ("Basic realm".equalsIgnoreCase(headerElement.getName())) { - acceptBasic = true; + acceptBasic = true; } } return acceptNTLM && !acceptBasic; @@ -490,10 +489,9 @@ public final class DavGatewayHttpClientFacade { * @param httpClient Http client instance * @param method Http method * @param followRedirects Follow redirects flag - * @return Http status * @throws IOException on error */ - public static int executeGetMethod(HttpClient httpClient, GetMethod method, boolean followRedirects) throws IOException { + public static void executeGetMethod(HttpClient httpClient, GetMethod method, boolean followRedirects) throws IOException { // do not follow redirects in expired sessions method.setFollowRedirects(followRedirects); int status = httpClient.executeMethod(method); @@ -517,7 +515,6 @@ public final class DavGatewayHttpClientFacade { throw DavGatewayHttpClientFacade.buildHttpException(method); } } - return status; } private static void resetMethod(HttpMethod method) { diff --git a/src/java/davmail/ldap/LdapConnection.java b/src/java/davmail/ldap/LdapConnection.java index 38c0a254..fcc01281 100644 --- a/src/java/davmail/ldap/LdapConnection.java +++ b/src/java/davmail/ldap/LdapConnection.java @@ -1498,7 +1498,7 @@ public class LdapConnection extends AbstractConnection { String value = person.get(contactAttribute); if (value != null) { if (ldapAttribute.startsWith("birth")) { - SimpleDateFormat parser = session.getZuluDateFormat(); + SimpleDateFormat parser = ExchangeSession.getZuluDateFormat(); Calendar calendar = Calendar.getInstance(); try { calendar.setTime(parser.parse(value)); diff --git a/src/test/davmail/exchange/TestExchangeSessionContact.java b/src/test/davmail/exchange/TestExchangeSessionContact.java index 9308df23..e74a2ced 100644 --- a/src/test/davmail/exchange/TestExchangeSessionContact.java +++ b/src/test/davmail/exchange/TestExchangeSessionContact.java @@ -18,6 +18,7 @@ */ package davmail.exchange; +import davmail.util.IOUtil; import org.apache.commons.codec.binary.Base64; import java.io.ByteArrayOutputStream; @@ -32,31 +33,6 @@ import java.util.UUID; @SuppressWarnings({"UseOfSystemOutOrSystemErr"}) public class TestExchangeSessionContact extends AbstractExchangeSessionTestCase { static String itemName; - /* - public void testSearchContacts() throws IOException { - List contacts = session.searchContacts(ExchangeSession.CONTACTS, ExchangeSession.CONTACT_ATTRIBUTES, null); - for (ExchangeSession.Contact contact : contacts) { - System.out.println(session.getItem(ExchangeSession.CONTACTS, contact.getName())); - } - } - - public void testSearchContactsUidOnly() throws IOException { - Set attributes = new HashSet(); - attributes.add("uid"); - List contacts = session.searchContacts(ExchangeSession.CONTACTS, attributes, null); - for (ExchangeSession.Contact contact : contacts) { - System.out.println(contact); - } - } - - public void testSearchContactsByUid() throws IOException { - Set attributes = new HashSet(); - attributes.add("uid"); - List contacts = session.searchContacts(ExchangeSession.CONTACTS, attributes, null); - for (ExchangeSession.Contact contact : contacts) { - System.out.println(session.searchContacts(ExchangeSession.CONTACTS, attributes, session.equals("uid", contact.get("uid")))); - } - } */ public void testCreateFolder() throws IOException { // recreate empty folder @@ -110,12 +86,8 @@ public class TestExchangeSessionContact extends AbstractExchangeSessionTestCase // add photo ByteArrayOutputStream baos = new ByteArrayOutputStream(); - InputStream partInputStream = new FileInputStream("src/data/anonymous.jpg"); - byte[] bytes = new byte[8192]; - int length; - while ((length = partInputStream.read(bytes)) > 0) { - baos.write(bytes, 0, length); - } + InputStream fileInputStream = new FileInputStream("src/data/anonymous.jpg"); + IOUtil.write(fileInputStream, baos); vCardWriter.appendProperty("PHOTO;ENCODING=b;TYPE=JPEG", new String(Base64.encodeBase64(baos.toByteArray()))); vCardWriter.endCard(); diff --git a/src/test/davmail/exchange/TestExchangeSessionSearchContact.java b/src/test/davmail/exchange/TestExchangeSessionSearchContact.java index 4391257b..f29de8d7 100644 --- a/src/test/davmail/exchange/TestExchangeSessionSearchContact.java +++ b/src/test/davmail/exchange/TestExchangeSessionSearchContact.java @@ -21,7 +21,9 @@ package davmail.exchange; import davmail.Settings; import java.io.IOException; +import java.util.HashSet; import java.util.List; +import java.util.Set; /** * Test contact search. @@ -47,4 +49,29 @@ public class TestExchangeSessionSearchContact extends AbstractExchangeSessionTes } } + public void testSearchContacts() throws IOException { + List contacts = session.searchContacts(ExchangeSession.CONTACTS, ExchangeSession.CONTACT_ATTRIBUTES, null); + for (ExchangeSession.Contact contact : contacts) { + System.out.println(session.getItem(ExchangeSession.CONTACTS, contact.getName())); + } + } + + public void testSearchContactsUidOnly() throws IOException { + Set attributes = new HashSet(); + attributes.add("uid"); + List contacts = session.searchContacts(ExchangeSession.CONTACTS, attributes, null); + for (ExchangeSession.Contact contact : contacts) { + System.out.println(contact); + } + } + + public void testSearchContactsByUid() throws IOException { + Set attributes = new HashSet(); + attributes.add("uid"); + List contacts = session.searchContacts(ExchangeSession.CONTACTS, attributes, null); + for (ExchangeSession.Contact contact : contacts) { + System.out.println(session.searchContacts(ExchangeSession.CONTACTS, attributes, session.equals("uid", contact.get("uid")))); + } + } + }