mirror of
https://github.com/M66B/FairEmail.git
synced 2025-01-01 04:35:57 +00:00
Download content outside of transaction
This commit is contained in:
parent
208db65caa
commit
3e15a0594c
8 changed files with 18 additions and 37 deletions
|
@ -1477,7 +1477,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
|
|||
body = Helper.readText(EntityMessage.getFile(context, message.id));
|
||||
} catch (IOException ex) {
|
||||
Log.e(ex);
|
||||
db.message().setMessageContent(message.id, false, null);
|
||||
db.message().setMessageContent(message.id, false, null, null);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -629,10 +629,9 @@ class Core {
|
|||
MessageHelper helper = new MessageHelper((MimeMessage) imessage);
|
||||
MessageHelper.MessageParts parts = helper.getMessageParts();
|
||||
String body = parts.getHtml(context);
|
||||
String preview = HtmlHelper.getPreview(body);
|
||||
Helper.writeText(EntityMessage.getFile(context, message.id), body);
|
||||
db.message().setMessageContent(message.id, true, preview);
|
||||
db.message().setMessageWarning(message.id, parts.getWarnings(message.warning));
|
||||
db.message().setMessageContent(message.id, true,
|
||||
HtmlHelper.getPreview(body), parts.getWarnings(message.warning));
|
||||
}
|
||||
|
||||
private static void onAttachment(Context context, JSONArray jargs, EntityFolder folder, EntityMessage message, EntityOperation op, IMAPFolder ifolder) throws JSONException, MessagingException, IOException {
|
||||
|
@ -1001,13 +1000,11 @@ class Core {
|
|||
|
||||
for (int j = isub.length - 1; j >= 0 && state.running(); j--)
|
||||
try {
|
||||
db.beginTransaction();
|
||||
if (ids[from + j] != null)
|
||||
downloadMessage(
|
||||
context,
|
||||
folder, ifolder,
|
||||
(IMAPMessage) isub[j], ids[from + j]);
|
||||
db.setTransactionSuccessful();
|
||||
} catch (FolderClosedException ex) {
|
||||
throw ex;
|
||||
} catch (FolderClosedIOException ex) {
|
||||
|
@ -1015,7 +1012,6 @@ class Core {
|
|||
} catch (Throwable ex) {
|
||||
Log.e(folder.name, ex);
|
||||
} finally {
|
||||
db.endTransaction();
|
||||
// Free memory
|
||||
((IMAPMessage) isub[j]).invalidateHeaders();
|
||||
}
|
||||
|
@ -1379,8 +1375,8 @@ class Core {
|
|||
if (!metered || (message.size != null && message.size < maxSize)) {
|
||||
String body = parts.getHtml(context);
|
||||
Helper.writeText(EntityMessage.getFile(context, message.id), body);
|
||||
db.message().setMessageContent(message.id, true, HtmlHelper.getPreview(body));
|
||||
db.message().setMessageWarning(message.id, parts.getWarnings(message.warning));
|
||||
db.message().setMessageContent(message.id, true,
|
||||
HtmlHelper.getPreview(body), parts.getWarnings(message.warning));
|
||||
Log.i(folder.name + " downloaded message id=" + message.id + " size=" + message.size);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -304,14 +304,11 @@ public interface DaoMessage {
|
|||
@Query("UPDATE message SET sent = :sent WHERE id = :id")
|
||||
int setMessageSent(long id, Long sent);
|
||||
|
||||
@Query("UPDATE message SET warning = :warning WHERE id = :id")
|
||||
int setMessageWarning(long id, String warning);
|
||||
|
||||
@Query("UPDATE message SET error = :error WHERE id = :id")
|
||||
int setMessageError(long id, String error);
|
||||
|
||||
@Query("UPDATE message SET content = :content, preview = :preview WHERE id = :id")
|
||||
int setMessageContent(long id, boolean content, String preview);
|
||||
@Query("UPDATE message SET content = :content, preview = :preview, warning = :warning WHERE id = :id")
|
||||
int setMessageContent(long id, boolean content, String preview, String warning);
|
||||
|
||||
@Query("UPDATE message SET headers = :headers WHERE id = :id")
|
||||
int setMessageHeaders(long id, String headers);
|
||||
|
|
|
@ -165,7 +165,7 @@ public class EntityOperation {
|
|||
EntityMessage.getFile(context, newid));
|
||||
} catch (IOException ex) {
|
||||
Log.e(ex);
|
||||
db.message().setMessageContent(newid, false, null);
|
||||
db.message().setMessageContent(newid, false, null, null);
|
||||
}
|
||||
|
||||
EntityAttachment.copy(context, db, message.id, newid);
|
||||
|
|
|
@ -221,7 +221,7 @@ public class EntityRule {
|
|||
reply.received = new Date().getTime();
|
||||
reply.id = db.message().insertMessage(reply);
|
||||
Helper.writeText(EntityMessage.getFile(context, reply.id), body);
|
||||
db.message().setMessageContent(reply.id, true, HtmlHelper.getPreview(body));
|
||||
db.message().setMessageContent(reply.id, true, HtmlHelper.getPreview(body), null);
|
||||
|
||||
EntityOperation.queue(context, db, reply, EntityOperation.SEND);
|
||||
}
|
||||
|
|
|
@ -1671,7 +1671,7 @@ public class FragmentCompose extends FragmentBase {
|
|||
draft.id = db.message().insertMessage(draft);
|
||||
Helper.writeText(EntityMessage.getFile(context, draft.id), body);
|
||||
|
||||
db.message().setMessageContent(draft.id, true, HtmlHelper.getPreview(body));
|
||||
db.message().setMessageContent(draft.id, true, HtmlHelper.getPreview(body), null);
|
||||
|
||||
// Write reference text
|
||||
if (ref != null && ref.content) {
|
||||
|
@ -2020,7 +2020,7 @@ public class FragmentCompose extends FragmentBase {
|
|||
draft.received = new Date().getTime();
|
||||
db.message().updateMessage(draft);
|
||||
Helper.writeText(EntityMessage.getFile(context, draft.id), body);
|
||||
db.message().setMessageContent(draft.id, true, HtmlHelper.getPreview(body));
|
||||
db.message().setMessageContent(draft.id, true, HtmlHelper.getPreview(body), null);
|
||||
}
|
||||
|
||||
// Remove unused inline images
|
||||
|
|
|
@ -412,7 +412,7 @@ public class Helper {
|
|||
draft.received = new Date().getTime();
|
||||
draft.id = db.message().insertMessage(draft);
|
||||
writeText(EntityMessage.getFile(context, draft.id), body);
|
||||
db.message().setMessageContent(draft.id, true, HtmlHelper.getPreview(body));
|
||||
db.message().setMessageContent(draft.id, true, HtmlHelper.getPreview(body), null);
|
||||
|
||||
attachSettings(context, draft.id, 1);
|
||||
attachNetworkInfo(context, draft.id, 2);
|
||||
|
|
|
@ -435,15 +435,9 @@ public class ServiceSynchronize extends LifecycleService {
|
|||
}
|
||||
|
||||
if (db.folder().getFolderDownload(folder.id))
|
||||
try {
|
||||
db.beginTransaction();
|
||||
Core.downloadMessage(ServiceSynchronize.this,
|
||||
folder, (IMAPFolder) ifolder,
|
||||
(IMAPMessage) imessage, message.id);
|
||||
db.setTransactionSuccessful();
|
||||
} finally {
|
||||
db.endTransaction();
|
||||
}
|
||||
Core.downloadMessage(ServiceSynchronize.this,
|
||||
folder, (IMAPFolder) ifolder,
|
||||
(IMAPMessage) imessage, message.id);
|
||||
} catch (MessageRemovedException ex) {
|
||||
Log.w(folder.name, ex);
|
||||
} catch (FolderClosedException ex) {
|
||||
|
@ -524,15 +518,9 @@ public class ServiceSynchronize extends LifecycleService {
|
|||
}
|
||||
|
||||
if (db.folder().getFolderDownload(folder.id))
|
||||
try {
|
||||
db.beginTransaction();
|
||||
Core.downloadMessage(ServiceSynchronize.this,
|
||||
folder, (IMAPFolder) ifolder,
|
||||
(IMAPMessage) e.getMessage(), message.id);
|
||||
db.setTransactionSuccessful();
|
||||
} finally {
|
||||
db.endTransaction();
|
||||
}
|
||||
Core.downloadMessage(ServiceSynchronize.this,
|
||||
folder, (IMAPFolder) ifolder,
|
||||
(IMAPMessage) e.getMessage(), message.id);
|
||||
} catch (MessageRemovedException ex) {
|
||||
Log.w(folder.name, ex);
|
||||
} catch (FolderClosedException ex) {
|
||||
|
|
Loading…
Reference in a new issue