mirror of https://github.com/M66B/FairEmail.git
Download related attachment
This commit is contained in:
parent
ba14cebb4b
commit
cfbe4e0590
|
@ -1646,6 +1646,7 @@ class Core {
|
||||||
DB db = DB.getInstance(context);
|
DB db = DB.getInstance(context);
|
||||||
|
|
||||||
long id = jargs.getLong(0);
|
long id = jargs.getLong(0);
|
||||||
|
Long related = (jargs.length() > 1 ? jargs.getLong(1) : null);
|
||||||
|
|
||||||
// Get attachment
|
// Get attachment
|
||||||
EntityAttachment attachment = db.attachment().getAttachment(id);
|
EntityAttachment attachment = db.attachment().getAttachment(id);
|
||||||
|
@ -1668,7 +1669,7 @@ class Core {
|
||||||
MessageHelper.MessageParts parts = helper.getMessageParts();
|
MessageHelper.MessageParts parts = helper.getMessageParts();
|
||||||
|
|
||||||
// Download attachment
|
// Download attachment
|
||||||
parts.downloadAttachment(context, attachment);
|
parts.downloadAttachment(context, attachment, related);
|
||||||
|
|
||||||
if (attachment.size != null)
|
if (attachment.size != null)
|
||||||
EntityLog.log(context, "Operation attachment size=" + attachment.size);
|
EntityLog.log(context, "Operation attachment size=" + attachment.size);
|
||||||
|
@ -2414,7 +2415,7 @@ class Core {
|
||||||
|
|
||||||
for (EntityAttachment attachment : parts.getAttachments())
|
for (EntityAttachment attachment : parts.getAttachments())
|
||||||
if (attachment.subsequence == null)
|
if (attachment.subsequence == null)
|
||||||
parts.downloadAttachment(context, attachment);
|
parts.downloadAttachment(context, attachment, null);
|
||||||
|
|
||||||
|
|
||||||
updateContactInfo(context, account, folder, message);
|
updateContactInfo(context, account, folder, message);
|
||||||
|
@ -3752,7 +3753,7 @@ class Core {
|
||||||
if (state.getNetworkState().isUnmetered() ||
|
if (state.getNetworkState().isUnmetered() ||
|
||||||
(attachment.size != null && attachment.size < maxSize))
|
(attachment.size != null && attachment.size < maxSize))
|
||||||
try {
|
try {
|
||||||
parts.downloadAttachment(context, attachment);
|
parts.downloadAttachment(context, attachment, null);
|
||||||
if (stats != null && attachment.size != null)
|
if (stats != null && attachment.size != null)
|
||||||
stats.attachments += attachment.size;
|
stats.attachments += attachment.size;
|
||||||
} catch (Throwable ex) {
|
} catch (Throwable ex) {
|
||||||
|
|
|
@ -6288,7 +6288,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
|
||||||
remote.sequence = index + 1;
|
remote.sequence = index + 1;
|
||||||
remote.id = db.attachment().insertAttachment(remote);
|
remote.id = db.attachment().insertAttachment(remote);
|
||||||
try {
|
try {
|
||||||
parts.downloadAttachment(context, index, remote);
|
parts.downloadAttachment(context, index, remote, null);
|
||||||
} catch (Throwable ex) {
|
} catch (Throwable ex) {
|
||||||
Log.e(ex);
|
Log.e(ex);
|
||||||
}
|
}
|
||||||
|
@ -6931,7 +6931,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
|
||||||
remote.sequence = index + 1;
|
remote.sequence = index + 1;
|
||||||
remote.id = db.attachment().insertAttachment(remote);
|
remote.id = db.attachment().insertAttachment(remote);
|
||||||
try {
|
try {
|
||||||
parts.downloadAttachment(context, index, remote);
|
parts.downloadAttachment(context, index, remote, null);
|
||||||
} catch (Throwable ex) {
|
} catch (Throwable ex) {
|
||||||
Log.e(ex);
|
Log.e(ex);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2022,7 +2022,7 @@ public class MessageHelper {
|
||||||
return null;
|
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();
|
List<EntityAttachment> remotes = getAttachments();
|
||||||
|
|
||||||
// Some servers order attachments randomly
|
// Some servers order attachments randomly
|
||||||
|
@ -2084,13 +2084,13 @@ public class MessageHelper {
|
||||||
if (index < 0)
|
if (index < 0)
|
||||||
throw new IllegalArgumentException("Attachment not found");
|
throw new IllegalArgumentException("Attachment not found");
|
||||||
|
|
||||||
downloadAttachment(context, index, local);
|
downloadAttachment(context, index, local, related);
|
||||||
|
|
||||||
if (Helper.isTnef(local.type, local.name))
|
if (Helper.isTnef(local.type, local.name))
|
||||||
decodeTNEF(context, local);
|
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);
|
Log.i("downloading attachment id=" + local.id + " index=" + index + " " + local);
|
||||||
|
|
||||||
DB db = DB.getInstance(context);
|
DB db = DB.getInstance(context);
|
||||||
|
@ -2101,6 +2101,8 @@ public class MessageHelper {
|
||||||
// Download attachment
|
// Download attachment
|
||||||
File file = EntityAttachment.getFile(context, local.id, local.name);
|
File file = EntityAttachment.getFile(context, local.id, local.name);
|
||||||
db.attachment().setProgress(local.id, 0);
|
db.attachment().setProgress(local.id, 0);
|
||||||
|
if (related != null)
|
||||||
|
db.attachment().setProgress(related, 0);
|
||||||
|
|
||||||
if (EntityAttachment.PGP_CONTENT.equals(apart.encrypt) ||
|
if (EntityAttachment.PGP_CONTENT.equals(apart.encrypt) ||
|
||||||
EntityAttachment.SMIME_CONTENT.equals(apart.encrypt)) {
|
EntityAttachment.SMIME_CONTENT.equals(apart.encrypt)) {
|
||||||
|
@ -2141,7 +2143,10 @@ public class MessageHelper {
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
if (now - lastprogress > ATTACHMENT_PROGRESS_UPDATE) {
|
if (now - lastprogress > ATTACHMENT_PROGRESS_UPDATE) {
|
||||||
lastprogress = now;
|
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
|
// Store attachment data
|
||||||
db.attachment().setDownloaded(local.id, size);
|
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);
|
Log.i("Downloaded attachment size=" + size);
|
||||||
} catch (FolderClosedIOException ex) {
|
} catch (FolderClosedIOException ex) {
|
||||||
|
|
Loading…
Reference in New Issue