1
0
mirror of https://github.com/moparisthebest/k-9 synced 2025-01-10 13:18:09 -05:00

mark as read/unread should be working

This commit is contained in:
Vitaly Polonetsky 2011-07-16 12:13:52 +03:00 committed by Jesse Vincent
parent f5454b9584
commit b2d57b8fb8
2 changed files with 58 additions and 29 deletions

View File

@ -1061,7 +1061,7 @@ public class EasStore extends Store {
try {
EmailSyncAdapter target = getMessagesInternal(null, null, null, start, end);
List<Message> messages = target.getMessages();
List<EasMessage> messages = target.getMessages();
return messages.toArray(EMPTY_MESSAGE_ARRAY);
} catch (IOException e) {
@ -1280,7 +1280,7 @@ public class EasStore extends Store {
if (fetchBodySane || fetchBody) {
try {
EmailSyncAdapter target = getMessagesInternal(messages, fp, listener, -1, -1);
messages = target.getMessages().toArray(new Message[0]);
messages = target.getMessages().toArray(EMPTY_MESSAGE_ARRAY);
} catch (IOException e) {
throw new MessagingException("io exception while fetching messages", e);
}
@ -1323,20 +1323,50 @@ public class EasStore extends Store {
}
private void markServerMessagesRead(String[] uids, boolean read) throws MessagingException {
// String messageBody = "";
// HashMap<String, String> headers = new HashMap<String, String>();
// HashMap<String, String> uidToUrl = getMessageUrls(uids);
// String[] urls = new String[uids.length];
//
// for (int i = 0, count = uids.length; i < count; i++) {
// urls[i] = uidToUrl.get(uids[i]);
// }
//
//// messageBody = getMarkMessagesReadXml(urls, read);
// headers.put("Brief", "t");
// headers.put("If-Match", "*");
//
//// processRequest(this.mFolderUrl, "BPROPPATCH", messageBody, headers, false);
Serializer s = new Serializer();
EmailSyncAdapter target = new EmailSyncAdapter(this, mAccount);
try {
String className = target.getCollectionName();
String syncKey = target.getSyncKey();
s.start(Tags.SYNC_SYNC)
.start(Tags.SYNC_COLLECTIONS)
.start(Tags.SYNC_COLLECTION)
.data(Tags.SYNC_CLASS, className)
.data(Tags.SYNC_SYNC_KEY, syncKey)
.data(Tags.SYNC_COLLECTION_ID, mServerId);
// Start with the default timeout
int timeout = COMMAND_TIMEOUT;
s.start(Tags.SYNC_COMMANDS);
for (String serverId : uids) {
s.start(Tags.SYNC_CHANGE)
.data(Tags.SYNC_SERVER_ID, serverId)
.start(Tags.SYNC_APPLICATION_DATA)
.data(Tags.EMAIL_READ, read ? "1" : "0")
.end()
.end();
}
s.end();
s.end().end().end().done();
HttpResponse resp = sendHttpClientPost("Sync", new ByteArrayEntity(s.toByteArray()),
timeout);
int code = resp.getStatusLine().getStatusCode();
if (code == HttpStatus.SC_OK) {
InputStream is = resp.getEntity().getContent();
if (is != null) {
target.cleanup();
} else {
Log.d(K9.LOG_TAG, "Empty input stream in sync command response");
}
} else {
throw new MessagingException("not ok status");
}
} catch (IOException e) {
throw new MessagingException("could not set read flag", e);
}
}
private void deleteServerMessages(String[] uids) throws MessagingException {
@ -1431,8 +1461,8 @@ public class EasStore extends Store {
@Override
public void setFlag(Flag flag, boolean set) throws MessagingException {
// super.setFlag(flag, set);
// mFolder.setFlags(new Message[] { this }, new Flag[] { flag }, set);
super.setFlag(flag, set);
mFolder.setFlags(new Message[] { this }, new Flag[] { flag }, set);
}
}

View File

@ -33,7 +33,6 @@ import com.fsck.k9.mail.Message;
import com.fsck.k9.mail.MessagingException;
import com.fsck.k9.mail.Message.RecipientType;
import com.fsck.k9.mail.internet.MimeUtility;
import com.fsck.k9.mail.internet.TextBody;
import com.fsck.k9.mail.store.EasStore.EasFolder;
import com.fsck.k9.mail.store.EasStore.EasMessage;
import com.fsck.k9.mail.store.exchange.Eas;
@ -67,7 +66,7 @@ public class EmailSyncAdapter extends AbstractSyncAdapter {
// Holds the parser's value for isLooping()
boolean mIsLooping = false;
private List<Message> newEmails;
private List<EasMessage> newEmails;
public EmailSyncAdapter(EasFolder folder, Account account) {
super(folder, account);
@ -103,7 +102,7 @@ public class EmailSyncAdapter extends AbstractSyncAdapter {
// private String mMailboxIdAsString;
ArrayList<Message> newEmails = new ArrayList<Message>();
ArrayList<EasMessage> newEmails = new ArrayList<EasMessage>();
ArrayList<Long> deletedEmails = new ArrayList<Long>();
ArrayList<ServerChange> changedEmails = new ArrayList<ServerChange>();
@ -122,7 +121,7 @@ public class EmailSyncAdapter extends AbstractSyncAdapter {
// Message.MAILBOX_KEY + "=" + mMailbox.mId, null);
}
public void addData (Message msg) throws IOException, MessagingException {
public void addData (EasMessage msg) throws IOException, MessagingException {
// ArrayList<Attachment> atts = new ArrayList<Attachment>();
while (nextTag(Tags.SYNC_APPLICATION_DATA) != END) {
@ -156,13 +155,13 @@ public class EmailSyncAdapter extends AbstractSyncAdapter {
msg.setSubject(getValue());
break;
case Tags.EMAIL_READ:
msg.setFlag(Flag.SEEN, getValueInt() == 1);
msg.setFlagInternal(Flag.SEEN, getValueInt() == 1);
break;
case Tags.BASE_BODY:
bodyParser(msg);
break;
case Tags.EMAIL_FLAG:
msg.setFlag(Flag.FLAGGED, flagParser());
msg.setFlagInternal(Flag.FLAGGED, flagParser());
break;
case Tags.EMAIL_BODY:
String body = getValue();
@ -266,8 +265,8 @@ public class EmailSyncAdapter extends AbstractSyncAdapter {
}
}
private void addParser(ArrayList<Message> emails) throws IOException, MessagingException {
Message msg = new EasMessage(null, mFolder);
private void addParser(ArrayList<EasMessage> emails) throws IOException, MessagingException {
EasMessage msg = new EasMessage(null, mFolder);
// msg.mAccountKey = mAccount.mId;
// msg.mMailboxKey = mMailbox.mId;
// msg.mFlagLoaded = Message.FLAG_LOADED_COMPLETE;
@ -288,8 +287,8 @@ public class EmailSyncAdapter extends AbstractSyncAdapter {
emails.add(msg);
}
private void fetchParser(ArrayList<Message> emails) throws IOException, MessagingException {
Message msg = new EasMessage(null, mFolder);
private void fetchParser(ArrayList<EasMessage> emails) throws IOException, MessagingException {
EasMessage msg = new EasMessage(null, mFolder);
// msg.mAccountKey = mAccount.mId;
// msg.mMailboxKey = mMailbox.mId;
// msg.mFlagLoaded = Message.FLAG_LOADED_COMPLETE;
@ -900,7 +899,7 @@ public class EmailSyncAdapter extends AbstractSyncAdapter {
return false;
}
public List<Message> getMessages() {
public List<EasMessage> getMessages() {
return newEmails;
}
}