mirror of
https://github.com/moparisthebest/davmail
synced 2025-01-12 22:18:11 -05:00
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:
parent
6e6bdf80f6
commit
f9427feaf5
@ -142,7 +142,7 @@ public class DavExchangeSession extends ExchangeSession {
|
|||||||
if (principalIndex >= 0) {
|
if (principalIndex >= 0) {
|
||||||
principal = folderPath.substring(USERS.length(), principalIndex);
|
principal = folderPath.substring(USERS.length(), principalIndex);
|
||||||
localPath = folderPath.substring(USERS.length() + principal.length() + 1);
|
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());
|
localPath = inboxName + localPath.substring(LOWER_CASE_INBOX.length());
|
||||||
} else if (localPath.startsWith(CALENDAR)) {
|
} else if (localPath.startsWith(CALENDAR)) {
|
||||||
localPath = calendarName + localPath.substring(CALENDAR.length());
|
localPath = calendarName + localPath.substring(CALENDAR.length());
|
||||||
|
@ -53,6 +53,7 @@ import java.util.*;
|
|||||||
public class ImapConnection extends AbstractConnection {
|
public class ImapConnection extends AbstractConnection {
|
||||||
private static final Logger LOGGER = Logger.getLogger(ImapConnection.class);
|
private static final Logger LOGGER = Logger.getLogger(ImapConnection.class);
|
||||||
|
|
||||||
|
protected String baseMailboxPath;
|
||||||
ExchangeSession.Folder currentFolder;
|
ExchangeSession.Folder currentFolder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -102,6 +103,8 @@ public class ImapConnection extends AbstractConnection {
|
|||||||
sendClient(commandId + " OK CAPABILITY completed");
|
sendClient(commandId + " OK CAPABILITY completed");
|
||||||
} else if ("login".equalsIgnoreCase(command)) {
|
} else if ("login".equalsIgnoreCase(command)) {
|
||||||
parseCredentials(tokens);
|
parseCredentials(tokens);
|
||||||
|
// detect shared mailbox access
|
||||||
|
splitUserName();
|
||||||
try {
|
try {
|
||||||
session = ExchangeSessionFactory.getInstance(userName, password);
|
session = ExchangeSessionFactory.getInstance(userName, password);
|
||||||
sendClient(commandId + " OK Authenticated");
|
sendClient(commandId + " OK Authenticated");
|
||||||
@ -119,6 +122,8 @@ public class ImapConnection extends AbstractConnection {
|
|||||||
sendClient("+ " + base64Encode("Username:"));
|
sendClient("+ " + base64Encode("Username:"));
|
||||||
state = State.LOGIN;
|
state = State.LOGIN;
|
||||||
userName = base64Decode(readClient());
|
userName = base64Decode(readClient());
|
||||||
|
// detect shared mailbox access
|
||||||
|
splitUserName();
|
||||||
sendClient("+ " + base64Encode("Password:"));
|
sendClient("+ " + base64Encode("Password:"));
|
||||||
state = State.PASSWORD;
|
state = State.PASSWORD;
|
||||||
password = base64Decode(readClient());
|
password = base64Decode(readClient());
|
||||||
@ -145,6 +150,9 @@ public class ImapConnection extends AbstractConnection {
|
|||||||
if ("lsub".equalsIgnoreCase(command) || "list".equalsIgnoreCase(command)) {
|
if ("lsub".equalsIgnoreCase(command) || "list".equalsIgnoreCase(command)) {
|
||||||
if (tokens.hasMoreTokens()) {
|
if (tokens.hasMoreTokens()) {
|
||||||
String folderContext = BASE64MailboxDecoder.decode(tokens.nextToken());
|
String folderContext = BASE64MailboxDecoder.decode(tokens.nextToken());
|
||||||
|
if (baseMailboxPath != null) {
|
||||||
|
folderContext = baseMailboxPath + folderContext;
|
||||||
|
}
|
||||||
if (tokens.hasMoreTokens()) {
|
if (tokens.hasMoreTokens()) {
|
||||||
String folderQuery = folderContext + BASE64MailboxDecoder.decode(tokens.nextToken());
|
String folderQuery = folderContext + BASE64MailboxDecoder.decode(tokens.nextToken());
|
||||||
if (folderQuery.endsWith("%/%") && !"/%/%".equals(folderQuery)) {
|
if (folderQuery.endsWith("%/%") && !"/%/%".equals(folderQuery)) {
|
||||||
@ -198,6 +206,9 @@ public class ImapConnection extends AbstractConnection {
|
|||||||
} else if ("select".equalsIgnoreCase(command) || "examine".equalsIgnoreCase(command)) {
|
} else if ("select".equalsIgnoreCase(command) || "examine".equalsIgnoreCase(command)) {
|
||||||
if (tokens.hasMoreTokens()) {
|
if (tokens.hasMoreTokens()) {
|
||||||
String folderName = BASE64MailboxDecoder.decode(tokens.nextToken());
|
String folderName = BASE64MailboxDecoder.decode(tokens.nextToken());
|
||||||
|
if (baseMailboxPath != null && !folderName.startsWith("/")) {
|
||||||
|
folderName = baseMailboxPath + folderName;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
currentFolder = session.getFolder(folderName);
|
currentFolder = session.getFolder(folderName);
|
||||||
currentFolder.loadMessages();
|
currentFolder.loadMessages();
|
||||||
@ -578,6 +589,24 @@ public class ImapConnection extends AbstractConnection {
|
|||||||
DavGatewayTray.resetIcon();
|
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.
|
* Send expunge untagged response for removed IMAP message uids.
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user