Example #1
0
bool SortTask::handleStateHelper(const Imap::Responses::State *const resp)
{
    if (resp->tag.isEmpty()) {
        if (resp->kind == Responses::NO && resp->respCode == Responses::NOUPDATE) {
            // * NO [NOUPDATE "tag"] means that the server won't be providing further updates for our SEARCH/SORT criteria
            const Responses::RespData<QString> *const untaggedTag = dynamic_cast<const Responses::RespData<QString>* const>(
                        resp->respCodeData.data());
            Q_ASSERT(untaggedTag);
            if (untaggedTag->data.toUtf8() == sortTag) {
                m_persistentSearch = false;
                model->m_taskModel->slotTaskMighHaveChanged(this);

                if (m_firstCommandCompleted) {
                    // The server decided that it will no longer inform us about the updated SORT order, and the original
                    // response has been already received and processed. That means that we're done here and shall declare
                    // ourselves as completed.
                    _completed();
                }
                // We actually support even more benevolent mode of operation where the server can tell us at any time that
                // this context updating is no longer supported. Yay for that; let's hope that it's reasonably bug-free now.
                return true;
            }
        }
        return false;
    }

    if (resp->tag == sortTag) {
        m_firstCommandCompleted = true;
        if (resp->kind == Responses::OK) {
            emit sortingAvailable(sortResult);
            if (!m_persistentSearch || _aborted) {
                // This is a one-shot operation, we shall not remain as an active task, listening for further updates
                _completed();
            } else {
                // got to prod the TaskPresentationModel
                model->m_taskModel->slotTaskMighHaveChanged(this);

                // Even though we aren't "finished" at this point, the KeepMailboxOpenTask is now free to issue its IDLE thing,
                // as that won't interfere with our mode of operation. Let's kick it around.
                KeepMailboxOpenTask *keepTask = dynamic_cast<KeepMailboxOpenTask*>(conn);
                Q_ASSERT(keepTask);
                keepTask->activateTasks();
            }
        } else {
            _failed(tr("Sorting command has failed"));
        }
        return true;
    } else if (resp->tag == cancelUpdateTag) {
        m_persistentSearch = false;
        model->m_taskModel->slotTaskMighHaveChanged(this);
        _completed();
        return true;
    } else {
        return false;
    }
}
bool SubscribeUnsubscribeTask::handleStateHelper(const Imap::Responses::State *const resp)
{
    if (resp->tag.isEmpty())
        return false;

    if (resp->tag == tag) {
        if (resp->kind == Responses::OK) {
            TreeItemMailbox *mailbox = dynamic_cast<TreeItemMailbox *>(static_cast<TreeItem *>(mailboxIndex.internalPointer()));
            QString subscribed = QLatin1String("\\SUBSCRIBED");
            switch (operation) {
            case SUBSCRIBE:
                if (mailbox && !mailbox->m_metadata.flags.contains(subscribed)) {
                    mailbox->m_metadata.flags.append(subscribed);
                }
                break;
            case UNSUBSCRIBE:
                if (mailbox) {
                    mailbox->m_metadata.flags.removeOne(subscribed);
                }
            }
            _completed();
        } else {
            _failed("SUBSCRIBE/UNSUBSCRIBE has failed");
            // FIXME: error handling
        }
        return true;
    } else {
        return false;
    }
}
   void
   RemoteLister::canceled()
   {
      debug() << "canceled: " << url().prettyURL() << endl;

      QTimer::singleShot( 0, this, SLOT(_completed()) );
   }
