mirror of
https://github.com/M66B/FairEmail.git
synced 2025-02-25 15:32:52 +00:00
Refactoring
This commit is contained in:
parent
a2f664e979
commit
cdada06344
1 changed files with 24 additions and 23 deletions
|
@ -165,8 +165,7 @@ class Core {
|
||||||
throw new MessageRemovedException();
|
throw new MessageRemovedException();
|
||||||
} else {
|
} else {
|
||||||
db.message().setMessageError(message.id, null);
|
db.message().setMessageError(message.id, null);
|
||||||
if (!EntityOperation.ADD.equals(op.name))
|
ensureUid(context, folder, message, op, (IMAPFolder) ifolder);
|
||||||
ensureUid(context, folder, message, (IMAPFolder) ifolder);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Operations should use database transaction when needed
|
// Operations should use database transaction when needed
|
||||||
|
@ -310,32 +309,34 @@ class Core {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void ensureUid(Context context, EntityFolder folder, EntityMessage message, IMAPFolder ifolder) throws MessagingException {
|
private static void ensureUid(Context context, EntityFolder folder, EntityMessage message, EntityOperation op, IMAPFolder ifolder) throws MessagingException {
|
||||||
DB db = DB.getInstance(context);
|
if (message.uid != null)
|
||||||
|
return;
|
||||||
|
if (EntityOperation.ADD.equals(op.name))
|
||||||
|
return;
|
||||||
|
|
||||||
// Get uid when needed
|
Log.i(folder.name + " ensure uid op=" + op.name + " msgid=" + message.msgid);
|
||||||
if (message.uid == null) {
|
|
||||||
Log.i(folder.name + " ensure uid msgid=" + message.msgid);
|
|
||||||
|
|
||||||
if (TextUtils.isEmpty(message.msgid))
|
if (TextUtils.isEmpty(message.msgid))
|
||||||
throw new IllegalArgumentException("Message without ID");
|
throw new IllegalArgumentException("Message without ID for " + op.name);
|
||||||
|
|
||||||
Message[] imessages = ifolder.search(new MessageIDTerm(message.msgid));
|
Message[] imessages = ifolder.search(new MessageIDTerm(message.msgid));
|
||||||
if (imessages == null || imessages.length == 0)
|
if (imessages == null || imessages.length == 0)
|
||||||
throw new IllegalArgumentException("Message not found");
|
throw new IllegalArgumentException("Message not found for " + op.name);
|
||||||
|
|
||||||
long uid = -1;
|
long uid = -1;
|
||||||
for (Message iexisting : imessages) {
|
for (Message iexisting : imessages) {
|
||||||
long muid = ifolder.getUID(iexisting);
|
long muid = ifolder.getUID(iexisting);
|
||||||
Log.i(folder.name + " found uid=" + muid);
|
Log.i(folder.name + " found uid=" + muid);
|
||||||
// RFC3501: Unique identifiers are assigned in a strictly ascending fashion
|
// RFC3501: Unique identifiers are assigned in a strictly ascending fashion
|
||||||
if (muid > uid)
|
if (muid > uid)
|
||||||
uid = muid;
|
uid = muid;
|
||||||
}
|
|
||||||
|
|
||||||
message.uid = uid;
|
|
||||||
db.message().setMessageUid(message.id, uid);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
message.uid = uid;
|
||||||
|
|
||||||
|
DB db = DB.getInstance(context);
|
||||||
|
db.message().setMessageUid(message.id, uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void onSeen(Context context, JSONArray jargs, EntityFolder folder, EntityMessage message, IMAPFolder ifolder) throws MessagingException, JSONException {
|
private static void onSeen(Context context, JSONArray jargs, EntityFolder folder, EntityMessage message, IMAPFolder ifolder) throws MessagingException, JSONException {
|
||||||
|
|
Loading…
Reference in a new issue