1
0
mirror of https://github.com/moparisthebest/davmail synced 2024-12-14 19:52:21 -05:00

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
This commit is contained in:
mguessan 2010-06-19 21:35:09 +00:00
parent 0bd3eba7c4
commit d552bc2993
3 changed files with 103 additions and 83 deletions

View File

@ -96,17 +96,6 @@ public abstract class ExchangeSession {
protected static final String JUNK = "Junk"; protected static final String JUNK = "Junk";
protected static final String UNSENT = "Unsent Messages"; 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; protected String publicFolderUrl;
/** /**
@ -114,7 +103,7 @@ public abstract class ExchangeSession {
*/ */
protected String mailPath; protected String mailPath;
protected String email; protected String email;
private String alias; protected String alias;
protected final HttpClient httpClient; protected final HttpClient httpClient;
private final String userName; private final String userName;
@ -812,37 +801,6 @@ public abstract class ExchangeSession {
sendMessage(properties, mailBuffer.toString()); 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. * Get folder object.
* Folder name can be logical names INBOX, Drafts, Trash or calendar, * Folder name can be logical names INBOX, Drafts, Trash or calendar,
@ -2479,46 +2437,7 @@ public abstract class ExchangeSession {
* @return Exchange folder path * @return Exchange folder path
* @throws IOException on error * @throws IOException on error
*/ */
public String buildCalendarPath(String principal, String folderName) throws IOException { public abstract 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();
}
/** /**
* Test if folderPath is inside user mailbox. * Test if folderPath is inside user mailbox.

View File

@ -74,6 +74,102 @@ public class DavExchangeSession extends ExchangeSession {
WELL_KNOWN_FOLDERS.add(Field.get("outbox").davPropertyName); 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 * @inheritDoc
*/ */

View File

@ -458,6 +458,11 @@ public class EwsExchangeSession extends ExchangeSession {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
@Override
public String buildCalendarPath(String principal, String folderName) throws IOException {
throw new UnsupportedOperationException();
}
@Override @Override
protected void loadVtimezone() { protected void loadVtimezone() {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();