|
|
@ -986,7 +986,8 @@ public class ServiceSynchronize extends LifecycleService {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
db.beginTransaction();
|
|
|
|
db.beginTransaction();
|
|
|
|
downloadMessage(ServiceSynchronize.this,
|
|
|
|
downloadMessage(ServiceSynchronize.this,
|
|
|
|
folder, ifolder, (IMAPMessage) imessage, message.id);
|
|
|
|
folder, ifolder, (IMAPMessage) imessage,
|
|
|
|
|
|
|
|
message.id, db.folder().getFolderDownload(folder.id));
|
|
|
|
db.setTransactionSuccessful();
|
|
|
|
db.setTransactionSuccessful();
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
db.endTransaction();
|
|
|
|
db.endTransaction();
|
|
|
@ -1072,7 +1073,8 @@ public class ServiceSynchronize extends LifecycleService {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
db.beginTransaction();
|
|
|
|
db.beginTransaction();
|
|
|
|
downloadMessage(ServiceSynchronize.this,
|
|
|
|
downloadMessage(ServiceSynchronize.this,
|
|
|
|
folder, ifolder, (IMAPMessage) e.getMessage(), message.id);
|
|
|
|
folder, ifolder, (IMAPMessage) e.getMessage(),
|
|
|
|
|
|
|
|
message.id, db.folder().getFolderDownload(folder.id));
|
|
|
|
db.setTransactionSuccessful();
|
|
|
|
db.setTransactionSuccessful();
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
db.endTransaction();
|
|
|
|
db.endTransaction();
|
|
|
@ -2016,6 +2018,7 @@ public class ServiceSynchronize extends LifecycleService {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
int sync_days = jargs.getInt(0);
|
|
|
|
int sync_days = jargs.getInt(0);
|
|
|
|
int keep_days = jargs.getInt(1);
|
|
|
|
int keep_days = jargs.getInt(1);
|
|
|
|
|
|
|
|
boolean download = jargs.getBoolean(2);
|
|
|
|
|
|
|
|
|
|
|
|
Log.i(folder.name + " start sync after=" + sync_days + "/" + keep_days);
|
|
|
|
Log.i(folder.name + " start sync after=" + sync_days + "/" + keep_days);
|
|
|
|
|
|
|
|
|
|
|
@ -2127,7 +2130,8 @@ public class ServiceSynchronize extends LifecycleService {
|
|
|
|
db.beginTransaction();
|
|
|
|
db.beginTransaction();
|
|
|
|
EntityMessage message = synchronizeMessage(
|
|
|
|
EntityMessage message = synchronizeMessage(
|
|
|
|
this,
|
|
|
|
this,
|
|
|
|
folder, ifolder, (IMAPMessage) isub[j], false, true);
|
|
|
|
folder, ifolder, (IMAPMessage) isub[j],
|
|
|
|
|
|
|
|
false, true);
|
|
|
|
ids[from + j] = message.id;
|
|
|
|
ids[from + j] = message.id;
|
|
|
|
db.setTransactionSuccessful();
|
|
|
|
db.setTransactionSuccessful();
|
|
|
|
} catch (MessageRemovedException ex) {
|
|
|
|
} catch (MessageRemovedException ex) {
|
|
|
@ -2173,7 +2177,10 @@ public class ServiceSynchronize extends LifecycleService {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
db.beginTransaction();
|
|
|
|
db.beginTransaction();
|
|
|
|
if (ids[from + j] != null)
|
|
|
|
if (ids[from + j] != null)
|
|
|
|
downloadMessage(this, folder, ifolder, (IMAPMessage) isub[j], ids[from + j]);
|
|
|
|
downloadMessage(
|
|
|
|
|
|
|
|
this,
|
|
|
|
|
|
|
|
folder, ifolder, (IMAPMessage) isub[j],
|
|
|
|
|
|
|
|
ids[from + j], download);
|
|
|
|
db.setTransactionSuccessful();
|
|
|
|
db.setTransactionSuccessful();
|
|
|
|
} catch (FolderClosedException ex) {
|
|
|
|
} catch (FolderClosedException ex) {
|
|
|
|
throw ex;
|
|
|
|
throw ex;
|
|
|
@ -2426,7 +2433,10 @@ public class ServiceSynchronize extends LifecycleService {
|
|
|
|
return message;
|
|
|
|
return message;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static void downloadMessage(Context context, EntityFolder folder, IMAPFolder ifolder, IMAPMessage imessage, long id) throws MessagingException, IOException {
|
|
|
|
private static void downloadMessage(
|
|
|
|
|
|
|
|
Context context,
|
|
|
|
|
|
|
|
EntityFolder folder, IMAPFolder ifolder, IMAPMessage imessage,
|
|
|
|
|
|
|
|
long id, boolean download) throws MessagingException, IOException {
|
|
|
|
DB db = DB.getInstance(context);
|
|
|
|
DB db = DB.getInstance(context);
|
|
|
|
EntityMessage message = db.message().getMessage(id);
|
|
|
|
EntityMessage message = db.message().getMessage(id);
|
|
|
|
if (message == null)
|
|
|
|
if (message == null)
|
|
|
@ -2435,11 +2445,11 @@ public class ServiceSynchronize extends LifecycleService {
|
|
|
|
if (message.setContactInfo(context))
|
|
|
|
if (message.setContactInfo(context))
|
|
|
|
db.message().updateMessage(message);
|
|
|
|
db.message().updateMessage(message);
|
|
|
|
|
|
|
|
|
|
|
|
if (folder.download) {
|
|
|
|
if (download) {
|
|
|
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
|
|
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
|
|
|
long download = prefs.getInt("download", 32768);
|
|
|
|
long maxSize = prefs.getInt("download", 32768);
|
|
|
|
if (download == 0)
|
|
|
|
if (maxSize == 0)
|
|
|
|
download = Long.MAX_VALUE;
|
|
|
|
maxSize = Long.MAX_VALUE;
|
|
|
|
|
|
|
|
|
|
|
|
List<EntityAttachment> attachments = db.attachment().getAttachments(message.id);
|
|
|
|
List<EntityAttachment> attachments = db.attachment().getAttachments(message.id);
|
|
|
|
MessageHelper helper = new MessageHelper(imessage);
|
|
|
|
MessageHelper helper = new MessageHelper(imessage);
|
|
|
@ -2448,13 +2458,13 @@ public class ServiceSynchronize extends LifecycleService {
|
|
|
|
|
|
|
|
|
|
|
|
boolean fetch = false;
|
|
|
|
boolean fetch = false;
|
|
|
|
if (!message.content)
|
|
|
|
if (!message.content)
|
|
|
|
if (!metered || (message.size != null && message.size < download))
|
|
|
|
if (!metered || (message.size != null && message.size < maxSize))
|
|
|
|
fetch = true;
|
|
|
|
fetch = true;
|
|
|
|
|
|
|
|
|
|
|
|
if (!fetch)
|
|
|
|
if (!fetch)
|
|
|
|
for (EntityAttachment attachment : attachments)
|
|
|
|
for (EntityAttachment attachment : attachments)
|
|
|
|
if (!attachment.available)
|
|
|
|
if (!attachment.available)
|
|
|
|
if (!metered || (attachment.size != null && attachment.size < download)) {
|
|
|
|
if (!metered || (attachment.size != null && attachment.size < maxSize)) {
|
|
|
|
fetch = true;
|
|
|
|
fetch = true;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -2474,7 +2484,7 @@ public class ServiceSynchronize extends LifecycleService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!message.content)
|
|
|
|
if (!message.content)
|
|
|
|
if (!metered || (message.size != null && message.size < download)) {
|
|
|
|
if (!metered || (message.size != null && message.size < maxSize)) {
|
|
|
|
String body = helper.getHtml();
|
|
|
|
String body = helper.getHtml();
|
|
|
|
message.write(context, body);
|
|
|
|
message.write(context, body);
|
|
|
|
db.message().setMessageContent(
|
|
|
|
db.message().setMessageContent(
|
|
|
@ -2486,7 +2496,7 @@ public class ServiceSynchronize extends LifecycleService {
|
|
|
|
for (int i = 0; i < attachments.size(); i++) {
|
|
|
|
for (int i = 0; i < attachments.size(); i++) {
|
|
|
|
EntityAttachment attachment = attachments.get(i);
|
|
|
|
EntityAttachment attachment = attachments.get(i);
|
|
|
|
if (!attachment.available)
|
|
|
|
if (!attachment.available)
|
|
|
|
if (!metered || (attachment.size != null && attachment.size < download)) {
|
|
|
|
if (!metered || (attachment.size != null && attachment.size < maxSize)) {
|
|
|
|
if (iattachments == null)
|
|
|
|
if (iattachments == null)
|
|
|
|
iattachments = helper.getAttachments();
|
|
|
|
iattachments = helper.getAttachments();
|
|
|
|
// Attachments of drafts might not have been uploaded yet
|
|
|
|
// Attachments of drafts might not have been uploaded yet
|
|
|
|