mirror of
https://github.com/moparisthebest/davmail
synced 2024-12-13 03:02:22 -05: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
|
||||
*/
|
||||
public Folder getFolder(String folderName) throws IOException {
|
||||
Folder folder = new Folder();
|
||||
folder.folderUrl = getFolderPath(folderName);
|
||||
|
||||
Vector<String> reqProps = new Vector<String>();
|
||||
reqProps.add("DAV:hassubs");
|
||||
reqProps.add("DAV:nosubs");
|
||||
reqProps.add("DAV:objectcount");
|
||||
reqProps.add("urn:schemas:httpmail:unreadcount");
|
||||
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()) {
|
||||
ResponseEntity entity = (ResponseEntity) folderEnum.nextElement();
|
||||
folder = buildFolder(entity);
|
||||
folder.folderName = folderName;
|
||||
}
|
||||
return folder;
|
||||
}
|
||||
@ -814,6 +812,7 @@ public class ExchangeSession {
|
||||
public boolean hasChildren;
|
||||
public boolean noInferiors;
|
||||
public long lastModified;
|
||||
public String folderName;
|
||||
|
||||
public String getFlags() {
|
||||
if (noInferiors) {
|
||||
|
@ -171,65 +171,90 @@ public class ImapConnection extends AbstractConnection {
|
||||
sendClient(commandId + " BAD missing create argument");
|
||||
}
|
||||
} else if ("uid".equalsIgnoreCase(command)) {
|
||||
if (tokens.hasMoreTokens() && "fetch".equalsIgnoreCase(tokens.nextToken())) {
|
||||
if (tokens.hasMoreTokens()) {
|
||||
String messageParameter = tokens.nextToken();
|
||||
if (currentFolder == null) {
|
||||
sendClient(commandId + " NO no folder selected");
|
||||
}
|
||||
int startIndex;
|
||||
int endIndex;
|
||||
int colonIndex = messageParameter.indexOf(":");
|
||||
if (colonIndex < 0) {
|
||||
startIndex = endIndex = Integer.parseInt(messageParameter);
|
||||
} else {
|
||||
startIndex = Integer.parseInt(messageParameter.substring(0, colonIndex));
|
||||
if (messageParameter.endsWith("*")) {
|
||||
endIndex = messages.size();
|
||||
if (tokens.hasMoreTokens()) {
|
||||
String subcommand = tokens.nextToken();
|
||||
if ("fetch".equalsIgnoreCase(subcommand)) {
|
||||
if (tokens.hasMoreTokens()) {
|
||||
String messageParameter = tokens.nextToken();
|
||||
if (currentFolder == null) {
|
||||
sendClient(commandId + " NO no folder selected");
|
||||
}
|
||||
int startIndex;
|
||||
int endIndex;
|
||||
int colonIndex = messageParameter.indexOf(":");
|
||||
if (colonIndex < 0) {
|
||||
startIndex = endIndex = Integer.parseInt(messageParameter);
|
||||
} else {
|
||||
endIndex = Integer.parseInt(messageParameter.substring(colonIndex + 1));
|
||||
}
|
||||
}
|
||||
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))");
|
||||
}
|
||||
startIndex = Integer.parseInt(messageParameter.substring(0, colonIndex));
|
||||
if (messageParameter.endsWith("*")) {
|
||||
endIndex = messages.size();
|
||||
} else {
|
||||
endIndex = Integer.parseInt(messageParameter.substring(colonIndex + 1));
|
||||
}
|
||||
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 {
|
||||
sendClient(commandId + " BAD command unrecognized");
|
||||
if (messageIndex > 0) {
|
||||
sendClient("* SEARCH " + messageIndex);
|
||||
}
|
||||
sendClient(commandId + " OK SEARCH completed");
|
||||
|
||||
} else if ("store".equalsIgnoreCase(subcommand)) {
|
||||
// TODO
|
||||
sendClient(commandId + " OK STORE completed");
|
||||
}
|
||||
} else {
|
||||
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);
|
||||
sendClient(commandId + " OK APPEND completed");
|
||||
} 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");
|
||||
} else {
|
||||
sendClient(commandId + " BAD command unrecognized");
|
||||
|
Loading…
Reference in New Issue
Block a user