|
|
@ -633,7 +633,7 @@ public class MessageHelper {
|
|
|
|
return result;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void downloadAttachment(Context context, DB db, long id, int sequence) throws MessagingException, IOException {
|
|
|
|
void downloadAttachment(Context context, DB db, long id, int sequence) throws IOException {
|
|
|
|
// Attachments of drafts might not have been uploaded yet
|
|
|
|
// Attachments of drafts might not have been uploaded yet
|
|
|
|
if (sequence > attachments.size()) {
|
|
|
|
if (sequence > attachments.size()) {
|
|
|
|
Log.w("Attachment unavailable sequence=" + sequence + " size=" + attachments.size());
|
|
|
|
Log.w("Attachment unavailable sequence=" + sequence + " size=" + attachments.size());
|
|
|
@ -642,7 +642,6 @@ public class MessageHelper {
|
|
|
|
|
|
|
|
|
|
|
|
// Get data
|
|
|
|
// Get data
|
|
|
|
AttachmentPart apart = attachments.get(sequence - 1);
|
|
|
|
AttachmentPart apart = attachments.get(sequence - 1);
|
|
|
|
long total = apart.part.getSize();
|
|
|
|
|
|
|
|
File file = EntityAttachment.getFile(context, id);
|
|
|
|
File file = EntityAttachment.getFile(context, id);
|
|
|
|
|
|
|
|
|
|
|
|
// Download attachment
|
|
|
|
// Download attachment
|
|
|
@ -654,6 +653,7 @@ public class MessageHelper {
|
|
|
|
os = new BufferedOutputStream(new FileOutputStream(file));
|
|
|
|
os = new BufferedOutputStream(new FileOutputStream(file));
|
|
|
|
|
|
|
|
|
|
|
|
long size = 0;
|
|
|
|
long size = 0;
|
|
|
|
|
|
|
|
long total = apart.part.getSize();
|
|
|
|
byte[] buffer = new byte[ATTACHMENT_BUFFER_SIZE];
|
|
|
|
byte[] buffer = new byte[ATTACHMENT_BUFFER_SIZE];
|
|
|
|
for (int len = is.read(buffer); len != -1; len = is.read(buffer)) {
|
|
|
|
for (int len = is.read(buffer); len != -1; len = is.read(buffer)) {
|
|
|
|
size += len;
|
|
|
|
size += len;
|
|
|
@ -668,10 +668,10 @@ public class MessageHelper {
|
|
|
|
db.attachment().setDownloaded(id, size);
|
|
|
|
db.attachment().setDownloaded(id, size);
|
|
|
|
|
|
|
|
|
|
|
|
Log.i("Downloaded attachment size=" + size);
|
|
|
|
Log.i("Downloaded attachment size=" + size);
|
|
|
|
} catch (IOException ex) {
|
|
|
|
} catch (Throwable ex) {
|
|
|
|
|
|
|
|
Log.w(ex);
|
|
|
|
// Reset progress on failure
|
|
|
|
// Reset progress on failure
|
|
|
|
db.attachment().setProgress(id, null);
|
|
|
|
db.attachment().setError(id, Helper.formatThrowable(ex));
|
|
|
|
throw ex;
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
if (os != null)
|
|
|
|
if (os != null)
|
|
|
|
os.close();
|
|
|
|
os.close();
|
|
|
|