IMAP: implement shared mailbox access

git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1402 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
mguessan 2010-09-01 00:15:36 +00:00
parent 6e6bdf80f6
commit f9427feaf5
2 changed files with 30 additions and 1 deletions

View File

@ -142,7 +142,7 @@ public class DavExchangeSession extends ExchangeSession {
if (principalIndex >= 0) {
principal = folderPath.substring(USERS.length(), principalIndex);
localPath = folderPath.substring(USERS.length() + principal.length() + 1);
if (localPath.startsWith(LOWER_CASE_INBOX)) {
if (localPath.startsWith(LOWER_CASE_INBOX) || localPath.startsWith(INBOX)) {
localPath = inboxName + localPath.substring(LOWER_CASE_INBOX.length());
} else if (localPath.startsWith(CALENDAR)) {
localPath = calendarName + localPath.substring(CALENDAR.length());

View File

@ -53,6 +53,7 @@ import java.util.*;
public class ImapConnection extends AbstractConnection {
private static final Logger LOGGER = Logger.getLogger(ImapConnection.class);
protected String baseMailboxPath;
ExchangeSession.Folder currentFolder;
/**
@ -102,6 +103,8 @@ public class ImapConnection extends AbstractConnection {
sendClient(commandId + " OK CAPABILITY completed");
} else if ("login".equalsIgnoreCase(command)) {
parseCredentials(tokens);
// detect shared mailbox access
splitUserName();
try {
session = ExchangeSessionFactory.getInstance(userName, password);
sendClient(commandId + " OK Authenticated");
@ -119,6 +122,8 @@ public class ImapConnection extends AbstractConnection {
sendClient("+ " + base64Encode("Username:"));
state = State.LOGIN;
userName = base64Decode(readClient());
// detect shared mailbox access
splitUserName();
sendClient("+ " + base64Encode("Password:"));
state = State.PASSWORD;
password = base64Decode(readClient());
@ -145,6 +150,9 @@ public class ImapConnection extends AbstractConnection {
if ("lsub".equalsIgnoreCase(command) || "list".equalsIgnoreCase(command)) {
if (tokens.hasMoreTokens()) {
String folderContext = BASE64MailboxDecoder.decode(tokens.nextToken());
if (baseMailboxPath != null) {
folderContext = baseMailboxPath + folderContext;
}
if (tokens.hasMoreTokens()) {
String folderQuery = folderContext + BASE64MailboxDecoder.decode(tokens.nextToken());
if (folderQuery.endsWith("%/%") && !"/%/%".equals(folderQuery)) {
@ -198,6 +206,9 @@ public class ImapConnection extends AbstractConnection {
} else if ("select".equalsIgnoreCase(command) || "examine".equalsIgnoreCase(command)) {
if (tokens.hasMoreTokens()) {
String folderName = BASE64MailboxDecoder.decode(tokens.nextToken());
if (baseMailboxPath != null && !folderName.startsWith("/")) {
folderName = baseMailboxPath + folderName;
}
try {
currentFolder = session.getFolder(folderName);
currentFolder.loadMessages();
@ -578,6 +589,24 @@ public class ImapConnection extends AbstractConnection {
DavGatewayTray.resetIcon();
}
/**
* Detect shared mailbox access.
* see http://msexchangeteam.com/archive/2004/03/31/105275.aspx
*/
protected void splitUserName() {
String[] tokens = null;
if (userName.indexOf('/') >= 0) {
tokens = userName.split("/");
} else if (userName.indexOf('\\') >= 0) {
tokens = userName.split("\\\\");
}
if (tokens != null && tokens.length == 3) {
userName = tokens[0] + '\\' + tokens[1];
baseMailboxPath = "/users/" + tokens[2] + '/';
}
}
/**
* Send expunge untagged response for removed IMAP message uids.
*