1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-08-13 17:03:48 -04:00

MessageReference is now immutable

This commit is contained in:
Valentin CAULIER 2015-03-21 11:02:15 +01:00
parent 3e84c20c9b
commit 13f6b42250

View File

@ -17,10 +17,10 @@ import com.fsck.k9.mail.filter.Base64;
import java.util.StringTokenizer; import java.util.StringTokenizer;
public class MessageReference implements Parcelable { public class MessageReference implements Parcelable {
public String accountUuid; protected final String accountUuid;
public String folderName; protected final String folderName;
public String uid; protected final String uid;
public Flag flag; protected final Flag flag;
/** /**
* @deprecated MessageReference should be immutable now, and this way, it won't be possible to modify it anymore * @deprecated MessageReference should be immutable now, and this way, it won't be possible to modify it anymore
@ -60,7 +60,11 @@ public class MessageReference implements Parcelable {
if (identity == null || identity.length() < 1) { if (identity == null || identity.length() < 1) {
throw new MessagingException("Null or truncated MessageReference identity."); throw new MessagingException("Null or truncated MessageReference identity.");
} }
// Some temp variables
String accountUuid = null;
String folderName = null;
String uid = null;
Flag flag = null;
// Version check. // Version check.
if (identity.charAt(0) == IDENTITY_VERSION_1.charAt(0)) { if (identity.charAt(0) == IDENTITY_VERSION_1.charAt(0)) {
// Split the identity, stripping away the first two characters representing the version and delimiter. // Split the identity, stripping away the first two characters representing the version and delimiter.
@ -78,9 +82,6 @@ public class MessageReference implements Parcelable {
throw new MessagingException("Could not thaw message flag '" + flagString + "'", ie); throw new MessagingException("Could not thaw message flag '" + flagString + "'", ie);
} }
} }
else {
flag = null;
}
if (K9.DEBUG) if (K9.DEBUG)
Log.d(K9.LOG_TAG, "Thawed " + toString()); Log.d(K9.LOG_TAG, "Thawed " + toString());
@ -88,6 +89,10 @@ public class MessageReference implements Parcelable {
throw new MessagingException("Invalid MessageReference in " + identity + " identity."); throw new MessagingException("Invalid MessageReference in " + identity + " identity.");
} }
} }
this.accountUuid = accountUuid;
this.folderName = folderName;
this.uid = uid;
this.flag = flag;
} }
/** /**
@ -221,6 +226,10 @@ public class MessageReference implements Parcelable {
return uid; return uid;
} }
public Flag getFlag(){
return flag;
}
public MessageReference withModifiedUid(String newUid){ public MessageReference withModifiedUid(String newUid){
return new MessageReference(accountUuid, folderName, newUid, flag); return new MessageReference(accountUuid, folderName, newUid, flag);
} }
@ -228,8 +237,4 @@ public class MessageReference implements Parcelable {
public MessageReference withModifiedFlag(Flag newFlag){ public MessageReference withModifiedFlag(Flag newFlag){
return new MessageReference(accountUuid, folderName, uid, newFlag); return new MessageReference(accountUuid, folderName, uid, newFlag);
} }
public Flag getFlag(){
return flag;
}
} }