void tst_QMessageFilter::testComplexFiltersPreFilter()
{
    QMessageFilter filter1 = QMessageFilter::byId(QMessageId(email_prefix+"123"), QMessageDataComparator::Equal);
    QMessageFilter filter2 = QMessageFilter::byId(QMessageId(sms_prefix+"123"), QMessageDataComparator::Equal);
    QMessageFilter filter3 = QMessageFilter::byType(QMessage::Email, QMessageDataComparator::Equal);
    QMessageFilter filter4 = QMessageFilter::byType(QMessage::Sms, QMessageDataComparator::Equal);
    QMessageFilter filter5 = QMessageFilter::byType(QMessage::Mms, QMessageDataComparator::Equal);
    QMessageFilter filter6 = QMessageFilter::byReceptionTimeStamp(QDateTime::fromString("1999-04-01T10:31:00Z", Qt::ISODate), QMessageDataComparator::Equal);
    QMessageFilter filter7 = QMessageFilter::byStatus(QMessage::HasAttachments, QMessageDataComparator::NotEqual);

    QMessageFilter complexFilter = (filter1 & filter6) | filter3;
    QCOMPARE(MessagingHelper::preFilter(complexFilter, QMessage::Email), true);
    QCOMPARE(MessagingHelper::preFilter(complexFilter, QMessage::Sms), false);

    complexFilter = (filter4 & filter6) | (filter2 & filter7);
    QCOMPARE(MessagingHelper::preFilter(complexFilter, QMessage::Email), false);
    QCOMPARE(MessagingHelper::preFilter(complexFilter, QMessage::Sms), true);

    complexFilter = filter3 | (filter2 & filter7);
    QCOMPARE(MessagingHelper::preFilter(complexFilter, QMessage::Email), true);
    QCOMPARE(MessagingHelper::preFilter(complexFilter, QMessage::Sms), true);

    complexFilter = (filter1 & filter6) | (filter4 & filter6);
    QCOMPARE(MessagingHelper::preFilter(complexFilter, QMessage::Email), true);
    QCOMPARE(MessagingHelper::preFilter(complexFilter, QMessage::Sms), true);

    complexFilter = (filter5 & filter6) | (filter5 & filter7);
    QCOMPARE(MessagingHelper::preFilter(complexFilter, QMessage::Email), false);
    QCOMPARE(MessagingHelper::preFilter(complexFilter, QMessage::Sms), false);


}
 QMessageId stripIdPrefix(const QMessageId& id)
 {
     if (id.toString().startsWith(freestylePrefix))
         return QMessageId(id.toString().right(id.toString().length() - QString(freestylePrefix).length()));
     else if (id.toString().startsWith(mtmPrefix))
         return QMessageId(id.toString().right(id.toString().length() - QString(mtmPrefix).length()));
     else
         return QMessageId(id);
 }
Example #3
0
 QMessageId addIdPrefix(const QMessageId& id, const EngineType& type)
 {
     switch (type) {
     case EngineTypeFreestyle:
         Q_ASSERT(!id.toString().startsWith(freestylePrefix));
         return QMessageId(freestylePrefix + id.toString());
     case EngineTypeMTM:
         Q_ASSERT(!id.toString().startsWith(mtmPrefix));
         return QMessageId(mtmPrefix + id.toString());
     default:
         return QMessageId(id);
     }
 }