Example #4
0
bool CreateMailboxTask::handleStateHelper(const Imap::Responses::State *const resp)
{
    if (resp->tag.isEmpty())
        return false;

    if (resp->tag == tagCreate) {
        if (resp->kind == Responses::OK) {
            EMIT_LATER(model, mailboxCreationSucceded, Q_ARG(QString, mailbox));
            if (_dead) {
                // Got to check if we're still allowed to execute before launching yet another command
                _failed("Asked to die");
                return true;
            }
            tagList = parser->list(QLatin1String(""), mailbox);
            // Don't call _completed() yet, we're going to update mbox list before that
        } else {
            EMIT_LATER(model, mailboxCreationFailed, Q_ARG(QString, mailbox), Q_ARG(QString, resp->message));
            _failed("Cannot create mailbox");
        }
        return true;
    } else if (resp->tag == tagList) {
        if (resp->kind == Responses::OK) {
            model->finalizeIncrementalList(parser, mailbox);
            _completed();
        } else {
            _failed("Error with the LIST command after the CREATE");
        }
        return true;
    } else {
        return false;
    }
}
void SubscribeUnsubscribeTask::perform()
{
    parser = conn->parser;
    markAsActiveTask();

    IMAP_TASK_CHECK_ABORT_DIE;

    if (! mailboxIndex.isValid()) {
        // FIXME: add proper fix
        log("Mailbox vanished before we could ask for number of messages inside");
        _completed();
        return;
    }
    TreeItemMailbox *mailbox = dynamic_cast<TreeItemMailbox *>(static_cast<TreeItem *>(mailboxIndex.internalPointer()));
    Q_ASSERT(mailbox);

    switch (operation) {
    case SUBSCRIBE:
        tag = parser->subscribe(mailbox->mailbox());
        break;
    case UNSUBSCRIBE:
        tag = parser->unSubscribe(mailbox->mailbox());
        break;
    default:
        Q_ASSERT(false);
    }
}
Example #6
0
bool AppendTask::handleStateHelper(const Imap::Responses::State *const resp)
{
    if (resp->tag.isEmpty())
        return false;

    if (resp->tag == tag) {

        if (resp->kind == Responses::OK) {
            if (resp->respCode == Responses::APPENDUID) {
                const Responses::RespData<QPair<uint, Sequence> > *const respData =
                        dynamic_cast<const Responses::RespData<QPair<uint, Sequence> >* const>(resp->respCodeData.data());
                Q_ASSERT(respData);
                auto uids = respData->data.second.toVector();
                if (uids.size() != 1) {
                    log(QLatin1String("APPENDUID: malformed data, cannot extract a single UID"));
                } else {
                    emit appendUid(respData->data.first, uids.front());
                }
            }
            // nothing should be needed here
            _completed();
        } else {
            _failed(resp->message);
        }
        return true;
    } else {
        return false;
    }
}
bool SubscribeUnsubscribeTask::handleStateHelper(const Imap::Responses::State *const resp)
{
    if (resp->tag.isEmpty())
        return false;

    if (resp->tag == tag) {
        if (resp->kind == Responses::OK) {
            TreeItemMailbox *mailbox = dynamic_cast<TreeItemMailbox *>(model->findMailboxByName(mailboxName));
            QString subscribed = QStringLiteral("\\SUBSCRIBED");
            switch (operation) {
            case SUBSCRIBE:
                if (mailbox && !mailbox->m_metadata.flags.contains(subscribed)) {
                    mailbox->m_metadata.flags.append(subscribed);
                }
                break;
            case UNSUBSCRIBE:
                if (mailbox) {
                    mailbox->m_metadata.flags.removeOne(subscribed);
                }
            }
            if (mailbox) {
                auto index = mailbox->toIndex(model);
                emit model->dataChanged(index, index);
            }
            _completed();
        } else {
            _failed(tr("SUBSCRIBE/UNSUBSCRIBE has failed"));
            // FIXME: error handling
        }
        return true;
    } else {
        return false;
    }
}
   void
   RemoteLister::completed()
   {
      debug() << "completed: " << url().prettyURL() << endl;

      //as usual KDE documentation didn't suggest I needed to do this at all
      //I had to figure it out myself
      // -- avoid crash
      QTimer::singleShot( 0, this, SLOT(_completed()) );
   }
