1
0
mirror of https://github.com/moparisthebest/davmail synced 2024-12-13 19:22:22 -05:00

Implement folder create

git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@305 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
mguessan 2009-01-23 13:01:46 +00:00
parent f619571390
commit 43ddbaf8e2
2 changed files with 57 additions and 18 deletions

View File

@ -14,6 +14,7 @@ import org.apache.webdav.lib.ResponseEntity;
import org.apache.webdav.lib.WebdavResource; import org.apache.webdav.lib.WebdavResource;
import org.apache.webdav.lib.methods.PropPatchMethod; import org.apache.webdav.lib.methods.PropPatchMethod;
import org.apache.webdav.lib.methods.SearchMethod; import org.apache.webdav.lib.methods.SearchMethod;
import org.apache.webdav.lib.methods.MkcolMethod;
import org.htmlcleaner.CommentToken; import org.htmlcleaner.CommentToken;
import org.htmlcleaner.HtmlCleaner; import org.htmlcleaner.HtmlCleaner;
import org.htmlcleaner.TagNode; import org.htmlcleaner.TagNode;
@ -805,6 +806,41 @@ public class ExchangeSession {
return folder; return folder;
} }
public void createFolder(String folderName) throws IOException {
String folderPath = getFolderPath(folderName);
int index = folderPath.lastIndexOf("/");
PropPatchMethod method = new PropPatchMethod(folderPath) {
public String getName() {
return "MKCOL";
}
};
method.setDebug(4);
method.addPropertyToSet("outlookfolderclass","IPF.Note","ex","http://schemas.microsoft.com/exchange/");
wdr.retrieveSessionInstance().executeMethod(method);
// ok or alredy exists
if (method.getStatusCode() != HttpStatus.SC_MULTI_STATUS && method.getStatusCode() != HttpStatus.SC_METHOD_NOT_ALLOWED) {
HttpException ex = new HttpException();
ex.setReasonCode(method.getStatusCode());
ex.setReason(method.getStatusText());
throw ex;
}
/*
PostMethod postMethod = new PostMethod(folderPath.substring(0, index));
postMethod.addParameter("Cmd", "createfolder");
postMethod.addParameter("Action", "Create");
postMethod.addParameter("FolderName", folderPath.substring(index + 1));
postMethod.addParameter("FolderType", "IPF.Note");
wdr.retrieveSessionInstance().executeMethod(postMethod);
if (postMethod.getStatusCode() != HttpStatus.SC_MOVED_TEMPORARILY) {
HttpException ex = new HttpException();
ex.setReasonCode(postMethod.getStatusCode());
ex.setReason(postMethod.getStatusText());
throw ex;
}
*/
}
public static class Folder { public static class Folder {
public String folderUrl; public String folderUrl;
public int objectCount; public int objectCount;

View File

@ -161,12 +161,8 @@ public class ImapConnection extends AbstractConnection {
} else if ("create".equalsIgnoreCase(command)) { } else if ("create".equalsIgnoreCase(command)) {
if (tokens.hasMoreTokens()) { if (tokens.hasMoreTokens()) {
String folderName = BASE64MailboxDecoder.decode(removeQuotes(tokens.nextToken())); String folderName = BASE64MailboxDecoder.decode(removeQuotes(tokens.nextToken()));
if (session.getFolder(folderName) != null) { session.createFolder(folderName);
sendClient(commandId + " OK folder already exists"); sendClient(commandId + " OK folder created");
} else {
// TODO
sendClient(commandId + " NO unsupported");
}
} else { } else {
sendClient(commandId + " BAD missing create argument"); sendClient(commandId + " BAD missing create argument");
} }
@ -281,7 +277,14 @@ public class ImapConnection extends AbstractConnection {
int size = Integer.parseInt(removeQuotes(tokens.nextToken())); int size = Integer.parseInt(removeQuotes(tokens.nextToken()));
sendClient("+ send literal data"); sendClient("+ send literal data");
char[] buffer = new char[size]; char[] buffer = new char[size];
in.read(buffer); int index = 0;
int count = 0;
while (count >= 0 && index < size) {
count = in.read(buffer, index, size - index);
if (count >= 0) {
index += count;
}
}
// empty line // empty line
readClient(); readClient();
session.createMessage(session.getFolderPath(folderName), "test", null, new String(buffer), true); session.createMessage(session.getFolderPath(folderName), "test", null, new String(buffer), true);