1
0
mirror of https://github.com/moparisthebest/davmail synced 2025-02-28 09:21:49 -05:00

IMAP: replaced uid parsing by a new MAPI property: CdoPR_INTERNET_ARTICLE_NUMBER

git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@464 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
mguessan 2009-03-19 12:41:11 +00:00
parent 4dddf4a50f
commit f7cb5d4beb
2 changed files with 23 additions and 24 deletions

View File

@ -7,7 +7,6 @@ import org.apache.commons.httpclient.auth.AuthenticationException;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.PutMethod;
import org.apache.commons.httpclient.util.Base64;
import org.apache.commons.httpclient.util.URIUtil;
import org.apache.log4j.Logger;
import org.apache.webdav.lib.Property;
@ -530,6 +529,8 @@ public class ExchangeSession {
message.size = Integer.parseInt(prop.getPropertyAsString());
} else if ("uid".equals(localName)) {
message.uid = prop.getPropertyAsString();
} else if ("x0e230003".equals(localName)) {
message.imapUid = Long.parseLong(prop.getPropertyAsString());
} else if ("read".equals(localName)) {
message.read = "1".equals(prop.getPropertyAsString());
} else if ("x10830003".equals(localName)) {
@ -608,6 +609,7 @@ public class ExchangeSession {
String folderUrl = getFolderPath(folderName);
MessageList messages = new MessageList();
String searchRequest = "Select \"DAV:uid\", \"http://schemas.microsoft.com/mapi/proptag/x0e080003\"" +
" ,\"http://schemas.microsoft.com/mapi/proptag/x0e230003\""+
" ,\"http://schemas.microsoft.com/mapi/proptag/x10830003\", \"http://schemas.microsoft.com/mapi/proptag/x10900003\"" +
" ,\"http://schemas.microsoft.com/mapi/proptag/x0E070003\", \"http://schemas.microsoft.com/mapi/proptag/x10810003\"" +
" ,\"urn:schemas:mailheader:message-id\", \"urn:schemas:httpmail:read\", \"DAV:isdeleted\", \"urn:schemas:mailheader:date\"" +
@ -939,6 +941,7 @@ public class ExchangeSession {
public class Message implements Comparable {
public String messageUrl;
public String uid;
public long imapUid;
public int size;
public String messageId;
public String date;
@ -950,16 +953,8 @@ public class ExchangeSession {
public boolean answered;
public boolean forwarded;
public long getUidAsLong() {
byte[] decodedValue = Base64.decode(uid.getBytes());
long result = 0;
for (int i = 5; i < 9; i++) {
result = result << 8;
result |= decodedValue[i] & 0xff;
}
return result;
public long getImapUid() {
return imapUid;
}
public String getImapFlags() {
@ -1070,7 +1065,7 @@ public class ExchangeSession {
}
public int compareTo(Object message) {
long compareValue = (getUidAsLong() - ((Message) message).getUidAsLong());
long compareValue = (getImapUid() - ((Message) message).getImapUid());
if (compareValue > 0) {
return 1;
} else if (compareValue < 0) {
@ -1082,7 +1077,7 @@ public class ExchangeSession {
@Override
public boolean equals(Object message) {
return message instanceof Message && getUidAsLong() == ((Message) message).getUidAsLong();
return message instanceof Message && getImapUid() == ((Message) message).getImapUid();
}
}
@ -1091,7 +1086,7 @@ public class ExchangeSession {
@Override
public boolean add(Message message) {
uidMessageMap.put(message.getUidAsLong(), message);
uidMessageMap.put(message.getImapUid(), message);
return super.add(message);
}

View File

@ -143,7 +143,7 @@ public class ImapConnection extends AbstractConnection {
if (messages.size() == 0) {
sendClient("* OK [UIDNEXT " + 1 + "]");
} else {
sendClient("* OK [UIDNEXT " + (messages.get(messages.size() - 1).getUidAsLong() + 1) + "]");
sendClient("* OK [UIDNEXT " + (messages.get(messages.size() - 1).getImapUid() + 1) + "]");
}
sendClient("* FLAGS (\\Answered \\Deleted \\Draft \\Flagged \\Seen $Forwarded Junk)");
sendClient("* OK [PERMANENTFLAGS (\\Answered \\Deleted \\Draft \\Flagged \\Seen $Forwarded Junk \\*)]");
@ -236,9 +236,9 @@ public class ImapConnection extends AbstractConnection {
if (((undeleted && !message.deleted) || !undeleted)
&& (conditions.flagged == null || message.flagged == conditions.flagged)
&& (conditions.answered == null || message.answered == conditions.answered)
&& (conditions.startUid == 0 || message.getUidAsLong() >= conditions.startUid)
&& (conditions.startUid == 0 || message.getImapUid() >= conditions.startUid)
) {
sendClient("* SEARCH " + message.getUidAsLong());
sendClient("* SEARCH " + message.getImapUid());
}
}
sendClient(commandId + " OK SEARCH completed");
@ -250,7 +250,7 @@ public class ImapConnection extends AbstractConnection {
while (UIDRangeIterator.hasNext()) {
ExchangeSession.Message message = UIDRangeIterator.next();
updateFlags(message, action, flags);
sendClient("* " + (UIDRangeIterator.currentIndex) + " FETCH (UID " + message.getUidAsLong() + " FLAGS (" + (message.getImapFlags()) + "))");
sendClient("* " + (UIDRangeIterator.currentIndex) + " FETCH (UID " + message.getImapUid() + " FLAGS (" + (message.getImapFlags()) + "))");
}
sendClient(commandId + " OK STORE completed");
} else if ("copy".equalsIgnoreCase(subcommand)) {
@ -387,7 +387,7 @@ public class ImapConnection extends AbstractConnection {
if (localMessages.size() == 0) {
answer.append("UIDNEXT 1 ");
} else {
answer.append("UIDNEXT ").append((localMessages.get(localMessages.size() - 1).getUidAsLong() + 1)).append(" ");
answer.append("UIDNEXT ").append((localMessages.get(localMessages.size() - 1).getImapUid() + 1)).append(" ");
}
}
@ -456,7 +456,7 @@ public class ImapConnection extends AbstractConnection {
private void handleFetch(ExchangeSession.Message message, int currentIndex, String parameters) throws IOException {
StringBuilder buffer = new StringBuilder();
buffer.append("* ").append(currentIndex).append(" FETCH (UID ").append(message.getUidAsLong());
buffer.append("* ").append(currentIndex).append(" FETCH (UID ").append(message.getImapUid());
boolean bodystructure = false;
StringTokenizer paramTokens = new StringTokenizer(parameters);
while (paramTokens.hasMoreTokens()) {
@ -693,7 +693,11 @@ public class ImapConnection extends AbstractConnection {
conditions.answered = Boolean.FALSE;
} else if ("HEADER".equals(token)) {
String headerName = tokens.nextToken().toLowerCase();
conditions.append(operator).append("\"urn:schemas:mailheader:").append(headerName).append("\"='").append(tokens.nextToken()).append("'");
String value = tokens.nextToken();
if ("message-id".equals(headerName)) {
value = "<"+value+">";
}
conditions.append(operator).append("\"urn:schemas:mailheader:").append(headerName).append("\"='").append(value).append("'");
} else if ("UID".equals(token)) {
String range = tokens.nextToken();
if ("1:*".equals(range)) {
@ -968,7 +972,7 @@ public class ImapConnection extends AbstractConnection {
} else {
startUid = endUid = convertToLong(currentRange);
}
while (currentIndex < messages.size() && messages.get(currentIndex).getUidAsLong() < startUid) {
while (currentIndex < messages.size() && messages.get(currentIndex).getImapUid() < startUid) {
currentIndex++;
}
} else {
@ -977,7 +981,7 @@ public class ImapConnection extends AbstractConnection {
}
public boolean hasNext() {
while (currentIndex < messages.size() && messages.get(currentIndex).getUidAsLong() > endUid) {
while (currentIndex < messages.size() && messages.get(currentIndex).getImapUid() > endUid) {
skipToStartUid();
}
return currentIndex < messages.size();
@ -985,7 +989,7 @@ public class ImapConnection extends AbstractConnection {
public ExchangeSession.Message next() {
ExchangeSession.Message message = messages.get(currentIndex++);
long uid = message.getUidAsLong();
long uid = message.getImapUid();
if (uid < startUid || uid > endUid) {
throw new RuntimeException("Message uid " + uid + " not in range " + startUid + ":" + endUid);
}