bool UnSelectTask::handleStateHelper(const Imap::Responses::State *const resp)
{
    if (resp->tag.isEmpty()) {
        switch (resp->respCode) {
        case Responses::UNSEEN:
        case Responses::PERMANENTFLAGS:
        case Responses::UIDNEXT:
        case Responses::UIDVALIDITY:
        case Responses::NOMODSEQ:
        case Responses::HIGHESTMODSEQ:
        case Responses::CLOSED:
            return true;
        default:
            break;
        }
    }
    if (!resp->tag.isEmpty()) {
        if (resp->tag == unSelectTag) {
            if (resp->kind == Responses::OK) {
                // nothing should be needed here
                _completed();
            } else {
                // This is really bad.
                throw MailboxException("Attempted to unselect current mailbox, but the server denied our request. "
                                       "Can't continue, to avoid possible data corruption.", *resp);
            }
            return true;
        } else if (resp->tag == selectMissingTag) {
            if (resp->kind == Responses::OK) {
                QTimer::singleShot(0, this, SLOT(doFakeSelect()));
                log(QStringLiteral("The emergency EXAMINE command has unexpectedly succeeded, trying to get out of here..."), Common::LOG_MAILBOX_SYNC);
            } else {
                // This is very good :)
                _completed();
            }
            return true;
        }
    }
    return false;
}
bool NumberOfMessagesTask::handleStateHelper(const Imap::Responses::State *const resp)
{
    if (resp->tag.isEmpty())
        return false;

    if (resp->tag == tag) {
        if (resp->kind == Responses::OK) {
            _completed();
        } else {
            _failed(tr("STATUS has failed"));
            // FIXME: error handling
        }
        return true;
    } else {
        return false;
    }
}
Example #11
0
bool IdTask::handleStateHelper(const Imap::Responses::State *const resp)
{
    if (resp->tag.isEmpty())
        return false;

    if (resp->tag == tag) {
        if (resp->kind == Responses::OK) {
            // nothing should be needed here
            _completed();
        } else {
            _failed(tr("ID failed, strange"));
            // But hey, we can just ignore this one
        }
        return true;
    } else {
        return false;
    }
}
Example #12
0
bool FetchMsgMetadataTask::handleStateHelper(const Imap::Responses::State *const resp)
{
    if (resp->tag.isEmpty())
        return false;

    if (resp->tag == tag) {

        if (resp->kind == Responses::OK) {
            _completed();
        } else {
            _failed("UID FETCH failed");
            // FIXME: error handling
        }
        return true;
    } else {
        return false;
    }
}
bool GenUrlAuthTask::handleStateHelper(const Imap::Responses::State *const resp)
{
    if (resp->tag.isEmpty())
        return false;

    if (resp->tag == tag) {

        if (resp->kind == Responses::OK) {
            // nothing should be needed here
            _completed();
        } else {
            _failed(resp->message);
        }
        return true;
    } else {
        return false;
    }
}
void NumberOfMessagesTask::perform()
{
    parser = conn->parser;
    markAsActiveTask();

    IMAP_TASK_CHECK_ABORT_DIE;

    if (! mailboxIndex.isValid()) {
        // FIXME: add proper fix
        log(QLatin1String("Mailbox vanished before we could ask for number of messages inside"));
        _completed();
        return;
    }
    TreeItemMailbox *mailbox = dynamic_cast<TreeItemMailbox *>(static_cast<TreeItem *>(mailboxIndex.internalPointer()));
    Q_ASSERT(mailbox);

    tag = parser->status(mailbox->mailbox(), requestedStatusOptions());
}
Example #15
0
bool NoopTask::handleStateHelper(const Imap::Responses::State *const resp)
{
    if (resp->tag.isEmpty())
        return false;

    if (resp->tag == tag) {

        if (resp->kind == Responses::OK) {
            // nothing should be needed here
            _completed();
        } else {
            _failed("NOOP failed, strange");
            // FIXME: error handling
        }
        return true;
    } else {
        return false;
    }
}
Example #16
0
bool ThreadTask::handleStateHelper(const Imap::Responses::State *const resp)
{
    if (resp->tag.isEmpty())
        return false;

    if (resp->tag == tag) {
        if (resp->kind == Responses::OK) {
            if (!m_incrementalMode)
                emit model->threadingAvailable(mailboxIndex, algorithm, searchCriteria, mapping);
            _completed();
        } else {
            _failed("Threading command has failed");
        }
        mapping.clear();
        return true;
    } else {
        return false;
    }
}
Example #17
0
void CommandBase::Completed()
{
    if(!_completed.empty())
        _completed(shared_from_this());
}