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
}
Example #3
0
QMessageIdList convert(const QList<QMailMessageId> &ids)
{
    QMessageIdList result;

    foreach (const QMailMessageId &id, ids) {
        result.append(convert(id));
    }
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;
            }
        }
    }