mirror of
https://github.com/moparisthebest/davmail
synced 2024-12-14 03:32: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:
parent
f619571390
commit
43ddbaf8e2
@ -14,6 +14,7 @@ import org.apache.webdav.lib.ResponseEntity;
|
||||
import org.apache.webdav.lib.WebdavResource;
|
||||
import org.apache.webdav.lib.methods.PropPatchMethod;
|
||||
import org.apache.webdav.lib.methods.SearchMethod;
|
||||
import org.apache.webdav.lib.methods.MkcolMethod;
|
||||
import org.htmlcleaner.CommentToken;
|
||||
import org.htmlcleaner.HtmlCleaner;
|
||||
import org.htmlcleaner.TagNode;
|
||||
@ -570,7 +571,7 @@ public class ExchangeSession {
|
||||
String folderUrl = getFolderPath(folderName);
|
||||
List<Message> messages = new ArrayList<Message>();
|
||||
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" +
|
||||
" WHERE \"DAV:ishidden\" = False AND \"DAV:isfolder\" = False\n" +
|
||||
" ORDER BY \"urn:schemas:httpmail:date\" ASC";
|
||||
@ -585,12 +586,12 @@ public class ExchangeSession {
|
||||
return messages;
|
||||
}
|
||||
|
||||
public List<Folder> getSubFolders(String folderName,boolean recursive) throws IOException {
|
||||
String mode = recursive?"DEEP":"SHALLOW";
|
||||
public List<Folder> getSubFolders(String folderName, boolean recursive) throws IOException {
|
||||
String mode = recursive ? "DEEP" : "SHALLOW";
|
||||
List<Folder> folders = new ArrayList<Folder>();
|
||||
String searchRequest = "Select \"DAV:nosubs\", \"DAV:hassubs\"," +
|
||||
" \"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";
|
||||
Enumeration folderEnum = DavGatewayHttpClientFacade.executeSearchMethod(wdr.retrieveSessionInstance(), mailPath, searchRequest);
|
||||
|
||||
@ -623,12 +624,12 @@ public class ExchangeSession {
|
||||
try {
|
||||
folder.lastModified = dateParser.parse(property.getPropertyAsString()).getTime();
|
||||
} catch (ParseException e) {
|
||||
LOGGER.error("Unable to parse date: "+e);
|
||||
LOGGER.error("Unable to parse date: " + e);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (href.endsWith("/")) {
|
||||
href = href.substring(0, href.length()-1);
|
||||
href = href.substring(0, href.length() - 1);
|
||||
}
|
||||
|
||||
// replace well known folder names
|
||||
@ -641,7 +642,7 @@ public class ExchangeSession {
|
||||
} else if (href.startsWith(deleteditemsUrl)) {
|
||||
folder.folderUrl = href.replaceFirst(deleteditemsUrl, "Trash");
|
||||
} else {
|
||||
int index = href.indexOf(mailPath.substring(0, mailPath.length()-1));
|
||||
int index = href.indexOf(mailPath.substring(0, mailPath.length() - 1));
|
||||
if (index >= 0) {
|
||||
folder.folderUrl = href.substring(index + mailPath.length());
|
||||
} else {
|
||||
@ -770,7 +771,7 @@ public class ExchangeSession {
|
||||
folderPath = folderName.replaceFirst("Drafts", draftsUrl);
|
||||
} else if (folderName.startsWith("Sent")) {
|
||||
folderPath = folderName.replaceFirst("Sent", sentitemsUrl);
|
||||
// absolute folder path
|
||||
// absolute folder path
|
||||
} else if (folderName != null && folderName.startsWith("/")) {
|
||||
folderPath = folderName;
|
||||
} else {
|
||||
@ -805,6 +806,41 @@ public class ExchangeSession {
|
||||
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 String folderUrl;
|
||||
public int objectCount;
|
||||
|
@ -161,12 +161,8 @@ public class ImapConnection extends AbstractConnection {
|
||||
} else if ("create".equalsIgnoreCase(command)) {
|
||||
if (tokens.hasMoreTokens()) {
|
||||
String folderName = BASE64MailboxDecoder.decode(removeQuotes(tokens.nextToken()));
|
||||
if (session.getFolder(folderName) != null) {
|
||||
sendClient(commandId + " OK folder already exists");
|
||||
} else {
|
||||
// TODO
|
||||
sendClient(commandId + " NO unsupported");
|
||||
}
|
||||
session.createFolder(folderName);
|
||||
sendClient(commandId + " OK folder created");
|
||||
} else {
|
||||
sendClient(commandId + " BAD missing create argument");
|
||||
}
|
||||
@ -254,7 +250,7 @@ public class ImapConnection extends AbstractConnection {
|
||||
|
||||
} else if ("store".equalsIgnoreCase(subcommand)) {
|
||||
// TODO
|
||||
sendClient(commandId + " OK STORE completed");
|
||||
sendClient(commandId + " OK STORE completed");
|
||||
}
|
||||
} else {
|
||||
sendClient(commandId + " BAD command unrecognized");
|
||||
@ -281,7 +277,14 @@ public class ImapConnection extends AbstractConnection {
|
||||
int size = Integer.parseInt(removeQuotes(tokens.nextToken()));
|
||||
sendClient("+ send literal data");
|
||||
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
|
||||
readClient();
|
||||
session.createMessage(session.getFolderPath(folderName), "test", null, new String(buffer), true);
|
||||
|
Loading…
Reference in New Issue
Block a user