Download related attachment

pull/195/head
M66B 4 years ago
parent ba14cebb4b
commit cfbe4e0590

@ -1646,6 +1646,7 @@ class Core {
DB db = DB.getInstance(context);
long id = jargs.getLong(0);
Long related = (jargs.length() > 1 ? jargs.getLong(1) : null);
// Get attachment
EntityAttachment attachment = db.attachment().getAttachment(id);
@ -1668,7 +1669,7 @@ class Core {
MessageHelper.MessageParts parts = helper.getMessageParts();
// Download attachment
parts.downloadAttachment(context, attachment);
parts.downloadAttachment(context, attachment, related);
if (attachment.size != null)
EntityLog.log(context, "Operation attachment size=" + attachment.size);
@ -2414,7 +2415,7 @@ class Core {
for (EntityAttachment attachment : parts.getAttachments())
if (attachment.subsequence == null)
parts.downloadAttachment(context, attachment);
parts.downloadAttachment(context, attachment, null);
updateContactInfo(context, account, folder, message);
@ -3752,7 +3753,7 @@ class Core {
if (state.getNetworkState().isUnmetered() ||
(attachment.size != null && attachment.size < maxSize))
try {
parts.downloadAttachment(context, attachment);
parts.downloadAttachment(context, attachment, null);
if (stats != null && attachment.size != null)
stats.attachments += attachment.size;
} catch (Throwable ex) {

@ -6288,7 +6288,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
remote.sequence = index + 1;
remote.id = db.attachment().insertAttachment(remote);
try {
parts.downloadAttachment(context, index, remote);
parts.downloadAttachment(context, index, remote, null);
} catch (Throwable ex) {
Log.e(ex);
}
@ -6931,7 +6931,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
remote.sequence = index + 1;
remote.id = db.attachment().insertAttachment(remote);
try {
parts.downloadAttachment(context, index, remote);
parts.downloadAttachment(context, index, remote, null);
} catch (Throwable ex) {
Log.e(ex);
}

@ -2022,7 +2022,7 @@ public class MessageHelper {
return null;
}
void downloadAttachment(Context context, EntityAttachment local) throws IOException, MessagingException {
void downloadAttachment(Context context, EntityAttachment local, Long related) throws IOException, MessagingException {
List<EntityAttachment> remotes = getAttachments();
// Some servers order attachments randomly
@ -2084,13 +2084,13 @@ public class MessageHelper {
if (index < 0)
throw new IllegalArgumentException("Attachment not found");
downloadAttachment(context, index, local);
downloadAttachment(context, index, local, related);
if (Helper.isTnef(local.type, local.name))
decodeTNEF(context, local);
}
void downloadAttachment(Context context, int index, EntityAttachment local) throws MessagingException, IOException {
void downloadAttachment(Context context, int index, EntityAttachment local, Long related) throws MessagingException, IOException {
Log.i("downloading attachment id=" + local.id + " index=" + index + " " + local);
DB db = DB.getInstance(context);
@ -2101,6 +2101,8 @@ public class MessageHelper {
// Download attachment
File file = EntityAttachment.getFile(context, local.id, local.name);
db.attachment().setProgress(local.id, 0);
if (related != null)
db.attachment().setProgress(related, 0);
if (EntityAttachment.PGP_CONTENT.equals(apart.encrypt) ||
EntityAttachment.SMIME_CONTENT.equals(apart.encrypt)) {
@ -2141,7 +2143,10 @@ public class MessageHelper {
long now = System.currentTimeMillis();
if (now - lastprogress > ATTACHMENT_PROGRESS_UPDATE) {
lastprogress = now;
db.attachment().setProgress(local.id, (int) (size * 100 / total));
int progress = (int) (size * 100 / total);
db.attachment().setProgress(local.id, progress);
if (related != null)
db.attachment().setProgress(related, progress);
}
}
}
@ -2149,6 +2154,11 @@ public class MessageHelper {
// Store attachment data
db.attachment().setDownloaded(local.id, size);
if (related != null) {
File rel = EntityAttachment.getFile(context, related, local.name);
Helper.copy(file, rel);
db.attachment().setDownloaded(related, size);
}
Log.i("Downloaded attachment size=" + size);
} catch (FolderClosedIOException ex) {

Loading…
Cancel
Save