MCPcopy Create free account
hub / github.com/MailCore/mailcore2 / idle

Method idle

src/core/imap/MCIMAPSession.cpp:3556–3642  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3554}
3555
3556void IMAPSession::idle(String * folder, uint32_t lastKnownUID, ErrorCode * pError)
3557{
3558 int r;
3559
3560 // connection thread
3561 selectIfNeeded(folder, pError);
3562 if (* pError != ErrorNone)
3563 return;
3564
3565 if (lastKnownUID != 0) {
3566 Array * msgs;
3567
3568 msgs = fetchMessagesByUID(folder, IMAPMessagesRequestKindUid, IndexSet::indexSetWithRange(RangeMake(lastKnownUID, UINT64_MAX)),
3569 NULL, pError);
3570 if (* pError != ErrorNone)
3571 return;
3572 if (msgs->count() > 0) {
3573 IMAPMessage * msg;
3574
3575 msg = (IMAPMessage *) msgs->objectAtIndex(0);
3576 if (msg->uid() > lastKnownUID) {
3577 MCLog("found msg UID %u %u", (unsigned int) msg->uid(), (unsigned int) lastKnownUID);
3578 return;
3579 }
3580 }
3581 }
3582
3583 r = mailimap_idle(mImap);
3584 if (r == MAILIMAP_ERROR_STREAM) {
3585 mShouldDisconnect = true;
3586 * pError = ErrorConnection;
3587 return;
3588 }
3589 else if (r == MAILIMAP_ERROR_PARSE) {
3590 mShouldDisconnect = true;
3591 * pError = ErrorParse;
3592 return;
3593 }
3594 else if (hasError(r)) {
3595 * pError = ErrorIdle;
3596 return;
3597 }
3598
3599 if (!mImap->imap_selection_info->sel_has_exists && !mImap->imap_selection_info->sel_has_recent) {
3600 int r;
3601 r = mailstream_wait_idle(mImap->imap_stream, MAX_IDLE_DELAY);
3602 switch (r) {
3603 case MAILSTREAM_IDLE_ERROR:
3604 case MAILSTREAM_IDLE_CANCELLED:
3605 {
3606 mShouldDisconnect = true;
3607 * pError = ErrorConnection;
3608 MCLog("error or cancelled");
3609 return;
3610 }
3611 case MAILSTREAM_IDLE_INTERRUPTED:
3612 MCLog("interrupted by user");
3613 break;

Callers 1

mainMethod · 0.80

Calls 4

hasErrorFunction · 0.85
objectAtIndexMethod · 0.80
countMethod · 0.45
uidMethod · 0.45

Tested by

no test coverage detected