Esempio n. 1
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);
                }
            }
        }
    }
}
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;
            }
        }
    }
Esempio n. 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;
}
Esempio n. 4
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);
        }
    }
}
Esempio n. 5
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;
}
Esempio n. 6
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;
}
Esempio n. 7
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;
}
Esempio n. 8
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();
    }
}