Пример #1
0
QMessageIdList QMFStore::queryMessages(const QMessageFilter &filter, const QString &body, QMessageDataComparator::MatchFlags matchFlags, 
				       const QMessageSortOrder &sortOrder, uint limit, uint offset, QMessageManager::Error &error) const
{
    if (filter.matchFlags() != 0) {
        error = QMessageManager::NotYetImplemented;
        return QMessageIdList();
    }
    
    error = QMessageManager::NoError;
    QMessageIdList ids(convert(d_ptr->_store->queryMessages(convert(filter), convert(sortOrder))));
    
    Qt::CaseSensitivity searchOptions(Qt::CaseInsensitive);
    if (matchFlags & QMessageDataComparator::MatchCaseSensitive) {
        searchOptions = Qt::CaseSensitive;
    }
    
    QMessageIdList result;
    foreach (QMessageId id, ids) {
        QMessage message(id);
        QMessageContentContainer bodyContainer(message.find(message.bodyId()));
        if (bodyContainer.textContent().contains(body, searchOptions)) {
            result.append(id);
            if (limit && ((uint)result.count() >= offset + limit)) {
                break;
            }
        }
    }
Пример #2
0
QMessageIdList convert(const QList<QMailMessageId> &ids)
{
    QMessageIdList result;

    foreach (const QMailMessageId &id, ids) {
        result.append(convert(id));
    }
Пример #3
0
QMessageIdList QMessageStore::queryMessages(const QMessageFilter &filter, const QString &body, QMessageDataComparator::MatchFlags matchFlags, const QMessageSortOrder &sortOrder, uint limit, uint offset) const
{
    bool useHelpers(false);
    QMessageIdList messageIds;

    d_ptr->error = QMessageManager::NoError;

    QMessageFilter handledFilter = filter;
    MessagingHelper::handleNestedFiltersFromMessageFilter(handledFilter);

    // returns the filtered but not ordered list
    messageIds = StorageEngine::instance()->queryMessagesSync(handledFilter, body, matchFlags, sortOrder, limit, offset);

    // QMFStore does not need to use helpers, but messages from StorageEngine needs to be sorted
    if (messageIds.count() > 0)
	useHelpers = true;

    messageIds += QMFStore::instance()->queryMessages(handledFilter, body, matchFlags, sortOrder, limit, offset, d_ptr->error);

    // since QMFStore does sorting and applies offset and limits, 
    // we need to do those here only if there are messages from StorageEngine as well
    if (useHelpers) {
	MessagingHelper::orderMessages(messageIds, sortOrder);
	MessagingHelper::applyOffsetAndLimitToMessageIdList(messageIds, limit, offset);
    }    

    return messageIds;
}
Пример #4
0
void MessagingHelper::orderMessages(QMessageIdList& messageIds,  const QMessageSortOrder &sortOrder)
{
    if (!sortOrder.isEmpty()) {
        messagingHelper()->m_MessageSortOrder = (QMessageSortOrder*)&sortOrder;
        qSort(messageIds.begin(), messageIds.end(), MessagingHelper::messageLessThan);
    }
}
Пример #5
0
void MessagingHelper::filterMessages(QMessageIdList& messageIds, const QMessageFilter& filter)
{
    if (messageIds.count() && !filter.isEmpty()) {
        QMessageFilterPrivate* pf = QMessageFilterPrivate::implementation(filter);
        if ((pf->_field == QMessageFilterPrivate::None) &&
            (pf->_filterList.count() == 0)) {
            if (pf->_notFilter) {
                // There is only one filter: empty ~QMessageFilter()
                // => accountIds must be cleared
                messageIds.clear();
                return;
            } else {
                // There is only one filter: empty QMessageFilter()
                // => accountIds list can remain intact
                return;
            }
        }

        if (pf->_valid) {
            QMessageStore* store = QMessageStore::instance();
            for (int i=messageIds.count()-1; i >= 0; i--) {
                QMessage message = store->message(messageIds[i]);
                if (!pf->filter(message)) {
                    messageIds.removeAt(i);
                }
            }
        }
    }
}
Пример #6
0
QMessageFilter QMessageFilter::byRecipients(const QString &pattern, QMessageDataComparator::LikeComparator cmp)
{
    QMessageIdList ids;

    foreach (QMessageId const& id, QMessageManager().queryMessages()) {
        QMessage msg(id);
        QMessageAddressList addressList(msg.to());
        addressList.append(msg.cc());
        addressList.append(msg.bcc());

        bool matched(false);

        foreach (QMessageAddress const& addr, addressList) {
            if (MessagingUtil::globMatch(pattern, addr.addressee())) {
                matched = true;
                break;
            }
        }

        if ((matched && cmp == QMessageDataComparator::Like)
                || (!matched && cmp == QMessageDataComparator::NotLike)) {
            ids.push_back(id);
        }
    }

    return QMessageFilter::byId(ids);
}
Пример #7
0
QMessageFilter QMessageFilter::bySubject(const QString &pattern, QMessageDataComparator::LikeComparator cmp)
{
    QMessageIdList ids;
    foreach (QMessageId const& id, QMessageManager().queryMessages()) {
        bool matched(MessagingUtil::globMatch(pattern, QMessage(id).subject()));
        if ((matched && cmp == QMessageDataComparator::Like)
                || (!matched && cmp == QMessageDataComparator::NotLike)) {
            ids.push_back(id);
        }
    }

    return QMessageFilter::byId(ids);
}
Пример #8
0
bool QMessageStore::removeMessages(const QMessageFilter& filter, QMessageManager::RemovalOption option)
{
    QMessageIdList ids = queryMessages(filter, QMessageSortOrder(), 0, 0);

    for (int i=0; i < ids.count(); i++) {
        if (ids[i].toString().startsWith("MO_")) {
            if (!ModestEngine::instance()->removeMessage(ids[i], option)) {
                return false;
            }
        } else if(!EventLoggerEngine::instance()->deleteMessage(ids[i]))
            return false;
    }
    return true;
}
Пример #9
0
bool QMessageStore::removeMessages(const QMessageFilter& filter, QMessageManager::RemovalOption option)
{
    bool noErrors;

    d_ptr->error = QMessageManager::NoError;

    noErrors = QMFStore::instance()->removeMessages(filter, option, d_ptr->error);

    QMessageIdList ids = StorageEngine::instance()->queryMessagesSync(filter, QMessageSortOrder(), 0, 0);
    for (int i = 0; i < ids.size(); i++) {
        if (!removeMessage(ids.at(i), option))
            noErrors = false;
    }
    
    return noErrors;
}
Пример #10
0
int QMessageStore::countMessages(const QMessageFilter& filter) const
{
    int count = 0;

    QMessageFilter handledFilter = filter;
    MessagingHelper::handleNestedFiltersFromMessageFilter(handledFilter);

    if (MessagingHelper::preFilter(handledFilter, QMessage::Email)) {
        count += ModestEngine::instance()->countMessagesSync(handledFilter);
    }

    if (MessagingHelper::preFilter(handledFilter, QMessage::Sms)) {
        QMessageIdList messageIds = EventLoggerEngine::instance()->filterAndOrderMessages(handledFilter,QMessageSortOrder(),QString(),QMessageDataComparator::MatchFlags());
        count += messageIds.count();
    }

    return count;
}
void tst_QMessageFilter::testIdPreFilter()
{
    QMessageFilter filter = QMessageFilter::byId(QMessageId(email_prefix+"123"), QMessageDataComparator::Equal);
    QCOMPARE(MessagingHelper::preFilter(filter, QMessage::Email), true);
    QCOMPARE(MessagingHelper::preFilter(filter, QMessage::Sms), false);

    filter = QMessageFilter::byId(QMessageId(sms_prefix+"123"), QMessageDataComparator::Equal);
    QCOMPARE(MessagingHelper::preFilter(filter, QMessage::Sms), true);
    QCOMPARE(MessagingHelper::preFilter(filter, QMessage::Email), false);

    filter = QMessageFilter::byId(QMessageId(email_prefix+"123"), QMessageDataComparator::NotEqual);
    QCOMPARE(MessagingHelper::preFilter(filter, QMessage::Email), true);
    QCOMPARE(MessagingHelper::preFilter(filter, QMessage::Sms), true);

    filter = QMessageFilter::byId(QMessageId(), QMessageDataComparator::Equal);
    QCOMPARE(MessagingHelper::preFilter(filter, QMessage::Email), true);
    QCOMPARE(MessagingHelper::preFilter(filter, QMessage::Sms), true);

    filter = QMessageFilter::byId(QMessageId(), QMessageDataComparator::NotEqual);
    QCOMPARE(MessagingHelper::preFilter(filter, QMessage::Email), true);
    QCOMPARE(MessagingHelper::preFilter(filter, QMessage::Sms), true);

    QMessageIdList idList;
    idList.append(QMessageId(email_prefix+"123"));
    idList.append(QMessageId(email_prefix+"124"));
    filter = QMessageFilter::byId(idList, QMessageDataComparator::Includes);
    QCOMPARE(MessagingHelper::preFilter(filter, QMessage::Email), true);
    QCOMPARE(MessagingHelper::preFilter(filter, QMessage::Sms), false);

    filter = QMessageFilter::byId(idList, QMessageDataComparator::Excludes);
    QCOMPARE(MessagingHelper::preFilter(filter, QMessage::Email), true);
    QCOMPARE(MessagingHelper::preFilter(filter, QMessage::Sms), true);

    idList.clear();
    idList.append(QMessageId(sms_prefix+"123"));
    idList.append(QMessageId(sms_prefix+"124"));
    filter = QMessageFilter::byId(idList, QMessageDataComparator::Includes);
    QCOMPARE(MessagingHelper::preFilter(filter, QMessage::Email), false);
    QCOMPARE(MessagingHelper::preFilter(filter, QMessage::Sms), true);

    filter = QMessageFilter::byId(idList, QMessageDataComparator::Excludes);
    QCOMPARE(MessagingHelper::preFilter(filter, QMessage::Email), true);
    QCOMPARE(MessagingHelper::preFilter(filter, QMessage::Sms), true);

    idList.clear();
    idList.append(QMessageId(email_prefix+"123"));
    idList.append(QMessageId(sms_prefix+"124"));
    filter = QMessageFilter::byId(idList, QMessageDataComparator::Includes);
    QCOMPARE(MessagingHelper::preFilter(filter, QMessage::Email), true);
    QCOMPARE(MessagingHelper::preFilter(filter, QMessage::Sms), true);

    filter = QMessageFilter::byId(idList, QMessageDataComparator::Excludes);
    QCOMPARE(MessagingHelper::preFilter(filter, QMessage::Email), true);
    QCOMPARE(MessagingHelper::preFilter(filter, QMessage::Sms), true);
}
void tst_QMessageFilter::testIdFilter()
{
#if defined(Q_WS_MAEMO_5)
    QMessage message;
    QMessagePrivate* privateMessage = QMessagePrivate::implementation(message);
    privateMessage->_id = QMessageId("123");

    QMessageFilter filter = QMessageFilter::byId(QMessageId("123"), QMessageDataComparator::Equal);
    QMessageFilterPrivate* pf = QMessageFilterPrivate::implementation(filter);
    QCOMPARE(pf->filter(message), true);

    filter = QMessageFilter::byId(QMessageId("124"), QMessageDataComparator::Equal);
    pf = QMessageFilterPrivate::implementation(filter);
    QCOMPARE(pf->filter(message), false);

    filter = QMessageFilter::byId(QMessageId("123"), QMessageDataComparator::NotEqual);
    pf = QMessageFilterPrivate::implementation(filter);
    QCOMPARE(pf->filter(message), false);

    filter = QMessageFilter::byId(QMessageId("124"), QMessageDataComparator::NotEqual);
    pf = QMessageFilterPrivate::implementation(filter);
    QCOMPARE(pf->filter(message), true);

    QMessageIdList idList;
    idList.append(QMessageId("123"));
    idList.append(QMessageId("124"));
    idList.append(QMessageId("125"));
    filter = QMessageFilter::byId(idList, QMessageDataComparator::Includes);
    pf = QMessageFilterPrivate::implementation(filter);
    QCOMPARE(pf->filter(message), true);

    filter = QMessageFilter::byId(idList, QMessageDataComparator::Excludes);
    pf = QMessageFilterPrivate::implementation(filter);
    QCOMPARE(pf->filter(message), false);

    idList.clear();
    idList.append(QMessageId("124"));
    idList.append(QMessageId("125"));
    idList.append(QMessageId("126"));
    filter = QMessageFilter::byId(idList, QMessageDataComparator::Includes);
    pf = QMessageFilterPrivate::implementation(filter);
    QCOMPARE(pf->filter(message), false);

    filter = QMessageFilter::byId(idList, QMessageDataComparator::Excludes);
    pf = QMessageFilterPrivate::implementation(filter);
    QCOMPARE(pf->filter(message), true);
#endif
}
Пример #13
0
bool QMessageService::moveMessages(const QMessageIdList &messageIds, const QMessageFolderId &toFolderId)
{
    if (d_ptr->_active) {
        return false;
    }
    
    if (!toFolderId.isValid()) {
        d_ptr->_error = QMessageManager::InvalidId;
        return false;
    }

    const int count = messageIds.count();
    if ( count == 0) {
        return false;
    }

    // verify that messages are of same type and valid
    EngineType expectedType = idType(messageIds[0]);
    for( int i = 1; i < count; ++i ) {
        if( idType( messageIds[i] ) != expectedType || 
            !messageIds[i].isValid() ) {
            // invalid message id or inconsistent type found
            d_ptr->_error = QMessageManager::InvalidId;
            return false;
        }
    }

    d_ptr->_active = true;
    d_ptr->_error = QMessageManager::NoError;
    d_ptr->_state = QMessageService::ActiveState;
    emit stateChanged(d_ptr->_state);

    bool retVal = d_ptr->moveMessages( messageIds, toFolderId );
    if (!retVal) {
        d_ptr->setFinished(retVal);
    }
    return retVal;
}
Пример #14
0
bool QMessageServicePrivate::moveMessages(const QMessageIdList &messageIds, const QMessageFolderId &toFolderId)
{
    bool ret = false;
    // it'a already verified that messageIds has elements and they are of same type
    switch (idType(messageIds.at(0))) {
        case EngineTypeFreestyle: {
#ifdef FREESTYLEMAILMAPI12USED
            ret = CFSEngine::instance()->moveMessages( *this, messageIds, toFolderId );
#else
            // not supported
            ret = false;
#endif
            break;
        }
        case EngineTypeMTM: // flow through
        default: {
            // not supported
            ret = false;
            break;
        }
    }
    return ret;
}
Пример #15
0
void QMessageServicePrivate::messagesFound(const QMessageIdList &ids, bool isFiltered, bool isSorted)
{
    _pendingRequestCount--;

    if (!isFiltered) {
        _filtered = false;
    }

    if (!isSorted) {
        _sorted = false;
    } else {
        if ((ids.count() > 0) && (_ids.count() > 0)) {
            _sorted = false;
        }
    }

    _ids.append(ids);

    if (_pendingRequestCount == 0) {
        if (!_filtered) {
            MessagingHelper::filterMessages(_ids, _filter);
        }
        if (!_sorted) {
            MessagingHelper::orderMessages(_ids, _sortOrder);
        }
        MessagingHelper::applyOffsetAndLimitToMessageIdList(_ids, _limit, _offset);

        emit q_ptr->messagesFound(_ids);

        setFinished(true);

        _ids.clear();
        _filter = QMessageFilter();
        _sortOrder = QMessageSortOrder();
    }
}
Пример #16
0
void MessagingHelper::applyOffsetAndLimitToMessageIdList(QMessageIdList& messageIds, int limit, int offset)
{
    if (messageIds.count() == 0) {
        return;
    }

    if (offset > 0) {
        if (offset > messageIds.count()) {
            messageIds.clear();
        } else {
            for (int i = 0; i < offset; i++) {
                messageIds.removeFirst();
            }
        }
    }
    if (limit > 0) {
        for (int i = messageIds.count()-1; i >= limit; i--) {
            messageIds.removeAt(i);
        }
    }
}