From d552bc29937b32ff2a20daa7445579bd2c451c76 Mon Sep 17 00:00:00 2001 From: mguessan Date: Sat, 19 Jun 2010 21:35:09 +0000 Subject: [PATCH] EWS: move mailbox folder urls to DavExchangeSession git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1098 3d1905a2-6b24-0410-a738-b14d5a86fcbd --- .../davmail/exchange/ExchangeSession.java | 85 +--------------- .../exchange/dav/DavExchangeSession.java | 96 +++++++++++++++++++ .../exchange/ews/EwsExchangeSession.java | 5 + 3 files changed, 103 insertions(+), 83 deletions(-) diff --git a/src/java/davmail/exchange/ExchangeSession.java b/src/java/davmail/exchange/ExchangeSession.java index 848d6419..f85c40c5 100644 --- a/src/java/davmail/exchange/ExchangeSession.java +++ b/src/java/davmail/exchange/ExchangeSession.java @@ -96,17 +96,6 @@ public abstract class ExchangeSession { protected static final String JUNK = "Junk"; protected static final String UNSENT = "Unsent Messages"; - /** - * Various standard mail boxes Urls - */ - protected String inboxUrl; - protected String deleteditemsUrl; - protected String sentitemsUrl; - protected String sendmsgUrl; - protected String draftsUrl; - protected String calendarUrl; - protected String contactsUrl; - protected String outboxUrl; protected String publicFolderUrl; /** @@ -114,7 +103,7 @@ public abstract class ExchangeSession { */ protected String mailPath; protected String email; - private String alias; + protected String alias; protected final HttpClient httpClient; private final String userName; @@ -812,37 +801,6 @@ public abstract class ExchangeSession { sendMessage(properties, mailBuffer.toString()); } - /** - * Convert logical or relative folder path to absolute folder path. - * - * @param folderName folder name - * @return folder path - */ - public String getFolderPath(String folderName) { - String folderPath; - if (folderName.startsWith(INBOX)) { - folderPath = folderName.replaceFirst(INBOX, inboxUrl); - } else if (folderName.startsWith(TRASH)) { - folderPath = folderName.replaceFirst(TRASH, deleteditemsUrl); - } else if (folderName.startsWith(DRAFTS)) { - folderPath = folderName.replaceFirst(DRAFTS, draftsUrl); - } else if (folderName.startsWith(SENT)) { - folderPath = folderName.replaceFirst(SENT, sentitemsUrl); - } else if (folderName.startsWith(CALENDAR)) { - folderPath = folderName.replaceFirst(CALENDAR, calendarUrl); - } else if (folderName.startsWith(CONTACTS)) { - folderPath = folderName.replaceFirst(CONTACTS, contactsUrl); - } else if (folderName.startsWith("public")) { - folderPath = publicFolderUrl + folderName.substring("public".length()); - // absolute folder path - } else if (folderName.startsWith("/")) { - folderPath = folderName; - } else { - folderPath = mailPath + folderName; - } - return folderPath; - } - /** * Get folder object. * Folder name can be logical names INBOX, Drafts, Trash or calendar, @@ -2479,46 +2437,7 @@ public abstract class ExchangeSession { * @return Exchange folder path * @throws IOException on error */ - public String buildCalendarPath(String principal, String folderName) throws IOException { - StringBuilder buffer = new StringBuilder(); - // other user calendar => replace principal folder name in mailPath - if (principal != null && !alias.equalsIgnoreCase(principal) && !email.equalsIgnoreCase(principal)) { - LOGGER.debug("Detected shared calendar path for principal " + principal + ", user principal is " + email); - int index = mailPath.lastIndexOf('/', mailPath.length() - 2); - if (index >= 0 && mailPath.endsWith("/")) { - buffer.append(mailPath.substring(0, index + 1)).append(principal).append('/'); - } else { - throw new DavMailException("EXCEPTION_INVALID_MAIL_PATH", mailPath); - } - } else if (principal != null) { - buffer.append(mailPath); - } - - if (folderName != null && (folderName.startsWith("calendar") || folderName.startsWith("contacts") - // OSX address book name - || folderName.startsWith("addressbook"))) { - if (folderName.startsWith("calendar")) { - // replace 'calendar' folder name with i18n name - buffer.append(calendarUrl.substring(calendarUrl.lastIndexOf('/') + 1)); - } else { - // replace 'contacts' folder name with i18n name - buffer.append(contactsUrl.substring(contactsUrl.lastIndexOf('/') + 1)); - } - - // sub calendar folder => append sub folder name - int index = folderName.indexOf('/'); - if (index >= 0) { - buffer.append(folderName.substring(index)); - } - // replace 'inbox' folder name with i18n name - } else if ("inbox".equals(folderName)) { - buffer.append(inboxUrl.substring(inboxUrl.lastIndexOf('/') + 1)); - // append folder name without replace (public folder) - } else if (folderName != null && folderName.length() > 0) { - buffer.append(folderName); - } - return buffer.toString(); - } + public abstract String buildCalendarPath(String principal, String folderName) throws IOException; /** * Test if folderPath is inside user mailbox. diff --git a/src/java/davmail/exchange/dav/DavExchangeSession.java b/src/java/davmail/exchange/dav/DavExchangeSession.java index 68da1185..ea83c84f 100644 --- a/src/java/davmail/exchange/dav/DavExchangeSession.java +++ b/src/java/davmail/exchange/dav/DavExchangeSession.java @@ -74,6 +74,102 @@ public class DavExchangeSession extends ExchangeSession { WELL_KNOWN_FOLDERS.add(Field.get("outbox").davPropertyName); } + /** + * Various standard mail boxes Urls + */ + protected String inboxUrl; + protected String deleteditemsUrl; + protected String sentitemsUrl; + protected String sendmsgUrl; + protected String draftsUrl; + protected String calendarUrl; + protected String contactsUrl; + protected String outboxUrl; + + /** + * Convert logical or relative folder path to absolute folder path. + * + * @param folderName folder name + * @return folder path + */ + public String getFolderPath(String folderName) { + String folderPath; + if (folderName.startsWith(INBOX)) { + folderPath = folderName.replaceFirst(INBOX, inboxUrl); + } else if (folderName.startsWith(TRASH)) { + folderPath = folderName.replaceFirst(TRASH, deleteditemsUrl); + } else if (folderName.startsWith(DRAFTS)) { + folderPath = folderName.replaceFirst(DRAFTS, draftsUrl); + } else if (folderName.startsWith(SENT)) { + folderPath = folderName.replaceFirst(SENT, sentitemsUrl); + } else if (folderName.startsWith(CALENDAR)) { + folderPath = folderName.replaceFirst(CALENDAR, calendarUrl); + } else if (folderName.startsWith(CONTACTS)) { + folderPath = folderName.replaceFirst(CONTACTS, contactsUrl); + } else if (folderName.startsWith("public")) { + folderPath = publicFolderUrl + folderName.substring("public".length()); + // absolute folder path + } else if (folderName.startsWith("/")) { + folderPath = folderName; + } else { + folderPath = mailPath + folderName; + } + return folderPath; + } + + /** + * Build Caldav calendar path for principal and folder name. + * - prefix is current user mailbox path if principal is current user, + * else prefix is parent folder of current user mailbox path followed by principal + * - suffix according to well known folder names (internationalized on Exchange) + * + * @param principal calendar principal + * @param folderName requested folder name + * @return Exchange folder path + * @throws IOException on error + */ + public String buildCalendarPath(String principal, String folderName) throws IOException { + StringBuilder buffer = new StringBuilder(); + // other user calendar => replace principal folder name in mailPath + if (principal != null && !alias.equalsIgnoreCase(principal) && !email.equalsIgnoreCase(principal)) { + LOGGER.debug("Detected shared calendar path for principal " + principal + ", user principal is " + email); + int index = mailPath.lastIndexOf('/', mailPath.length() - 2); + if (index >= 0 && mailPath.endsWith("/")) { + buffer.append(mailPath.substring(0, index + 1)).append(principal).append('/'); + } else { + throw new DavMailException("EXCEPTION_INVALID_MAIL_PATH", mailPath); + } + } else if (principal != null) { + buffer.append(mailPath); + } + + if (folderName != null && (folderName.startsWith("calendar") || folderName.startsWith("contacts") + // OSX address book name + || folderName.startsWith("addressbook"))) { + if (folderName.startsWith("calendar")) { + // replace 'calendar' folder name with i18n name + buffer.append(calendarUrl.substring(calendarUrl.lastIndexOf('/') + 1)); + } else { + // replace 'contacts' folder name with i18n name + buffer.append(contactsUrl.substring(contactsUrl.lastIndexOf('/') + 1)); + } + + // sub calendar folder => append sub folder name + int index = folderName.indexOf('/'); + if (index >= 0) { + buffer.append(folderName.substring(index)); + } + // replace 'inbox' folder name with i18n name + } else if ("inbox".equals(folderName)) { + buffer.append(inboxUrl.substring(inboxUrl.lastIndexOf('/') + 1)); + // append folder name without replace (public folder) + } else if (folderName != null && folderName.length() > 0) { + buffer.append(folderName); + } + return buffer.toString(); + } + + /** * @inheritDoc */ diff --git a/src/java/davmail/exchange/ews/EwsExchangeSession.java b/src/java/davmail/exchange/ews/EwsExchangeSession.java index a77ca077..c97774c9 100644 --- a/src/java/davmail/exchange/ews/EwsExchangeSession.java +++ b/src/java/davmail/exchange/ews/EwsExchangeSession.java @@ -458,6 +458,11 @@ public class EwsExchangeSession extends ExchangeSession { throw new UnsupportedOperationException(); } + @Override + public String buildCalendarPath(String principal, String folderName) throws IOException { + throw new UnsupportedOperationException(); + } + @Override protected void loadVtimezone() { throw new UnsupportedOperationException();