MCPcopy Create free account
hub / github.com/M66B/FairEmail / onExists

Method onExists

app/src/main/java/eu/faircode/email/Core.java:2439–2521  ·  view source on GitHub ↗
(Context context, JSONArray jargs, EntityAccount account, EntityFolder folder, EntityMessage message, EntityOperation op, IMAPFolder ifolder)

Source from the content-addressed store, hash-verified

2437 }
2438
2439 private static void onExists(Context context, JSONArray jargs, EntityAccount account, EntityFolder folder, EntityMessage message, EntityOperation op, IMAPFolder ifolder) throws MessagingException, IOException {
2440 DB db = DB.getInstance(context);
2441
2442 boolean retry = jargs.optBoolean(0);
2443
2444 if (message.uid != null)
2445 return;
2446
2447 if (message.msgid == null)
2448 throw new IllegalArgumentException("exists without msgid");
2449
2450 // Search for message
2451 // Alternative, inconsistent for Outlook: X-Microsoft-Original-Message-ID
2452 Message[] imessages = ifolder.search(account.isOutlook()
2453 ? new HeaderTerm(MessageHelper.HEADER_CORRELATION_ID, message.msgid)
2454 : new MessageIDTerm(message.msgid));
2455 EntityLog.log(context, folder.name + " exists" +
2456 " retry=" + retry +
2457 " host=" + account.host +
2458 " outlook=" + account.isOutlook() +
2459 " messages=" + (imessages == null ? null : imessages.length));
2460
2461 if (account.isOutlook() && (imessages == null || imessages.length == 0)) {
2462 imessages = ifolder.search(
2463 new HeaderTerm(MessageHelper.HEADER_MICROSOFT_ORIGINAL_MESSAGE_ID, message.msgid));
2464 EntityLog.log(context, folder.name + " exists alt" +
2465 " retry=" + retry +
2466 " host=" + account.host +
2467 " outlook=" + account.isOutlook() +
2468 " messages=" + (imessages == null ? null : imessages.length));
2469 }
2470
2471 // Searching for random header:
2472 // iCloud: NO [UNAVAILABLE] Unexpected exception
2473 // Seznam: Jakarta Mail Exception: java.io.IOException: Connection dropped by server?
2474
2475 // Some email servers are slow with adding sent messages
2476 if (retry)
2477 Log.w(folder.name + " EXISTS retry" +
2478 " found=" + (imessages == null ? null : imessages.length) +
2479 " host=" + account.host);
2480 else if (imessages == null || imessages.length == 0) {
2481 long next = new Date().getTime() + (account.isOutlook() ? EXISTS_RETRY_DELAY_OUTLOOK : EXISTS_RETRY_DELAY);
2482
2483 Intent intent = new Intent(context, ServiceSynchronize.class);
2484 intent.setAction("exists:" + message.id);
2485 PendingIntent piExists = PendingIntentCompat.getForegroundService(
2486 context, ServiceSynchronize.PI_EXISTS, intent, PendingIntent.FLAG_UPDATE_CURRENT);
2487
2488 AlarmManager am = Helper.getSystemService(context, AlarmManager.class);
2489 AlarmManagerCompatEx.setAndAllowWhileIdle(context, am, AlarmManager.RTC_WAKEUP, next, piExists);
2490 return;
2491 }
2492
2493 if (imessages != null && imessages.length == 1) {
2494 String msgid;
2495 try {
2496 MessageHelper helper = new MessageHelper((MimeMessage) imessages[0], context);

Callers 1

processOperationsMethod · 0.95

Calls 15

getInstanceMethod · 0.95
logMethod · 0.95
wMethod · 0.95
getForegroundServiceMethod · 0.95
getSystemServiceMethod · 0.95
setAndAllowWhileIdleMethod · 0.95
getMessageIDMethod · 0.95
eMethod · 0.95
folderMethod · 0.95
queueMethod · 0.95
syncMethod · 0.95
isOutlookMethod · 0.80

Tested by

no test coverage detected