|
|
|
@ -147,7 +147,7 @@ class Core {
|
|
|
|
|
private static final int TOTAL_RETRY_MAX = LOCAL_RETRY_MAX * 10;
|
|
|
|
|
|
|
|
|
|
static void processOperations(
|
|
|
|
|
Context context, int session,
|
|
|
|
|
Context context,
|
|
|
|
|
EntityAccount account, EntityFolder folder, List<TupleOperationEx> ops,
|
|
|
|
|
Store istore, Folder ifolder,
|
|
|
|
|
State state, int priority, long sequence)
|
|
|
|
@ -162,7 +162,7 @@ class Core {
|
|
|
|
|
Log.i(folder.name + " executing operations=" + ops.size());
|
|
|
|
|
while (retry < LOCAL_RETRY_MAX && ops.size() > 0 &&
|
|
|
|
|
state.isRunning() &&
|
|
|
|
|
state.batchCanRun(session, folder.id, priority, sequence)) {
|
|
|
|
|
state.batchCanRun(folder.id, priority, sequence)) {
|
|
|
|
|
TupleOperationEx op = ops.get(0);
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
@ -302,7 +302,7 @@ class Core {
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case EntityOperation.DELETE:
|
|
|
|
|
onDelete(context, session, jargs, account, folder, message, (POP3Folder) ifolder, (POP3Store) istore, state);
|
|
|
|
|
onDelete(context, jargs, account, folder, message, (POP3Folder) ifolder, (POP3Store) istore, state);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case EntityOperation.SYNC:
|
|
|
|
@ -341,22 +341,22 @@ class Core {
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case EntityOperation.ADD:
|
|
|
|
|
onAdd(context, session, jargs, account, folder, message, (IMAPStore) istore, (IMAPFolder) ifolder, state);
|
|
|
|
|
onAdd(context, jargs, account, folder, message, (IMAPStore) istore, (IMAPFolder) ifolder, state);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case EntityOperation.MOVE:
|
|
|
|
|
List<EntityMessage> messages = new ArrayList<>();
|
|
|
|
|
messages.add(message);
|
|
|
|
|
messages.addAll(similar.values());
|
|
|
|
|
onMove(context, session, jargs, false, folder, messages, (IMAPStore) istore, (IMAPFolder) ifolder, state);
|
|
|
|
|
onMove(context, jargs, false, folder, messages, (IMAPStore) istore, (IMAPFolder) ifolder, state);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case EntityOperation.COPY:
|
|
|
|
|
onMove(context, session, jargs, true, folder, Arrays.asList(message), (IMAPStore) istore, (IMAPFolder) ifolder, state);
|
|
|
|
|
onMove(context, jargs, true, folder, Arrays.asList(message), (IMAPStore) istore, (IMAPFolder) ifolder, state);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case EntityOperation.FETCH:
|
|
|
|
|
onFetch(context, session, jargs, folder, (IMAPStore) istore, (IMAPFolder) ifolder, state);
|
|
|
|
|
onFetch(context, jargs, folder, (IMAPStore) istore, (IMAPFolder) ifolder, state);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case EntityOperation.DELETE:
|
|
|
|
@ -384,7 +384,7 @@ class Core {
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case EntityOperation.SYNC:
|
|
|
|
|
onSynchronizeMessages(context, session, jargs, account, folder, (IMAPStore) istore, (IMAPFolder) ifolder, state);
|
|
|
|
|
onSynchronizeMessages(context, jargs, account, folder, (IMAPStore) istore, (IMAPFolder) ifolder, state);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case EntityOperation.SUBSCRIBE:
|
|
|
|
@ -502,7 +502,7 @@ class Core {
|
|
|
|
|
retry++;
|
|
|
|
|
if (retry < LOCAL_RETRY_MAX &&
|
|
|
|
|
state.isRunning() &&
|
|
|
|
|
state.batchCanRun(session, folder.id, priority, sequence))
|
|
|
|
|
state.batchCanRun(folder.id, priority, sequence))
|
|
|
|
|
try {
|
|
|
|
|
Thread.sleep(LOCAL_RETRY_DELAY);
|
|
|
|
|
} catch (InterruptedException ex1) {
|
|
|
|
@ -530,8 +530,6 @@ class Core {
|
|
|
|
|
|
|
|
|
|
if (ops.size() == 0)
|
|
|
|
|
state.batchCompleted(folder.id, priority, sequence);
|
|
|
|
|
else
|
|
|
|
|
state.error(new OperationCanceledException("Processing"), session);
|
|
|
|
|
} finally {
|
|
|
|
|
Log.i(folder.name + " end process state=" + state + " pending=" + ops.size());
|
|
|
|
|
}
|
|
|
|
@ -801,7 +799,7 @@ class Core {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void onAdd(Context context, int session, JSONArray jargs, EntityAccount account, EntityFolder folder, EntityMessage message, IMAPStore istore, IMAPFolder ifolder, State state) throws MessagingException, IOException {
|
|
|
|
|
private static void onAdd(Context context, JSONArray jargs, EntityAccount account, EntityFolder folder, EntityMessage message, IMAPStore istore, IMAPFolder ifolder, State state) throws MessagingException, IOException {
|
|
|
|
|
// Add message
|
|
|
|
|
DB db = DB.getInstance(context);
|
|
|
|
|
|
|
|
|
@ -915,7 +913,7 @@ class Core {
|
|
|
|
|
try {
|
|
|
|
|
JSONArray fargs = new JSONArray();
|
|
|
|
|
fargs.put(newuid);
|
|
|
|
|
onFetch(context, session, fargs, folder, istore, ifolder, state);
|
|
|
|
|
onFetch(context, fargs, folder, istore, ifolder, state);
|
|
|
|
|
} catch (JSONException ex) {
|
|
|
|
|
Log.e(ex);
|
|
|
|
|
}
|
|
|
|
@ -929,7 +927,7 @@ class Core {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void onMove(Context context, int session, JSONArray jargs, boolean copy, EntityFolder folder, List<EntityMessage> messages, IMAPStore istore, IMAPFolder ifolder, State state) throws JSONException, MessagingException, IOException {
|
|
|
|
|
private static void onMove(Context context, JSONArray jargs, boolean copy, EntityFolder folder, List<EntityMessage> messages, IMAPStore istore, IMAPFolder ifolder, State state) throws JSONException, MessagingException, IOException {
|
|
|
|
|
// Move message
|
|
|
|
|
DB db = DB.getInstance(context);
|
|
|
|
|
|
|
|
|
@ -1062,7 +1060,7 @@ class Core {
|
|
|
|
|
if (fetch) {
|
|
|
|
|
JSONArray fargs = new JSONArray();
|
|
|
|
|
fargs.put(uid);
|
|
|
|
|
onFetch(context, session, fargs, target, istore, itarget, state);
|
|
|
|
|
onFetch(context, fargs, target, istore, itarget, state);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (Throwable ex) {
|
|
|
|
@ -1118,7 +1116,7 @@ class Core {
|
|
|
|
|
db.message().updateMessage(message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void onFetch(Context context, int session, JSONArray jargs, EntityFolder folder, IMAPStore istore, IMAPFolder ifolder, State state) throws JSONException, MessagingException, IOException {
|
|
|
|
|
private static void onFetch(Context context, JSONArray jargs, EntityFolder folder, IMAPStore istore, IMAPFolder ifolder, State state) throws JSONException, MessagingException, IOException {
|
|
|
|
|
long uid = jargs.getLong(0);
|
|
|
|
|
boolean removed = jargs.optBoolean(1);
|
|
|
|
|
|
|
|
|
@ -1162,7 +1160,7 @@ class Core {
|
|
|
|
|
}
|
|
|
|
|
ifolder.fetch(new Message[]{imessage}, fp);
|
|
|
|
|
|
|
|
|
|
EntityMessage message = synchronizeMessage(context, session, account, folder, istore, ifolder, imessage, false, download, rules, state, stats);
|
|
|
|
|
EntityMessage message = synchronizeMessage(context, account, folder, istore, ifolder, imessage, false, download, rules, state, stats);
|
|
|
|
|
if (message != null) {
|
|
|
|
|
if (account.isGmail() && EntityFolder.USER.equals(folder.type))
|
|
|
|
|
try {
|
|
|
|
@ -1175,7 +1173,7 @@ class Core {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (download)
|
|
|
|
|
downloadMessage(context, session, account, folder, istore, ifolder, imessage, message.id, state, stats);
|
|
|
|
|
downloadMessage(context, account, folder, istore, ifolder, imessage, message.id, state, stats);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!stats.isEmpty())
|
|
|
|
@ -1251,7 +1249,7 @@ class Core {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void onDelete(Context context, int session, JSONArray jargs, EntityAccount account, EntityFolder folder, EntityMessage message, POP3Folder ifolder, POP3Store istore, State state) throws MessagingException, IOException {
|
|
|
|
|
private static void onDelete(Context context, JSONArray jargs, EntityAccount account, EntityFolder folder, EntityMessage message, POP3Folder ifolder, POP3Store istore, State state) throws MessagingException, IOException {
|
|
|
|
|
// Delete message
|
|
|
|
|
DB db = DB.getInstance(context);
|
|
|
|
|
|
|
|
|
@ -1294,7 +1292,7 @@ class Core {
|
|
|
|
|
ifolder.open(Folder.READ_WRITE);
|
|
|
|
|
} catch (Throwable ex) {
|
|
|
|
|
Log.e(ex);
|
|
|
|
|
state.error(new FolderClosedException(ifolder, "POP"), session);
|
|
|
|
|
state.error(new FolderClosedException(ifolder, "POP"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -2091,7 +2089,7 @@ class Core {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void onSynchronizeMessages(
|
|
|
|
|
Context context, int session, JSONArray jargs,
|
|
|
|
|
Context context, JSONArray jargs,
|
|
|
|
|
EntityAccount account, final EntityFolder folder,
|
|
|
|
|
IMAPStore istore, final IMAPFolder ifolder, State state) throws JSONException, MessagingException, IOException {
|
|
|
|
|
final DB db = DB.getInstance(context);
|
|
|
|
@ -2401,7 +2399,7 @@ class Core {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
EntityMessage message = synchronizeMessage(
|
|
|
|
|
context, session,
|
|
|
|
|
context,
|
|
|
|
|
account, folder,
|
|
|
|
|
istore, ifolder, (MimeMessage) isub[j],
|
|
|
|
|
false, download && initialize == 0,
|
|
|
|
@ -2480,7 +2478,7 @@ class Core {
|
|
|
|
|
try {
|
|
|
|
|
if (ids[from + j] != null) {
|
|
|
|
|
boolean fetched = downloadMessage(
|
|
|
|
|
context, session,
|
|
|
|
|
context,
|
|
|
|
|
account, folder,
|
|
|
|
|
istore, ifolder,
|
|
|
|
|
(MimeMessage) isub[j], ids[from + j],
|
|
|
|
@ -2536,7 +2534,7 @@ class Core {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static EntityMessage synchronizeMessage(
|
|
|
|
|
Context context, int session,
|
|
|
|
|
Context context,
|
|
|
|
|
EntityAccount account, EntityFolder folder,
|
|
|
|
|
IMAPStore istore, IMAPFolder ifolder, MimeMessage imessage,
|
|
|
|
|
boolean browsed, boolean download,
|
|
|
|
@ -2871,7 +2869,7 @@ class Core {
|
|
|
|
|
" size=" + message.size + "/" + (body == null ? null : body.length()));
|
|
|
|
|
|
|
|
|
|
if (TextUtils.isEmpty(body) && parts.hasBody())
|
|
|
|
|
reportEmptyMessage(context, session, state, account, istore);
|
|
|
|
|
reportEmptyMessage(context, state, account, istore);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
@ -3192,7 +3190,7 @@ class Core {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static boolean downloadMessage(
|
|
|
|
|
Context context, int session,
|
|
|
|
|
Context context,
|
|
|
|
|
EntityAccount account, EntityFolder folder,
|
|
|
|
|
IMAPStore istore, IMAPFolder ifolder,
|
|
|
|
|
MimeMessage imessage, long id, State state, SyncStats stats) throws MessagingException, IOException {
|
|
|
|
@ -3265,7 +3263,7 @@ class Core {
|
|
|
|
|
" size=" + message.size + "/" + (body == null ? null : body.length()));
|
|
|
|
|
|
|
|
|
|
if (TextUtils.isEmpty(body) && parts.hasBody())
|
|
|
|
|
reportEmptyMessage(context, session, state, account, istore);
|
|
|
|
|
reportEmptyMessage(context, state, account, istore);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -3286,7 +3284,7 @@ class Core {
|
|
|
|
|
return fetch;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void reportEmptyMessage(Context context, int session, State state, EntityAccount account, IMAPStore istore) {
|
|
|
|
|
private static void reportEmptyMessage(Context context, State state, EntityAccount account, IMAPStore istore) {
|
|
|
|
|
try {
|
|
|
|
|
if (istore.hasCapability("ID")) {
|
|
|
|
|
Map<String, String> id = new LinkedHashMap<>();
|
|
|
|
@ -3313,7 +3311,7 @@ class Core {
|
|
|
|
|
account.partial_fetch = false;
|
|
|
|
|
DB db = DB.getInstance(context);
|
|
|
|
|
db.account().setAccountPartialFetch(account.id, account.partial_fetch);
|
|
|
|
|
state.error(new StoreClosedException(istore), session);
|
|
|
|
|
state.error(new StoreClosedException(istore));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -4056,8 +4054,6 @@ class Core {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static class State {
|
|
|
|
|
private int session = -1;
|
|
|
|
|
private boolean active = false;
|
|
|
|
|
private int backoff;
|
|
|
|
|
private ConnectionHelper.NetworkState networkState;
|
|
|
|
|
private Thread thread = new Thread();
|
|
|
|
@ -4107,17 +4103,7 @@ class Core {
|
|
|
|
|
return semaphore.tryAcquire(milliseconds, TimeUnit.MILLISECONDS);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void error(Throwable ex, int session) {
|
|
|
|
|
if (!this.active || session != this.session) {
|
|
|
|
|
Log.i("Ignoring" +
|
|
|
|
|
" active=" + active +
|
|
|
|
|
" session=" + session + "/" + this.session +
|
|
|
|
|
" ex=" + ex);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
active = false;
|
|
|
|
|
|
|
|
|
|
void error(Throwable ex) {
|
|
|
|
|
if (ex instanceof MessagingException &&
|
|
|
|
|
("connection failure".equals(ex.getMessage()) ||
|
|
|
|
|
"Not connected".equals(ex.getMessage()) || // POP3
|
|
|
|
@ -4148,18 +4134,12 @@ class Core {
|
|
|
|
|
yield();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void reset(int run) {
|
|
|
|
|
session = run;
|
|
|
|
|
active = true;
|
|
|
|
|
void reset() {
|
|
|
|
|
recoverable = true;
|
|
|
|
|
lastActivity = null;
|
|
|
|
|
resetBatches();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void setActive(boolean whether) {
|
|
|
|
|
this.active = whether;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void resetBatches() {
|
|
|
|
|
synchronized (this) {
|
|
|
|
|
for (FolderPriority key : sequence.keySet()) {
|
|
|
|
@ -4255,10 +4235,7 @@ class Core {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
boolean batchCanRun(int session, long folder, int priority, long current) {
|
|
|
|
|
if (!this.active || session != this.session)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
boolean batchCanRun(long folder, int priority, long current) {
|
|
|
|
|
synchronized (this) {
|
|
|
|
|
FolderPriority key = new FolderPriority(folder, priority);
|
|
|
|
|
boolean can = batch.get(key).equals(current);
|
|
|
|
|