mirror of
https://github.com/moparisthebest/davmail
synced 2024-12-13 19:22:22 -05:00
IMAP: Create messages as Draft, handle draft flag
git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@317 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
parent
ebac6850dc
commit
ad851bc6ce
@ -476,44 +476,17 @@ public class ExchangeSession {
|
|||||||
public void createMessage(String folderUrl, String messageName, String bcc, String messageBody, boolean allowOverwrite) throws IOException {
|
public void createMessage(String folderUrl, String messageName, String bcc, String messageBody, boolean allowOverwrite) throws IOException {
|
||||||
String messageUrl = URIUtil.encodePathQuery(folderUrl + "/" + encodeSubject(messageName) + ".EML");
|
String messageUrl = URIUtil.encodePathQuery(folderUrl + "/" + encodeSubject(messageName) + ".EML");
|
||||||
|
|
||||||
PutMethod putmethod = new PutMethod(messageUrl);
|
// create the message first as draft
|
||||||
putmethod.setRequestHeader("Translate", "f");
|
PropPatchMethod patchMethod = new PropPatchMethod(messageUrl);
|
||||||
putmethod.setRequestHeader("Content-Type", "message/rfc822");
|
|
||||||
if (!allowOverwrite) {
|
if (!allowOverwrite) {
|
||||||
putmethod.setRequestHeader("Allow-Rename", "t");
|
patchMethod.setRequestHeader("If-None-Match", "*");
|
||||||
putmethod.setRequestHeader("If-None-Match", "*");
|
|
||||||
}
|
}
|
||||||
InputStream bodyStream = null;
|
|
||||||
try {
|
try {
|
||||||
// use same encoding as client socket reader
|
|
||||||
bodyStream = new ByteArrayInputStream(messageBody.getBytes());
|
|
||||||
putmethod.setRequestBody(bodyStream);
|
|
||||||
int code = wdr.retrieveSessionInstance().executeMethod(putmethod);
|
|
||||||
|
|
||||||
if (code == HttpURLConnection.HTTP_OK) {
|
|
||||||
if (allowOverwrite) {
|
|
||||||
LOGGER.warn("Overwritten message " + messageUrl);
|
|
||||||
} else {
|
|
||||||
throw new IOException("Overwritten message " + messageUrl);
|
|
||||||
}
|
|
||||||
} else if (code != HttpURLConnection.HTTP_CREATED) {
|
|
||||||
throw new IOException("Unable to create message " + messageUrl + ": " + code + " " + putmethod.getStatusLine());
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
if (bodyStream != null) {
|
|
||||||
try {
|
|
||||||
bodyStream.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
LOGGER.error(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
putmethod.releaseConnection();
|
|
||||||
}
|
|
||||||
// update message with blind carbon copy
|
// update message with blind carbon copy
|
||||||
if (bcc != null && bcc.length() > 0) {
|
if (bcc != null && bcc.length() > 0) {
|
||||||
PropPatchMethod patchMethod = new PropPatchMethod(messageUrl);
|
|
||||||
try {
|
|
||||||
patchMethod.addPropertyToSet("bcc", bcc, "b", "urn:schemas:mailheader:");
|
patchMethod.addPropertyToSet("bcc", bcc, "b", "urn:schemas:mailheader:");
|
||||||
|
}
|
||||||
|
patchMethod.addPropertyToSet("x0E070003", "9", "d", "http://schemas.microsoft.com/mapi/proptag/");
|
||||||
int statusCode = wdr.retrieveSessionInstance().executeMethod(patchMethod);
|
int statusCode = wdr.retrieveSessionInstance().executeMethod(patchMethod);
|
||||||
if (statusCode != HttpStatus.SC_MULTI_STATUS) {
|
if (statusCode != HttpStatus.SC_MULTI_STATUS) {
|
||||||
throw new IOException("Unable to add bcc recipients: " + bcc);
|
throw new IOException("Unable to add bcc recipients: " + bcc);
|
||||||
@ -530,7 +503,31 @@ public class ExchangeSession {
|
|||||||
} finally {
|
} finally {
|
||||||
patchMethod.releaseConnection();
|
patchMethod.releaseConnection();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PutMethod putmethod = new PutMethod(messageUrl);
|
||||||
|
putmethod.setRequestHeader("Translate", "f");
|
||||||
|
putmethod.setRequestHeader("Content-Type", "message/rfc822");
|
||||||
|
InputStream bodyStream = null;
|
||||||
|
try {
|
||||||
|
// use same encoding as client socket reader
|
||||||
|
bodyStream = new ByteArrayInputStream(messageBody.getBytes());
|
||||||
|
putmethod.setRequestBody(bodyStream);
|
||||||
|
int code = wdr.retrieveSessionInstance().executeMethod(putmethod);
|
||||||
|
|
||||||
|
if (code != HttpURLConnection.HTTP_OK) {
|
||||||
|
throw new IOException("Unable to create message " + messageUrl + ": " + code + " " + putmethod.getStatusLine());
|
||||||
}
|
}
|
||||||
|
} finally {
|
||||||
|
if (bodyStream != null) {
|
||||||
|
try {
|
||||||
|
bodyStream.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
LOGGER.error(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
putmethod.releaseConnection();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Message buildMessage(ResponseEntity responseEntity) throws URIException {
|
protected Message buildMessage(ResponseEntity responseEntity) throws URIException {
|
||||||
@ -551,6 +548,8 @@ public class ExchangeSession {
|
|||||||
message.junk = "1".equals(prop.getPropertyAsString());
|
message.junk = "1".equals(prop.getPropertyAsString());
|
||||||
} else if ("x10900003".equals(localName)) {
|
} else if ("x10900003".equals(localName)) {
|
||||||
message.flagged = "2".equals(prop.getPropertyAsString());
|
message.flagged = "2".equals(prop.getPropertyAsString());
|
||||||
|
} else if ("x0E070003".equals(localName)) {
|
||||||
|
message.draft = "9".equals(prop.getPropertyAsString());
|
||||||
} else if ("message-id".equals(prop.getLocalName())) {
|
} else if ("message-id".equals(prop.getLocalName())) {
|
||||||
message.messageId = prop.getPropertyAsString();
|
message.messageId = prop.getPropertyAsString();
|
||||||
if (message.messageId.startsWith("<") && message.messageId.endsWith(">")) {
|
if (message.messageId.startsWith("<") && message.messageId.endsWith(">")) {
|
||||||
@ -604,6 +603,7 @@ public class ExchangeSession {
|
|||||||
MessageList messages = new MessageList();
|
MessageList messages = new MessageList();
|
||||||
String searchRequest = "Select \"DAV:uid\", \"http://schemas.microsoft.com/mapi/proptag/x0e080003\"" +
|
String searchRequest = "Select \"DAV:uid\", \"http://schemas.microsoft.com/mapi/proptag/x0e080003\"" +
|
||||||
" ,\"http://schemas.microsoft.com/mapi/proptag/x10830003\", \"http://schemas.microsoft.com/mapi/proptag/x10900003\"" +
|
" ,\"http://schemas.microsoft.com/mapi/proptag/x10830003\", \"http://schemas.microsoft.com/mapi/proptag/x10900003\"" +
|
||||||
|
" ,\"http://schemas.microsoft.com/mapi/proptag/x0E070003\"" +
|
||||||
" ,\"urn:schemas:mailheader:message-id\", \"urn:schemas:httpmail:read\"" +
|
" ,\"urn:schemas:mailheader:message-id\", \"urn:schemas:httpmail:read\"" +
|
||||||
" 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" +
|
||||||
@ -934,6 +934,7 @@ public class ExchangeSession {
|
|||||||
public boolean deleted;
|
public boolean deleted;
|
||||||
public boolean junk;
|
public boolean junk;
|
||||||
public boolean flagged;
|
public boolean flagged;
|
||||||
|
public boolean draft;
|
||||||
|
|
||||||
public long getUidAsLong() {
|
public long getUidAsLong() {
|
||||||
byte[] decodedValue = Base64.decode(uid.getBytes());
|
byte[] decodedValue = Base64.decode(uid.getBytes());
|
||||||
@ -961,6 +962,9 @@ public class ExchangeSession {
|
|||||||
if (junk) {
|
if (junk) {
|
||||||
buffer.append("Junk ");
|
buffer.append("Junk ");
|
||||||
}
|
}
|
||||||
|
if (draft) {
|
||||||
|
buffer.append("\\Draft ");
|
||||||
|
}
|
||||||
return buffer.toString().trim();
|
return buffer.toString().trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user