QByteArray QMessageContentContainer::content() const
{
    if (d_ptr->_content.isEmpty() && d_ptr->_id.isValid()) {
	d_ptr->_content = QMFStore::instance()->getMimePart(QMessageId(d_ptr->_containingMessageId), d_ptr->_id);
        d_ptr->_size = d_ptr->_content.size();
    }

    return d_ptr->_content;
}
QMessage EventLoggerEngine::eventToMessage(RTComElEvent & ev)
{

    QMessage message;

    if (!strcmp(ev.fld_service, "RTCOM_EL_SERVICE_SMS")) {
        message.setType(QMessage::Sms);
    } else if (!strcmp(ev.fld_service,"RTCOM_EL_SERVICE_CHAT")) {
        message.setType(QMessage::InstantMessage);
    } else {
        message.setType(QMessage::NoType);  // Other type, as exampele voice Call
    };

    message.setParentAccountId(QMessageAccountId(QString("y/Account/%1").arg(ev.fld_local_uid)));

    if (!ev.fld_is_read) {
        message.setStatus(QMessage::Read);
    };
    message.setPriority(QMessage::NormalPriority);
    message.setDate(QDateTime::fromTime_t(ev.fld_start_time));
    message.setReceivedDate(QDateTime::fromTime_t(ev.fld_start_time));
    if (ev.fld_outgoing) QMessagePrivate::setStandardFolder(message,QMessage::SentFolder);
    else
      QMessagePrivate::setStandardFolder(message,QMessage::InboxFolder);
    //    qDebug() << "event_type:"  << ev.fld_event_type << ev.fld_event_type_id << "Outgoing:" << ev.fld_outgoing << " Folder:" << message.standardFolder();

    if (ev.fld_outgoing) {
        // Outgoing message
        message.setFrom(QMessageAddress(QMessageAddress::Phone, QString(ev.fld_local_uid)));
        QMessagePrivate::setSenderName(message, QString(ev.fld_local_uid));
        message.setTo(QMessageAddress(QMessageAddress::Phone, QString(ev.fld_remote_uid)));
    } else {
        // Incoming message
        message.setFrom(QMessageAddress(QMessageAddress::Phone, QString(ev.fld_remote_uid)));
        QMessagePrivate::setSenderName(message, QString(ev.fld_remote_uid));
        QMessageAddressList messageAddresslist;
        messageAddresslist.append(QMessageAddress(QMessageAddress::Phone, QString(ev.fld_local_uid)));
        message.setTo(messageAddresslist);
    }

    message.setBody(QString::fromUtf8(ev.fld_free_text));
    QMessagePrivate* privateMessage = QMessagePrivate::implementation(message);
    privateMessage->_id = QMessageId(QString("el")+QString::number(ev.fld_id));
    privateMessage->_modified = false;
    // qDebug() << "id:" << message.id().toString() << "From:" << message.from().addressee() << "Text:" << message.textContent();
    return message;

}
//! [handle-response]
void MessageSender::stateChanged(QMessageService::State newState)
{
    if (newState == QMessageService::FinishedState) {
        if (service.error() == QMessageManager::NoError) {
            QMessageBox::information(0, tr("Success"), tr("Message sent successfully"));
        } else {
            QMessageBox::warning(0, tr("Failed"), tr("Unable to send message"));

            // Try to delete the failed message
            if (!manager.removeMessage(sendId)) {
                qWarning() << "Unable to remove failed message:" << sendId.toString();
            }
        }

        sendId = QMessageId();
        sendButton->setEnabled(true);
    }
}
QString QMessageContentContainer::textContent() const
{
    if (d_ptr->_textContent.isEmpty() && d_ptr->_id.isValid()) {
	d_ptr->_textContent = QMFStore::instance()->getMimePart(QMessageId(d_ptr->_containingMessageId), d_ptr->_id);
        d_ptr->_size = d_ptr->_textContent.size();
    }

    if (!d_ptr->_textContent.isEmpty()) {
        return d_ptr->_textContent;
    }

    QTextCodec *codec = QTextCodec::codecForName(d_ptr->_charset.data());
    if (codec) {
        return codec->toUnicode(d_ptr->_content);
    } else {
        return QString::fromLatin1(d_ptr->_content);
    }
}
Example #8
0
QMessageId convert(const QMailMessageId &id)
{
    return QMessageId(prefixIdentifier(QString::number(id.toULongLong())));
}
QMessageId addMessage(const Parameters &params)
{
    Q_UNUSED(params);
    return QMessageId();
}
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
}