1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-15 14:05:05 -05:00

Mark messages as ANSWERED only on send. Save a reference to the message in the identity so that loading a draft of a reply also marks the referenced message correctly.

This commit is contained in:
Andrew Chen 2011-02-03 06:32:29 +00:00
parent 6c03c968ef
commit 33e5520a9d
2 changed files with 125 additions and 26 deletions

View File

@ -534,24 +534,15 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
Log.d(K9.LOG_TAG, "action = " + action + ", account = " + mMessageReference.accountUuid + ", folder = " + mMessageReference.folderName + ", sourceMessageUid = " + mMessageReference.uid);
*/
if (ACTION_REPLY.equals(action) ||
ACTION_REPLY_ALL.equals(action))
{
if (K9.DEBUG)
Log.d(K9.LOG_TAG, "Setting message ANSWERED flag to true");
// TODO: Really, we should wait until we send the message, but that would require saving the original
// message info along with a Draft copy, in case it is left in Drafts for a while before being sent
final Account account = Preferences.getPreferences(this).getAccount(mMessageReference.accountUuid);
final String folderName = mMessageReference.folderName;
final String sourceMessageUid = mMessageReference.uid;
MessagingController.getInstance(getApplication()).setFlag(account, folderName, new String[] { sourceMessageUid }, Flag.ANSWERED, true);
}
updateTitle();
}
if (ACTION_REPLY.equals(action) ||
ACTION_REPLY_ALL.equals(action))
{
mMessageReference.flag = Flag.ANSWERED;
}
if (ACTION_REPLY.equals(action) ||
ACTION_REPLY_ALL.equals(action) ||
ACTION_EDIT_DRAFT.equals(action))
@ -1245,6 +1236,10 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
}
}
// Version identifier for "new style" identity. ! is an impossible value in base64 encoding, so we
// use that to determine which version we're in.
private static final String IDENTITY_VERSION_1 = "!";
/**
* Build the identity header string. This string contains metadata about a draft message to be
* used upon loading a draft for composition. This should be generated at the time of saving a
@ -1284,9 +1279,12 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
uri.appendQueryParameter(IdentityField.EMAIL.value(), mIdentity.getEmail());
}
// Tag this is as a "new style" identity. ! is an impossible value in base64 encoding, so we
// use that to determine which version we're in.
String k9identity = "!" + uri.build().getEncodedQuery();
if (mMessageReference != null)
{
uri.appendQueryParameter(IdentityField.ORIGINAL_MESSAGE.value(), mMessageReference.toIdentityString());
}
String k9identity = IDENTITY_VERSION_1 + uri.build().getEncodedQuery();
if (K9.DEBUG)
{
@ -1313,7 +1311,8 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
return identity;
}
if (identityString.charAt(0) == '!' && identityString.length() > 2)
// Check to see if this is a "next gen" identity.
if (identityString.charAt(0) == IDENTITY_VERSION_1.charAt(0) && identityString.length() > 2)
{
Uri.Builder builder = new Uri.Builder();
builder.encodedQuery(identityString.substring(1)); // Need to cut off the ! at the beginning.
@ -1499,6 +1498,18 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
}
}
sendMessage();
if (mMessageReference.flag != null)
{
if (K9.DEBUG)
Log.d(K9.LOG_TAG, "Setting referenced message (" + mMessageReference.folderName + ", " + mMessageReference.uid + ") flag to " + mMessageReference.flag);
final Account account = Preferences.getPreferences(this).getAccount(mMessageReference.accountUuid);
final String folderName = mMessageReference.folderName;
final String sourceMessageUid = mMessageReference.uid;
MessagingController.getInstance(getApplication()).setFlag(account, folderName, new String[]{sourceMessageUid}, mMessageReference.flag, true);
}
mDraftNeedsSaving = false;
finish();
}
@ -2220,8 +2231,6 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
if (message.getHeader(K9.IDENTITY_HEADER) != null && message.getHeader(K9.IDENTITY_HEADER).length > 0 && message.getHeader(K9.IDENTITY_HEADER)[0] != null)
{
k9identity = parseIdentityHeader(message.getHeader(K9.IDENTITY_HEADER)[0]);
if(K9.DEBUG)
Log.d(K9.LOG_TAG, "Parsed identity: " + k9identity.toString());
}
Identity newIdentity = new Identity();
@ -2257,6 +2266,18 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
newIdentity.setEmail(mIdentity.getEmail());
}
if (k9identity.containsKey(IdentityField.ORIGINAL_MESSAGE))
{
mMessageReference = null;
try
{
mMessageReference = new MessageReference(k9identity.get(IdentityField.ORIGINAL_MESSAGE));
} catch (MessagingException e)
{
Log.e(K9.LOG_TAG, "Could not decode message reference in identity.", e);
}
}
mIdentity = newIdentity;
updateSignature();

View File

@ -1,6 +1,13 @@
package com.fsck.k9.activity;
import android.util.Log;
import com.fsck.k9.K9;
import com.fsck.k9.helper.Utility;
import com.fsck.k9.mail.Flag;
import com.fsck.k9.mail.MessagingException;
import java.io.Serializable;
import java.util.StringTokenizer;
public class MessageReference implements Serializable
{
@ -8,6 +15,76 @@ public class MessageReference implements Serializable
public String accountUuid;
public String folderName;
public String uid;
public Flag flag = null;
/**
* Initialize an empty MessageReference.
*/
public MessageReference()
{
}
// Version identifier for use when serializing. This will allow us to introduce future versions
// if we have to rev MessageReference.
private static final String IDENTITY_VERSION_1 = "!";
private static final String IDENTITY_SEPARATOR = ":";
/**
* Initialize a MessageReference from a seraialized identity.
* @param identity Serialized identity.
* @throws MessagingException On missing or corrupted identity.
*/
public MessageReference(final String identity) throws MessagingException
{
// Can't be null and must be at least length one so we can check the version.
if (identity == null || identity.length() < 1)
{
throw new MessagingException("Null or truncated MessageReference identity.");
}
// Version check.
if (identity.charAt(0) == IDENTITY_VERSION_1.charAt(0))
{
// Split the identity, stripping away the first two characters representing the version and delimiter.
StringTokenizer tokens = new StringTokenizer(identity.substring(2), IDENTITY_SEPARATOR, false);
if (tokens.countTokens() == 4)
{
accountUuid = Utility.base64Decode(tokens.nextToken());
folderName = Utility.base64Decode(tokens.nextToken());
uid = Utility.base64Decode(tokens.nextToken());
flag = Flag.valueOf(tokens.nextToken());
if (K9.DEBUG)
Log.d(K9.LOG_TAG, "Thawed " + toString());
}
else
{
throw new MessagingException("Invalid token in " + IDENTITY_SEPARATOR + " identity.");
}
}
}
/**
* Serialize this MessageReference for storing in a K9 identity. This is a colon-delimited base64 string.
*
* @return Serialized string.
*/
public String toIdentityString()
{
StringBuilder refString = new StringBuilder();
refString.append(IDENTITY_VERSION_1);
refString.append(IDENTITY_SEPARATOR);
refString.append(Utility.base64Encode(accountUuid));
refString.append(IDENTITY_SEPARATOR);
refString.append(Utility.base64Encode(folderName));
refString.append(IDENTITY_SEPARATOR);
refString.append(Utility.base64Encode(uid));
refString.append(IDENTITY_SEPARATOR);
refString.append(flag.name());
return refString.toString();
}
@Override
public boolean equals(Object o)
@ -41,10 +118,11 @@ public class MessageReference implements Serializable
@Override
public String toString()
{
return "MessageReference{accountUuid = '" +
accountUuid
+ "', folderName = '" + folderName
+ "', uid = '" + uid
+ "'}";
return "MessageReference{" +
"accountUuid='" + accountUuid + '\'' +
", folderName='" + folderName + '\'' +
", uid='" + uid + '\'' +
", flag=" + flag +
'}';
}
}