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;
@ -570,7 +571,7 @@ public class ExchangeSession {
String folderUrl = getFolderPath(folderName); String folderUrl = getFolderPath(folderName);
List<Message> messages = new ArrayList<Message>(); List<Message> messages = new ArrayList<Message>();
String searchRequest = "Select \"DAV:uid\", \"http://schemas.microsoft.com/mapi/proptag/x0e080003\"" + String searchRequest = "Select \"DAV:uid\", \"http://schemas.microsoft.com/mapi/proptag/x0e080003\"" +
" ,\"urn:schemas:mailheader:from\",\"urn:schemas:mailheader:to\",\"urn:schemas:mailheader:cc\",\"urn:schemas:httpmail:subject\",\"urn:schemas:mailheader:date\",\"urn:schemas:mailheader:message-id\",\"urn:schemas:httpmail:priority\""+ " ,\"urn:schemas:mailheader:from\",\"urn:schemas:mailheader:to\",\"urn:schemas:mailheader:cc\",\"urn:schemas:httpmail:subject\",\"urn:schemas:mailheader:date\",\"urn:schemas:mailheader:message-id\",\"urn:schemas:httpmail:priority\"" +
" FROM Scope('SHALLOW TRAVERSAL OF \"" + folderUrl + "\"')\n" + " FROM Scope('SHALLOW TRAVERSAL OF \"" + folderUrl + "\"')\n" +
" WHERE \"DAV:ishidden\" = False AND \"DAV:isfolder\" = False\n" + " WHERE \"DAV:ishidden\" = False AND \"DAV:isfolder\" = False\n" +
" ORDER BY \"urn:schemas:httpmail:date\" ASC"; " ORDER BY \"urn:schemas:httpmail:date\" ASC";
@ -585,12 +586,12 @@ public class ExchangeSession {
return messages; return messages;
} }
public List<Folder> getSubFolders(String folderName,boolean recursive) throws IOException { public List<Folder> getSubFolders(String folderName, boolean recursive) throws IOException {
String mode = recursive?"DEEP":"SHALLOW"; String mode = recursive ? "DEEP" : "SHALLOW";
List<Folder> folders = new ArrayList<Folder>(); List<Folder> folders = new ArrayList<Folder>();
String searchRequest = "Select \"DAV:nosubs\", \"DAV:hassubs\"," + String searchRequest = "Select \"DAV:nosubs\", \"DAV:hassubs\"," +
" \"DAV:hassubs\",\"urn:schemas:httpmail:unreadcount\"" + " \"DAV:hassubs\",\"urn:schemas:httpmail:unreadcount\"" +
" FROM Scope('"+mode+" TRAVERSAL OF \"" + getFolderPath(folderName) + "\"')\n" + " FROM Scope('" + mode + " TRAVERSAL OF \"" + getFolderPath(folderName) + "\"')\n" +
" WHERE \"DAV:ishidden\" = False AND \"DAV:isfolder\" = True \n"; " WHERE \"DAV:ishidden\" = False AND \"DAV:isfolder\" = True \n";
Enumeration folderEnum = DavGatewayHttpClientFacade.executeSearchMethod(wdr.retrieveSessionInstance(), mailPath, searchRequest); Enumeration folderEnum = DavGatewayHttpClientFacade.executeSearchMethod(wdr.retrieveSessionInstance(), mailPath, searchRequest);
@ -623,12 +624,12 @@ public class ExchangeSession {
try { try {
folder.lastModified = dateParser.parse(property.getPropertyAsString()).getTime(); folder.lastModified = dateParser.parse(property.getPropertyAsString()).getTime();
} catch (ParseException e) { } catch (ParseException e) {
LOGGER.error("Unable to parse date: "+e); LOGGER.error("Unable to parse date: " + e);
} }
} }
} }
if (href.endsWith("/")) { if (href.endsWith("/")) {
href = href.substring(0, href.length()-1); href = href.substring(0, href.length() - 1);
} }
// replace well known folder names // replace well known folder names
@ -641,7 +642,7 @@ public class ExchangeSession {
} else if (href.startsWith(deleteditemsUrl)) { } else if (href.startsWith(deleteditemsUrl)) {
folder.folderUrl = href.replaceFirst(deleteditemsUrl, "Trash"); folder.folderUrl = href.replaceFirst(deleteditemsUrl, "Trash");
} else { } else {
int index = href.indexOf(mailPath.substring(0, mailPath.length()-1)); int index = href.indexOf(mailPath.substring(0, mailPath.length() - 1));
if (index >= 0) { if (index >= 0) {
folder.folderUrl = href.substring(index + mailPath.length()); folder.folderUrl = href.substring(index + mailPath.length());
} else { } else {
@ -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);