1
0
mirror of https://github.com/moparisthebest/k-9 synced 2025-01-10 21:28:14 -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 { try {
EmailSyncAdapter target = getMessagesInternal(null, null, null, start, end); EmailSyncAdapter target = getMessagesInternal(null, null, null, start, end);
List<Message> messages = target.getMessages(); List<EasMessage> messages = target.getMessages();
return messages.toArray(EMPTY_MESSAGE_ARRAY); return messages.toArray(EMPTY_MESSAGE_ARRAY);
} catch (IOException e) { } catch (IOException e) {
@ -1280,7 +1280,7 @@ public class EasStore extends Store {
if (fetchBodySane || fetchBody) { if (fetchBodySane || fetchBody) {
try { try {
EmailSyncAdapter target = getMessagesInternal(messages, fp, listener, -1, -1); 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) { } catch (IOException e) {
throw new MessagingException("io exception while fetching messages", 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 { private void markServerMessagesRead(String[] uids, boolean read) throws MessagingException {
// String messageBody = ""; Serializer s = new Serializer();
// HashMap<String, String> headers = new HashMap<String, String>(); EmailSyncAdapter target = new EmailSyncAdapter(this, mAccount);
// HashMap<String, String> uidToUrl = getMessageUrls(uids);
// String[] urls = new String[uids.length]; try {
// String className = target.getCollectionName();
// for (int i = 0, count = uids.length; i < count; i++) { String syncKey = target.getSyncKey();
// urls[i] = uidToUrl.get(uids[i]); s.start(Tags.SYNC_SYNC)
// } .start(Tags.SYNC_COLLECTIONS)
// .start(Tags.SYNC_COLLECTION)
//// messageBody = getMarkMessagesReadXml(urls, read); .data(Tags.SYNC_CLASS, className)
// headers.put("Brief", "t"); .data(Tags.SYNC_SYNC_KEY, syncKey)
// headers.put("If-Match", "*"); .data(Tags.SYNC_COLLECTION_ID, mServerId);
//
//// processRequest(this.mFolderUrl, "BPROPPATCH", messageBody, headers, false); // 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 { private void deleteServerMessages(String[] uids) throws MessagingException {
@ -1431,8 +1461,8 @@ public class EasStore extends Store {
@Override @Override
public void setFlag(Flag flag, boolean set) throws MessagingException { public void setFlag(Flag flag, boolean set) throws MessagingException {
// super.setFlag(flag, set); super.setFlag(flag, set);
// mFolder.setFlags(new Message[] { this }, new Flag[] { 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.MessagingException;
import com.fsck.k9.mail.Message.RecipientType; import com.fsck.k9.mail.Message.RecipientType;
import com.fsck.k9.mail.internet.MimeUtility; 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.EasFolder;
import com.fsck.k9.mail.store.EasStore.EasMessage; import com.fsck.k9.mail.store.EasStore.EasMessage;
import com.fsck.k9.mail.store.exchange.Eas; import com.fsck.k9.mail.store.exchange.Eas;
@ -67,7 +66,7 @@ public class EmailSyncAdapter extends AbstractSyncAdapter {
// Holds the parser's value for isLooping() // Holds the parser's value for isLooping()
boolean mIsLooping = false; boolean mIsLooping = false;
private List<Message> newEmails; private List<EasMessage> newEmails;
public EmailSyncAdapter(EasFolder folder, Account account) { public EmailSyncAdapter(EasFolder folder, Account account) {
super(folder, account); super(folder, account);
@ -103,7 +102,7 @@ public class EmailSyncAdapter extends AbstractSyncAdapter {
// private String mMailboxIdAsString; // private String mMailboxIdAsString;
ArrayList<Message> newEmails = new ArrayList<Message>(); ArrayList<EasMessage> newEmails = new ArrayList<EasMessage>();
ArrayList<Long> deletedEmails = new ArrayList<Long>(); ArrayList<Long> deletedEmails = new ArrayList<Long>();
ArrayList<ServerChange> changedEmails = new ArrayList<ServerChange>(); ArrayList<ServerChange> changedEmails = new ArrayList<ServerChange>();
@ -122,7 +121,7 @@ public class EmailSyncAdapter extends AbstractSyncAdapter {
// Message.MAILBOX_KEY + "=" + mMailbox.mId, null); // 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>(); // ArrayList<Attachment> atts = new ArrayList<Attachment>();
while (nextTag(Tags.SYNC_APPLICATION_DATA) != END) { while (nextTag(Tags.SYNC_APPLICATION_DATA) != END) {
@ -156,13 +155,13 @@ public class EmailSyncAdapter extends AbstractSyncAdapter {
msg.setSubject(getValue()); msg.setSubject(getValue());
break; break;
case Tags.EMAIL_READ: case Tags.EMAIL_READ:
msg.setFlag(Flag.SEEN, getValueInt() == 1); msg.setFlagInternal(Flag.SEEN, getValueInt() == 1);
break; break;
case Tags.BASE_BODY: case Tags.BASE_BODY:
bodyParser(msg); bodyParser(msg);
break; break;
case Tags.EMAIL_FLAG: case Tags.EMAIL_FLAG:
msg.setFlag(Flag.FLAGGED, flagParser()); msg.setFlagInternal(Flag.FLAGGED, flagParser());
break; break;
case Tags.EMAIL_BODY: case Tags.EMAIL_BODY:
String body = getValue(); String body = getValue();
@ -266,8 +265,8 @@ public class EmailSyncAdapter extends AbstractSyncAdapter {
} }
} }
private void addParser(ArrayList<Message> emails) throws IOException, MessagingException { private void addParser(ArrayList<EasMessage> emails) throws IOException, MessagingException {
Message msg = new EasMessage(null, mFolder); EasMessage msg = new EasMessage(null, mFolder);
// msg.mAccountKey = mAccount.mId; // msg.mAccountKey = mAccount.mId;
// msg.mMailboxKey = mMailbox.mId; // msg.mMailboxKey = mMailbox.mId;
// msg.mFlagLoaded = Message.FLAG_LOADED_COMPLETE; // msg.mFlagLoaded = Message.FLAG_LOADED_COMPLETE;
@ -288,8 +287,8 @@ public class EmailSyncAdapter extends AbstractSyncAdapter {
emails.add(msg); emails.add(msg);
} }
private void fetchParser(ArrayList<Message> emails) throws IOException, MessagingException { private void fetchParser(ArrayList<EasMessage> emails) throws IOException, MessagingException {
Message msg = new EasMessage(null, mFolder); EasMessage msg = new EasMessage(null, mFolder);
// msg.mAccountKey = mAccount.mId; // msg.mAccountKey = mAccount.mId;
// msg.mMailboxKey = mMailbox.mId; // msg.mMailboxKey = mMailbox.mId;
// msg.mFlagLoaded = Message.FLAG_LOADED_COMPLETE; // msg.mFlagLoaded = Message.FLAG_LOADED_COMPLETE;
@ -900,7 +899,7 @@ public class EmailSyncAdapter extends AbstractSyncAdapter {
return false; return false;
} }
public List<Message> getMessages() { public List<EasMessage> getMessages() {
return newEmails; return newEmails;
} }
} }