mirror of
https://github.com/moparisthebest/davmail
synced 2024-12-04 14:52:24 -05:00
IMAP: flagged, junk flags, draft replace (append + delete)
git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@314 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
parent
61b3f9c7a5
commit
70fc412250
@ -479,6 +479,10 @@ public class ExchangeSession {
|
|||||||
PutMethod putmethod = new PutMethod(messageUrl);
|
PutMethod putmethod = new PutMethod(messageUrl);
|
||||||
putmethod.setRequestHeader("Translate", "f");
|
putmethod.setRequestHeader("Translate", "f");
|
||||||
putmethod.setRequestHeader("Content-Type", "message/rfc822");
|
putmethod.setRequestHeader("Content-Type", "message/rfc822");
|
||||||
|
if (!allowOverwrite) {
|
||||||
|
putmethod.setRequestHeader("Allow-Rename", "t");
|
||||||
|
putmethod.setRequestHeader("If-None-Match", "*");
|
||||||
|
}
|
||||||
InputStream bodyStream = null;
|
InputStream bodyStream = null;
|
||||||
try {
|
try {
|
||||||
// use same encoding as client socket reader
|
// use same encoding as client socket reader
|
||||||
@ -543,6 +547,10 @@ public class ExchangeSession {
|
|||||||
message.uid = prop.getPropertyAsString();
|
message.uid = prop.getPropertyAsString();
|
||||||
} else if ("read".equals(localName)) {
|
} else if ("read".equals(localName)) {
|
||||||
message.read = "1".equals(prop.getPropertyAsString());
|
message.read = "1".equals(prop.getPropertyAsString());
|
||||||
|
} else if ("x10830003".equals(localName)) {
|
||||||
|
message.junk = "1".equals(prop.getPropertyAsString());
|
||||||
|
} else if ("x10900003".equals(localName)) {
|
||||||
|
message.flagged = "2".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(">")) {
|
||||||
@ -575,6 +583,10 @@ public class ExchangeSession {
|
|||||||
for (Map.Entry<String, String> entry : properties.entrySet()) {
|
for (Map.Entry<String, String> entry : properties.entrySet()) {
|
||||||
if ("read".equals(entry.getKey())) {
|
if ("read".equals(entry.getKey())) {
|
||||||
patchMethod.addPropertyToSet("read", entry.getValue(), "e", "urn:schemas:httpmail:");
|
patchMethod.addPropertyToSet("read", entry.getValue(), "e", "urn:schemas:httpmail:");
|
||||||
|
} else if ("junk".equals(entry.getKey())) {
|
||||||
|
patchMethod.addPropertyToSet("x10830003", entry.getValue(), "f", "http://schemas.microsoft.com/mapi/proptag/");
|
||||||
|
} else if ("flagged".equals(entry.getKey())) {
|
||||||
|
patchMethod.addPropertyToSet("x10900003", entry.getValue(), "f", "http://schemas.microsoft.com/mapi/proptag/");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int statusCode = wdr.retrieveSessionInstance().executeMethod(patchMethod);
|
int statusCode = wdr.retrieveSessionInstance().executeMethod(patchMethod);
|
||||||
@ -591,6 +603,7 @@ public class ExchangeSession {
|
|||||||
String folderUrl = getFolderPath(folderName);
|
String folderUrl = getFolderPath(folderName);
|
||||||
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\"" +
|
||||||
" ,\"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" +
|
||||||
@ -877,7 +890,6 @@ public class ExchangeSession {
|
|||||||
MoveMethod method = new MoveMethod(URIUtil.encodePath(folderPath),
|
MoveMethod method = new MoveMethod(URIUtil.encodePath(folderPath),
|
||||||
URIUtil.encodePath(targetPath));
|
URIUtil.encodePath(targetPath));
|
||||||
method.setOverwrite(false);
|
method.setOverwrite(false);
|
||||||
//method.addRequestHeader("Allow-Rename", "t");
|
|
||||||
try {
|
try {
|
||||||
int statusCode = wdr.retrieveSessionInstance().executeMethod(method);
|
int statusCode = wdr.retrieveSessionInstance().executeMethod(method);
|
||||||
if (statusCode == HttpStatus.SC_PRECONDITION_FAILED) {
|
if (statusCode == HttpStatus.SC_PRECONDITION_FAILED) {
|
||||||
@ -920,6 +932,8 @@ public class ExchangeSession {
|
|||||||
public String messageId;
|
public String messageId;
|
||||||
public boolean read;
|
public boolean read;
|
||||||
public boolean deleted;
|
public boolean deleted;
|
||||||
|
public boolean junk;
|
||||||
|
public boolean flagged;
|
||||||
|
|
||||||
public long getUidAsLong() {
|
public long getUidAsLong() {
|
||||||
byte[] decodedValue = Base64.decode(uid.getBytes());
|
byte[] decodedValue = Base64.decode(uid.getBytes());
|
||||||
@ -939,9 +953,15 @@ public class ExchangeSession {
|
|||||||
buffer.append("\\Seen ");
|
buffer.append("\\Seen ");
|
||||||
}
|
}
|
||||||
if (deleted) {
|
if (deleted) {
|
||||||
buffer.append("\\Deleted");
|
buffer.append("\\Deleted ");
|
||||||
}
|
}
|
||||||
return buffer.toString();
|
if (flagged) {
|
||||||
|
buffer.append("\\Flagged ");
|
||||||
|
}
|
||||||
|
if (junk) {
|
||||||
|
buffer.append("Junk ");
|
||||||
|
}
|
||||||
|
return buffer.toString().trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void write(OutputStream os) throws IOException {
|
public void write(OutputStream os) throws IOException {
|
||||||
|
@ -17,6 +17,7 @@ import java.net.SocketTimeoutException;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.StringTokenizer;
|
import java.util.StringTokenizer;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Dav Gateway smtp connection implementation.
|
* Dav Gateway smtp connection implementation.
|
||||||
@ -26,6 +27,8 @@ public class ImapConnection extends AbstractConnection {
|
|||||||
protected static final int INITIAL = 0;
|
protected static final int INITIAL = 0;
|
||||||
protected static final int AUTHENTICATED = 2;
|
protected static final int AUTHENTICATED = 2;
|
||||||
|
|
||||||
|
protected Random random = new Random();
|
||||||
|
|
||||||
ExchangeSession.Folder currentFolder;
|
ExchangeSession.Folder currentFolder;
|
||||||
ExchangeSession.MessageList messages;
|
ExchangeSession.MessageList messages;
|
||||||
|
|
||||||
@ -156,8 +159,8 @@ public class ImapConnection extends AbstractConnection {
|
|||||||
} else {
|
} else {
|
||||||
sendClient("* OK [UIDNEXT " + (messages.get(messages.size() - 1).getUidAsLong() + 1) + "]");
|
sendClient("* OK [UIDNEXT " + (messages.get(messages.size() - 1).getUidAsLong() + 1) + "]");
|
||||||
}
|
}
|
||||||
sendClient("* FLAGS (\\Answered \\Deleted \\Draft \\Flagged \\Seen $Forwarded $MDNSent Forwarded $Junk $NotJunk Junk JunkRecorded NonJunk NotJunk)");
|
sendClient("* FLAGS (\\Answered \\Deleted \\Draft \\Flagged \\Seen $Forwarded Forwarded Junk)");
|
||||||
sendClient("* OK [PERMANENTFLAGS (\\Answered \\Deleted \\Draft \\Flagged \\Seen $Forwarded $MDNSent Forwarded \\*)] junk-related flags are not permanent");
|
sendClient("* OK [PERMANENTFLAGS (\\Answered \\Deleted \\Draft \\Flagged \\Seen $Forwarded Forwarded Junk \\*)]");
|
||||||
//sendClient("* [UNSEEN 1] first unseen message in inbox");
|
//sendClient("* [UNSEEN 1] first unseen message in inbox");
|
||||||
sendClient(commandId + " OK [READ-WRITE] " + command + " completed");
|
sendClient(commandId + " OK [READ-WRITE] " + command + " completed");
|
||||||
} else {
|
} else {
|
||||||
@ -308,6 +311,12 @@ public class ImapConnection extends AbstractConnection {
|
|||||||
if ("\\Seen".equals(flag)) {
|
if ("\\Seen".equals(flag)) {
|
||||||
properties.put("read", "0");
|
properties.put("read", "0");
|
||||||
message.read = false;
|
message.read = false;
|
||||||
|
} else if ("\\Flagged".equals(flag)) {
|
||||||
|
properties.put("flagged", "0");
|
||||||
|
message.flagged = false;
|
||||||
|
} else if ("Junk".equals(flag)) {
|
||||||
|
properties.put("junk", "0");
|
||||||
|
message.junk = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if ("+Flags".equalsIgnoreCase(action)) {
|
} else if ("+Flags".equalsIgnoreCase(action)) {
|
||||||
@ -319,10 +328,18 @@ public class ImapConnection extends AbstractConnection {
|
|||||||
message.read = true;
|
message.read = true;
|
||||||
} else if ("\\Deleted".equals(flag)) {
|
} else if ("\\Deleted".equals(flag)) {
|
||||||
message.deleted = true;
|
message.deleted = true;
|
||||||
|
} else if ("\\Flagged".equals(flag)) {
|
||||||
|
properties.put("flagged", "2");
|
||||||
|
message.flagged = true;
|
||||||
|
} else if ("Junk".equals(flag)) {
|
||||||
|
properties.put("junk", "1");
|
||||||
|
message.junk = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
session.updateMessage(messages.getByUid(uid), properties);
|
if (properties.size() > 0) {
|
||||||
|
session.updateMessage(messages.getByUid(uid), properties);
|
||||||
|
}
|
||||||
int index = 0;
|
int index = 0;
|
||||||
for (ExchangeSession.Message currentMessage : messages) {
|
for (ExchangeSession.Message currentMessage : messages) {
|
||||||
index++;
|
index++;
|
||||||
@ -378,19 +395,9 @@ public class ImapConnection extends AbstractConnection {
|
|||||||
}
|
}
|
||||||
// empty line
|
// empty line
|
||||||
readClient();
|
readClient();
|
||||||
String messageBody = new String(buffer);
|
|
||||||
String subject = null;
|
String mailName = Long.toHexString(System.currentTimeMillis()) + Long.toHexString(random.nextLong());
|
||||||
int subjectStartIndex = messageBody.indexOf("Subject: ");
|
session.createMessage(session.getFolderPath(folderName), mailName, null, new String(buffer), false);
|
||||||
if (subjectStartIndex >= 0) {
|
|
||||||
int subjectEndIndex = messageBody.indexOf("\r", subjectStartIndex);
|
|
||||||
if (subjectEndIndex >= 0) {
|
|
||||||
subject = messageBody.substring(subjectStartIndex + "Subject: ".length(), subjectEndIndex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (subject == null) {
|
|
||||||
subject = "mail" + System.currentTimeMillis();
|
|
||||||
}
|
|
||||||
session.createMessage(session.getFolderPath(folderName), subject, null, new String(buffer), true);
|
|
||||||
sendClient(commandId + " OK APPEND completed");
|
sendClient(commandId + " OK APPEND completed");
|
||||||
} else if ("noop".equalsIgnoreCase(command) || "check".equalsIgnoreCase(command)) {
|
} else if ("noop".equalsIgnoreCase(command) || "check".equalsIgnoreCase(command)) {
|
||||||
if (currentFolder != null) {
|
if (currentFolder != null) {
|
||||||
@ -439,7 +446,7 @@ public class ImapConnection extends AbstractConnection {
|
|||||||
index++;
|
index++;
|
||||||
if (message.deleted) {
|
if (message.deleted) {
|
||||||
session.deleteMessage(message.messageUrl);
|
session.deleteMessage(message.messageUrl);
|
||||||
sendClient("* "+index+" EXPUNGE");
|
sendClient("* " + index + " EXPUNGE");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user