|
|
@ -987,20 +987,14 @@ public class ServiceSynchronize extends LifecycleService {
|
|
|
|
db.endTransaction();
|
|
|
|
db.endTransaction();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (folder.download) {
|
|
|
|
|
|
|
|
Boolean isMetered = Helper.isMetered(ServiceSynchronize.this);
|
|
|
|
|
|
|
|
boolean metered = (isMetered == null || isMetered);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
db.beginTransaction();
|
|
|
|
db.beginTransaction();
|
|
|
|
downloadMessage(
|
|
|
|
downloadMessage(ServiceSynchronize.this,
|
|
|
|
ServiceSynchronize.this, metered,
|
|
|
|
|
|
|
|
folder, ifolder, (IMAPMessage) imessage, message.id);
|
|
|
|
folder, ifolder, (IMAPMessage) imessage, message.id);
|
|
|
|
db.setTransactionSuccessful();
|
|
|
|
db.setTransactionSuccessful();
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
db.endTransaction();
|
|
|
|
db.endTransaction();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (MessageRemovedException ex) {
|
|
|
|
} catch (MessageRemovedException ex) {
|
|
|
|
Log.w(Helper.TAG, folder.name + " " + ex + "\n" + Log.getStackTraceString(ex));
|
|
|
|
Log.w(Helper.TAG, folder.name + " " + ex + "\n" + Log.getStackTraceString(ex));
|
|
|
|
} catch (IOException ex) {
|
|
|
|
} catch (IOException ex) {
|
|
|
@ -1073,20 +1067,14 @@ public class ServiceSynchronize extends LifecycleService {
|
|
|
|
db.endTransaction();
|
|
|
|
db.endTransaction();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (folder.download) {
|
|
|
|
|
|
|
|
Boolean isMetered = Helper.isMetered(ServiceSynchronize.this);
|
|
|
|
|
|
|
|
boolean metered = (isMetered == null || isMetered);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
db.beginTransaction();
|
|
|
|
db.beginTransaction();
|
|
|
|
downloadMessage(
|
|
|
|
downloadMessage(ServiceSynchronize.this,
|
|
|
|
ServiceSynchronize.this, metered,
|
|
|
|
|
|
|
|
folder, ifolder, (IMAPMessage) e.getMessage(), message.id);
|
|
|
|
folder, ifolder, (IMAPMessage) e.getMessage(), message.id);
|
|
|
|
db.setTransactionSuccessful();
|
|
|
|
db.setTransactionSuccessful();
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
db.endTransaction();
|
|
|
|
db.endTransaction();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (MessageRemovedException ex) {
|
|
|
|
} catch (MessageRemovedException ex) {
|
|
|
|
Log.w(Helper.TAG, folder.name + " " + ex + "\n" + Log.getStackTraceString(ex));
|
|
|
|
Log.w(Helper.TAG, folder.name + " " + ex + "\n" + Log.getStackTraceString(ex));
|
|
|
|
} catch (IOException ex) {
|
|
|
|
} catch (IOException ex) {
|
|
|
@ -2084,7 +2072,6 @@ public class ServiceSynchronize extends LifecycleService {
|
|
|
|
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();
|
|
|
|
Thread.sleep(20);
|
|
|
|
|
|
|
|
} catch (MessageRemovedException ex) {
|
|
|
|
} catch (MessageRemovedException ex) {
|
|
|
|
Log.w(Helper.TAG, folder.name + " " + ex + "\n" + Log.getStackTraceString(ex));
|
|
|
|
Log.w(Helper.TAG, folder.name + " " + ex + "\n" + Log.getStackTraceString(ex));
|
|
|
|
} catch (FolderClosedException ex) {
|
|
|
|
} catch (FolderClosedException ex) {
|
|
|
@ -2108,7 +2095,6 @@ public class ServiceSynchronize extends LifecycleService {
|
|
|
|
|
|
|
|
|
|
|
|
db.folder().setFolderSyncState(folder.id, "downloading");
|
|
|
|
db.folder().setFolderSyncState(folder.id, "downloading");
|
|
|
|
|
|
|
|
|
|
|
|
if (folder.download) {
|
|
|
|
|
|
|
|
//fp.add(IMAPFolder.FetchProfileItem.MESSAGE);
|
|
|
|
//fp.add(IMAPFolder.FetchProfileItem.MESSAGE);
|
|
|
|
|
|
|
|
|
|
|
|
// Download messages/attachments
|
|
|
|
// Download messages/attachments
|
|
|
@ -2119,18 +2105,11 @@ public class ServiceSynchronize extends LifecycleService {
|
|
|
|
Message[] isub = Arrays.copyOfRange(imessages, from, i + 1);
|
|
|
|
Message[] isub = Arrays.copyOfRange(imessages, from, i + 1);
|
|
|
|
// Fetch on demand
|
|
|
|
// Fetch on demand
|
|
|
|
|
|
|
|
|
|
|
|
Boolean isMetered = Helper.isMetered(ServiceSynchronize.this);
|
|
|
|
|
|
|
|
boolean metered = (isMetered == null || isMetered);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int j = isub.length - 1; j >= 0 && state.running(); j--)
|
|
|
|
for (int j = isub.length - 1; j >= 0 && state.running(); j--)
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
db.beginTransaction();
|
|
|
|
db.beginTransaction();
|
|
|
|
if (ids[from + j] != null) {
|
|
|
|
if (ids[from + j] != null)
|
|
|
|
downloadMessage(
|
|
|
|
downloadMessage(this, folder, ifolder, (IMAPMessage) isub[j], ids[from + j]);
|
|
|
|
this, metered,
|
|
|
|
|
|
|
|
folder, ifolder, (IMAPMessage) isub[j], ids[from + j]);
|
|
|
|
|
|
|
|
Thread.sleep(20);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
db.setTransactionSuccessful();
|
|
|
|
db.setTransactionSuccessful();
|
|
|
|
} catch (FolderClosedException ex) {
|
|
|
|
} catch (FolderClosedException ex) {
|
|
|
|
throw ex;
|
|
|
|
throw ex;
|
|
|
@ -2150,7 +2129,6 @@ public class ServiceSynchronize extends LifecycleService {
|
|
|
|
} catch (InterruptedException ignored) {
|
|
|
|
} catch (InterruptedException ignored) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (state.running)
|
|
|
|
if (state.running)
|
|
|
|
db.folder().setFolderInitialized(folder.id);
|
|
|
|
db.folder().setFolderInitialized(folder.id);
|
|
|
@ -2384,22 +2362,26 @@ public class ServiceSynchronize extends LifecycleService {
|
|
|
|
return message;
|
|
|
|
return message;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static void downloadMessage(Context context, boolean metered, 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) throws MessagingException, IOException {
|
|
|
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
|
|
|
|
|
|
|
long download = prefs.getInt("download", 32768);
|
|
|
|
|
|
|
|
if (download == 0)
|
|
|
|
|
|
|
|
download = Long.MAX_VALUE;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
List<EntityAttachment> attachments = db.attachment().getAttachments(message.id);
|
|
|
|
|
|
|
|
MessageHelper helper = new MessageHelper(imessage);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (message.setContactInfo(context))
|
|
|
|
if (message.setContactInfo(context))
|
|
|
|
db.message().updateMessage(message);
|
|
|
|
db.message().updateMessage(message);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (folder.download) {
|
|
|
|
|
|
|
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
|
|
|
|
|
|
|
long download = prefs.getInt("download", 32768);
|
|
|
|
|
|
|
|
if (download == 0)
|
|
|
|
|
|
|
|
download = Long.MAX_VALUE;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<EntityAttachment> attachments = db.attachment().getAttachments(message.id);
|
|
|
|
|
|
|
|
MessageHelper helper = new MessageHelper(imessage);
|
|
|
|
|
|
|
|
Boolean isMetered = Helper.isMetered(context);
|
|
|
|
|
|
|
|
boolean metered = (isMetered == null || isMetered);
|
|
|
|
|
|
|
|
|
|
|
|
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 < download))
|
|
|
@ -2453,6 +2435,7 @@ public class ServiceSynchronize extends LifecycleService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private class ServiceManager extends ConnectivityManager.NetworkCallback {
|
|
|
|
private class ServiceManager extends ConnectivityManager.NetworkCallback {
|
|
|
|
private ServiceState state;
|
|
|
|
private ServiceState state;
|
|
|
|