mirror of
https://github.com/M66B/FairEmail.git
synced 2025-02-22 22:21:18 +00:00
Added download operation for fast fetch
This commit is contained in:
parent
e0f76f699e
commit
55f589bea7
3 changed files with 34 additions and 4 deletions
|
@ -297,6 +297,15 @@ class Core {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case EntityOperation.DOWNLOAD:
|
||||||
|
if (EntityOperation.DOWNLOAD.equals(next.name)) {
|
||||||
|
JSONArray jnext = new JSONArray(next.args);
|
||||||
|
// Same uid
|
||||||
|
if (jargs.getLong(0) == jnext.getLong(0))
|
||||||
|
skip = true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case EntityOperation.MOVE:
|
case EntityOperation.MOVE:
|
||||||
if (group &&
|
if (group &&
|
||||||
message.uid != null &&
|
message.uid != null &&
|
||||||
|
@ -540,6 +549,10 @@ class Core {
|
||||||
onRule(context, jargs, message);
|
onRule(context, jargs, message);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case EntityOperation.DOWNLOAD:
|
||||||
|
onDownload(context, jargs, account, folder, message, (IMAPStore) istore, (IMAPFolder) ifolder, state);
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw new IllegalArgumentException("Unknown operation=" + op.name);
|
throw new IllegalArgumentException("Unknown operation=" + op.name);
|
||||||
}
|
}
|
||||||
|
@ -1785,6 +1798,8 @@ class Core {
|
||||||
if (download) {
|
if (download) {
|
||||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||||
boolean fast_fetch = prefs.getBoolean("fast_fetch", false);
|
boolean fast_fetch = prefs.getBoolean("fast_fetch", false);
|
||||||
|
|
||||||
|
boolean async = false;
|
||||||
if (fast_fetch) {
|
if (fast_fetch) {
|
||||||
long maxSize = prefs.getInt("download", MessageHelper.DEFAULT_DOWNLOAD_SIZE);
|
long maxSize = prefs.getInt("download", MessageHelper.DEFAULT_DOWNLOAD_SIZE);
|
||||||
if (maxSize == 0)
|
if (maxSize == 0)
|
||||||
|
@ -1793,19 +1808,23 @@ class Core {
|
||||||
|
|
||||||
if (!message.content)
|
if (!message.content)
|
||||||
if (state.getNetworkState().isUnmetered() || (message.size != null && message.size < maxSize))
|
if (state.getNetworkState().isUnmetered() || (message.size != null && message.size < maxSize))
|
||||||
EntityOperation.queue(context, message, EntityOperation.BODY);
|
async = true;
|
||||||
|
|
||||||
List<EntityAttachment> attachments = db.attachment().getAttachments(message.id);
|
List<EntityAttachment> attachments = db.attachment().getAttachments(message.id);
|
||||||
for (EntityAttachment attachment : attachments)
|
for (EntityAttachment attachment : attachments)
|
||||||
if (!attachment.available)
|
if (!attachment.available)
|
||||||
if (state.getNetworkState().isUnmetered() || (attachment.size != null && attachment.size < maxSize))
|
if (state.getNetworkState().isUnmetered() || (attachment.size != null && attachment.size < maxSize))
|
||||||
EntityOperation.queue(context, message, EntityOperation.ATTACHMENT, attachment.id);
|
async = true;
|
||||||
|
|
||||||
if (download_eml &&
|
if (download_eml &&
|
||||||
(message.raw == null || !message.raw) &&
|
(message.raw == null || !message.raw) &&
|
||||||
(state.getNetworkState().isUnmetered() || (message.total != null && message.total < maxSize)))
|
(state.getNetworkState().isUnmetered() || (message.total != null && message.total < maxSize)))
|
||||||
EntityOperation.queue(context, message, EntityOperation.RAW);
|
async = true;
|
||||||
} else
|
}
|
||||||
|
|
||||||
|
if (async && message.uid != null)
|
||||||
|
EntityOperation.queue(context, message, EntityOperation.DOWNLOAD, message.uid);
|
||||||
|
else
|
||||||
downloadMessage(context, account, folder, istore, ifolder, imessage, message.id, state, stats);
|
downloadMessage(context, account, folder, istore, ifolder, imessage, message.id, state, stats);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2933,6 +2952,15 @@ class Core {
|
||||||
rule.execute(context, message);
|
rule.execute(context, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void onDownload(Context context, JSONArray jargs, EntityAccount account, EntityFolder folder, EntityMessage message, IMAPStore istore, IMAPFolder ifolder, State state) throws MessagingException, IOException, JSONException {
|
||||||
|
long uid = jargs.getLong(0);
|
||||||
|
if (!Objects.equals(uid, message.uid))
|
||||||
|
throw new IllegalArgumentException("Different uid" + uid + "/" + message.uid);
|
||||||
|
|
||||||
|
MimeMessage imessage = (MimeMessage) ifolder.getMessageByUID(uid);
|
||||||
|
downloadMessage(context, account, folder, istore, ifolder, imessage, message.id, state, new SyncStats());
|
||||||
|
}
|
||||||
|
|
||||||
private static void onSynchronizeMessages(
|
private static void onSynchronizeMessages(
|
||||||
Context context, JSONArray jargs,
|
Context context, JSONArray jargs,
|
||||||
EntityAccount account, final EntityFolder folder,
|
EntityAccount account, final EntityFolder folder,
|
||||||
|
|
|
@ -40,6 +40,7 @@ public interface DaoOperation {
|
||||||
// Other operations: seen, answered, flag, keyword, label, subscribe, send, rule
|
// Other operations: seen, answered, flag, keyword, label, subscribe, send, rule
|
||||||
" WHEN operation.name = '" + EntityOperation.SYNC + "' AND folder.account IS NOT NULL THEN 1" +
|
" WHEN operation.name = '" + EntityOperation.SYNC + "' AND folder.account IS NOT NULL THEN 1" +
|
||||||
" WHEN operation.name = '" + EntityOperation.FETCH + "' THEN 2" +
|
" WHEN operation.name = '" + EntityOperation.FETCH + "' THEN 2" +
|
||||||
|
" WHEN operation.name = '" + EntityOperation.DOWNLOAD + "' THEN 3" +
|
||||||
" WHEN operation.name = '" + EntityOperation.EXISTS + "' THEN 3" +
|
" WHEN operation.name = '" + EntityOperation.EXISTS + "' THEN 3" +
|
||||||
" WHEN operation.name = '" + EntityOperation.REPORT + "' THEN 3" +
|
" WHEN operation.name = '" + EntityOperation.REPORT + "' THEN 3" +
|
||||||
" WHEN operation.name = '" + EntityOperation.COPY + "' THEN 4" +
|
" WHEN operation.name = '" + EntityOperation.COPY + "' THEN 4" +
|
||||||
|
|
|
@ -103,6 +103,7 @@ public class EntityOperation {
|
||||||
static final String PURGE = "purge";
|
static final String PURGE = "purge";
|
||||||
static final String EXPUNGE = "expunge";
|
static final String EXPUNGE = "expunge";
|
||||||
static final String REPORT = "report";
|
static final String REPORT = "report";
|
||||||
|
static final String DOWNLOAD = "download";
|
||||||
|
|
||||||
private static final int MAX_FETCH = 100; // operations
|
private static final int MAX_FETCH = 100; // operations
|
||||||
private static final long FORCE_WITHIN = 30 * 1000; // milliseconds
|
private static final long FORCE_WITHIN = 30 * 1000; // milliseconds
|
||||||
|
|
Loading…
Reference in a new issue