mirror of
https://github.com/moparisthebest/davmail
synced 2024-08-13 16:53:51 -04:00
IMAP: implement search check after append
git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@304 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
parent
98f4ea5e51
commit
f619571390
@ -789,20 +789,18 @@ public class ExchangeSession {
|
|||||||
* @throws IOException when unable to change folder
|
* @throws IOException when unable to change folder
|
||||||
*/
|
*/
|
||||||
public Folder getFolder(String folderName) throws IOException {
|
public Folder getFolder(String folderName) throws IOException {
|
||||||
Folder folder = new Folder();
|
|
||||||
folder.folderUrl = getFolderPath(folderName);
|
|
||||||
|
|
||||||
Vector<String> reqProps = new Vector<String>();
|
Vector<String> reqProps = new Vector<String>();
|
||||||
reqProps.add("DAV:hassubs");
|
reqProps.add("DAV:hassubs");
|
||||||
reqProps.add("DAV:nosubs");
|
reqProps.add("DAV:nosubs");
|
||||||
reqProps.add("DAV:objectcount");
|
reqProps.add("DAV:objectcount");
|
||||||
reqProps.add("urn:schemas:httpmail:unreadcount");
|
reqProps.add("urn:schemas:httpmail:unreadcount");
|
||||||
reqProps.add("DAV:getlastmodified");
|
reqProps.add("DAV:getlastmodified");
|
||||||
Enumeration folderEnum = wdr.propfindMethod(folder.folderUrl, 0, reqProps);
|
Enumeration folderEnum = wdr.propfindMethod(getFolderPath(folderName), 0, reqProps);
|
||||||
|
Folder folder = null;
|
||||||
if (folderEnum.hasMoreElements()) {
|
if (folderEnum.hasMoreElements()) {
|
||||||
ResponseEntity entity = (ResponseEntity) folderEnum.nextElement();
|
ResponseEntity entity = (ResponseEntity) folderEnum.nextElement();
|
||||||
folder = buildFolder(entity);
|
folder = buildFolder(entity);
|
||||||
|
folder.folderName = folderName;
|
||||||
}
|
}
|
||||||
return folder;
|
return folder;
|
||||||
}
|
}
|
||||||
@ -814,6 +812,7 @@ public class ExchangeSession {
|
|||||||
public boolean hasChildren;
|
public boolean hasChildren;
|
||||||
public boolean noInferiors;
|
public boolean noInferiors;
|
||||||
public long lastModified;
|
public long lastModified;
|
||||||
|
public String folderName;
|
||||||
|
|
||||||
public String getFlags() {
|
public String getFlags() {
|
||||||
if (noInferiors) {
|
if (noInferiors) {
|
||||||
|
@ -171,65 +171,90 @@ public class ImapConnection extends AbstractConnection {
|
|||||||
sendClient(commandId + " BAD missing create argument");
|
sendClient(commandId + " BAD missing create argument");
|
||||||
}
|
}
|
||||||
} else if ("uid".equalsIgnoreCase(command)) {
|
} else if ("uid".equalsIgnoreCase(command)) {
|
||||||
if (tokens.hasMoreTokens() && "fetch".equalsIgnoreCase(tokens.nextToken())) {
|
if (tokens.hasMoreTokens()) {
|
||||||
if (tokens.hasMoreTokens()) {
|
String subcommand = tokens.nextToken();
|
||||||
String messageParameter = tokens.nextToken();
|
if ("fetch".equalsIgnoreCase(subcommand)) {
|
||||||
if (currentFolder == null) {
|
if (tokens.hasMoreTokens()) {
|
||||||
sendClient(commandId + " NO no folder selected");
|
String messageParameter = tokens.nextToken();
|
||||||
}
|
if (currentFolder == null) {
|
||||||
int startIndex;
|
sendClient(commandId + " NO no folder selected");
|
||||||
int endIndex;
|
}
|
||||||
int colonIndex = messageParameter.indexOf(":");
|
int startIndex;
|
||||||
if (colonIndex < 0) {
|
int endIndex;
|
||||||
startIndex = endIndex = Integer.parseInt(messageParameter);
|
int colonIndex = messageParameter.indexOf(":");
|
||||||
} else {
|
if (colonIndex < 0) {
|
||||||
startIndex = Integer.parseInt(messageParameter.substring(0, colonIndex));
|
startIndex = endIndex = Integer.parseInt(messageParameter);
|
||||||
if (messageParameter.endsWith("*")) {
|
|
||||||
endIndex = messages.size();
|
|
||||||
} else {
|
} else {
|
||||||
endIndex = Integer.parseInt(messageParameter.substring(colonIndex + 1));
|
startIndex = Integer.parseInt(messageParameter.substring(0, colonIndex));
|
||||||
}
|
if (messageParameter.endsWith("*")) {
|
||||||
}
|
endIndex = messages.size();
|
||||||
if ("1:*".equals(messageParameter)) {
|
} else {
|
||||||
int count = 0;
|
endIndex = Integer.parseInt(messageParameter.substring(colonIndex + 1));
|
||||||
for (ExchangeSession.Message message : messages) {
|
|
||||||
count++;
|
|
||||||
sendClient("* " + count + " FETCH (UID " + count + " FLAGS (\\Seen))");
|
|
||||||
}
|
|
||||||
sendClient(commandId + " OK UID FETCH completed");
|
|
||||||
} else {
|
|
||||||
if (tokens.hasMoreTokens()) {
|
|
||||||
String parameters = tokens.nextToken();
|
|
||||||
for (int messageIndex = startIndex; messageIndex <= endIndex; messageIndex++) {
|
|
||||||
ExchangeSession.Message message = messages.get(messageIndex - 1);
|
|
||||||
|
|
||||||
if ("(BODYSTRUCTURE)".equals(parameters)) {
|
|
||||||
sendClient("* " + messageIndex + " FETCH (BODYSTRUCTURE (\"TEXT\" \"PLAIN\" (\"CHARSET\" \"windows-1252\") NIL NIL \"QUOTED-PRINTABLE\" " + message.size + " 50 NIL NIL NIL NIL))");
|
|
||||||
} else if (parameters.indexOf("BODY[]") >= 0) {
|
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
|
||||||
message.write(baos);
|
|
||||||
baos.close();
|
|
||||||
|
|
||||||
sendClient("* " + messageIndex + " FETCH (UID " + messageIndex + " RFC822.SIZE " + baos.size() + " BODY[]<0>" +
|
|
||||||
" {" + baos.size() + "}");
|
|
||||||
message.write(os);
|
|
||||||
sendClient(")");
|
|
||||||
} else {
|
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
|
||||||
message.write(baos);
|
|
||||||
baos.close();
|
|
||||||
sendClient("* " + messageIndex + " FETCH (UID " + messageIndex + " RFC822.SIZE " + baos.size() + " BODY[HEADER.FIELDS (FROM TO CC SUBJECT DATE MESSAGE-ID PRIORITY X-PRIORITY REFERENCES NEWSGROUPS IN-REPLY-TO CONTENT-TYPE)" +
|
|
||||||
"] {" + baos.size() + "}");
|
|
||||||
message.write(os);
|
|
||||||
sendClient(" FLAGS (\\Seen))");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
sendClient(commandId + " OK FETCH completed");
|
}
|
||||||
|
if ("1:*".equals(messageParameter)) {
|
||||||
|
int count = 0;
|
||||||
|
for (ExchangeSession.Message message : messages) {
|
||||||
|
count++;
|
||||||
|
sendClient("* " + count + " FETCH (UID " + count + " FLAGS (\\Seen))");
|
||||||
|
}
|
||||||
|
sendClient(commandId + " OK UID FETCH completed");
|
||||||
|
} else {
|
||||||
|
if (tokens.hasMoreTokens()) {
|
||||||
|
String parameters = tokens.nextToken();
|
||||||
|
for (int messageIndex = startIndex; messageIndex <= endIndex; messageIndex++) {
|
||||||
|
ExchangeSession.Message message = messages.get(messageIndex - 1);
|
||||||
|
|
||||||
|
if ("(BODYSTRUCTURE)".equals(parameters)) {
|
||||||
|
sendClient("* " + messageIndex + " FETCH (BODYSTRUCTURE (\"TEXT\" \"PLAIN\" (\"CHARSET\" \"windows-1252\") NIL NIL \"QUOTED-PRINTABLE\" " + message.size + " 50 NIL NIL NIL NIL))");
|
||||||
|
} else if (parameters.indexOf("BODY[]") >= 0) {
|
||||||
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
|
message.write(baos);
|
||||||
|
baos.close();
|
||||||
|
|
||||||
|
sendClient("* " + messageIndex + " FETCH (UID " + messageIndex + " RFC822.SIZE " + baos.size() + " BODY[]<0>" +
|
||||||
|
" {" + baos.size() + "}");
|
||||||
|
message.write(os);
|
||||||
|
sendClient(")");
|
||||||
|
} else {
|
||||||
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
|
message.write(baos);
|
||||||
|
baos.close();
|
||||||
|
sendClient("* " + messageIndex + " FETCH (UID " + messageIndex + " RFC822.SIZE " + baos.size() + " BODY[HEADER.FIELDS (FROM TO CC SUBJECT DATE MESSAGE-ID PRIORITY X-PRIORITY REFERENCES NEWSGROUPS IN-REPLY-TO CONTENT-TYPE)" +
|
||||||
|
"] {" + baos.size() + "}");
|
||||||
|
message.write(os);
|
||||||
|
sendClient(" FLAGS (\\Seen))");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sendClient(commandId + " OK FETCH completed");
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
sendClient(commandId + " BAD command unrecognized");
|
||||||
|
}
|
||||||
|
} else if ("search".equalsIgnoreCase(subcommand)) {
|
||||||
|
// only create check search
|
||||||
|
String messageId = null;
|
||||||
|
int messageIndex = 0;
|
||||||
|
while (tokens.hasMoreTokens()) {
|
||||||
|
messageId = tokens.nextToken();
|
||||||
|
}
|
||||||
|
// reload messages
|
||||||
|
messages = session.getAllMessages(currentFolder.folderName);
|
||||||
|
for (int i = 0; i < messages.size(); i++) {
|
||||||
|
if (messageId.equals(messages.get(i).messageId)) {
|
||||||
|
messageIndex = i + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
if (messageIndex > 0) {
|
||||||
sendClient(commandId + " BAD command unrecognized");
|
sendClient("* SEARCH " + messageIndex);
|
||||||
|
}
|
||||||
|
sendClient(commandId + " OK SEARCH completed");
|
||||||
|
|
||||||
|
} else if ("store".equalsIgnoreCase(subcommand)) {
|
||||||
|
// TODO
|
||||||
|
sendClient(commandId + " OK STORE completed");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
sendClient(commandId + " BAD command unrecognized");
|
sendClient(commandId + " BAD command unrecognized");
|
||||||
@ -262,6 +287,11 @@ public class ImapConnection extends AbstractConnection {
|
|||||||
session.createMessage(session.getFolderPath(folderName), "test", null, new String(buffer), true);
|
session.createMessage(session.getFolderPath(folderName), "test", null, new String(buffer), true);
|
||||||
sendClient(commandId + " OK APPEND completed");
|
sendClient(commandId + " OK APPEND completed");
|
||||||
} else if ("noop".equalsIgnoreCase(command)) {
|
} else if ("noop".equalsIgnoreCase(command)) {
|
||||||
|
if (currentFolder != null) {
|
||||||
|
currentFolder = session.getFolder(currentFolder.folderName);
|
||||||
|
sendClient("* " + currentFolder.objectCount + " EXISTS");
|
||||||
|
sendClient("* " + currentFolder.objectCount + " RECENT");
|
||||||
|
}
|
||||||
sendClient(commandId + " OK NOOP completed");
|
sendClient(commandId + " OK NOOP completed");
|
||||||
} else {
|
} else {
|
||||||
sendClient(commandId + " BAD command unrecognized");
|
sendClient(commandId + " BAD command unrecognized");
|
||||||
|
Loading…
Reference in New Issue
Block a user