bool QMFService::compose(const QMessage &message)
{
    if (isBusy()) {
        return false;
    }
    m_active = 0;
    setError(QMessageManager::NoError);

    QStringList arguments;
    if (message.subject().size())
        arguments << "--subject" << message.subject();

    if (message.textContent().size())
        arguments << "--body" << message.textContent();

    if (message.cc().size())
        arguments << "--cc" << MessagingHelper::addressListToString(message.cc());

    if (message.bcc().size())
        arguments << "--bcc" << MessagingHelper::addressListToString(message.bcc());

    if (message.to().size())
        arguments <<  MessagingHelper::addressListToString(message.to());

    //qDebug() << __PRETTY_FUNCTION__ << " starting:" << XDG_PROG << arguments;

    if (QProcess::execute(XDG_PROG, arguments) != 0) {
        qWarning() << __PRETTY_FUNCTION__ << "Cannot start email composer: " << XDG_PROG << arguments;
        setError(QMessageManager::FrameworkFault);
        return false;
    }

    //qDebug() << __PRETTY_FUNCTION__ << "execution completed";

    return true;
}
Example #2
0
bool QMessageService::send(QMessage &message)
{
	if (d_ptr->_active) {
		return false;
	}
	
	d_ptr->_active = true;
	d_ptr->_error = QMessageManager::NoError;
	
    bool retVal = true;	
    
    d_ptr->_state = QMessageService::ActiveState;
    emit stateChanged(d_ptr->_state);
    
    QMessageAccountId accountId = message.parentAccountId();
    QMessage::Type msgType = QMessage::NoType;

    // Check message type
    if (message.type() == QMessage::AnyType || message.type() == QMessage::NoType) {
        QMessage::TypeFlags types = QMessage::NoType;
        if (accountId.isValid()) {
            // ParentAccountId was defined => Message type can be read
            // from parent account
            QMessageAccount account = QMessageAccount(accountId);
            QMessage::TypeFlags types = account.messageTypes();
            if (types & QMessage::Sms) {
                msgType = QMessage::Sms;
            } else if (types & QMessage::Mms) {
                msgType = QMessage::Mms;
            } else if (types & QMessage::Email) {
                msgType = QMessage::Email;
            }
        }
        if (msgType == QMessage::NoType) {
            d_ptr->_error = QMessageManager::ConstraintFailure;
            retVal = false;
        }
    }

    if (retVal) {
        // Check account
        if (!accountId.isValid()) {
            accountId = QMessageAccount::defaultAccount(message.type());
            if (!accountId.isValid()) {
                d_ptr->_error = QMessageManager::InvalidId;
                retVal = false;
            }
        }
    }

    QMessageAccount account(accountId);
    if (retVal) {
        // Check account/message type compatibility
        if (!(account.messageTypes() & message.type()) && (msgType == QMessage::NoType)) {
            d_ptr->_error = QMessageManager::ConstraintFailure;
            retVal = false;
        }
    }
    
    if (retVal) {
        // Check recipients
        QMessageAddressList recipients = message.to() + message.bcc() + message.cc();
        if (recipients.isEmpty()) {
            d_ptr->_error = QMessageManager::ConstraintFailure;
            return false;
        }
    }
    
    if (retVal) {
        QMessage outgoing(message);

        // Set default account if unset
        if (!outgoing.parentAccountId().isValid()) {
            outgoing.setParentAccountId(accountId);
        }

        if (outgoing.type() == QMessage::AnyType || outgoing.type() == QMessage::NoType) {
            outgoing.setType(msgType);
        }

        if (account.messageTypes() & QMessage::Sms) {
            retVal = d_ptr->sendSMS(outgoing);
        } else if (account.messageTypes() & QMessage::Mms) {
            retVal = d_ptr->sendMMS(outgoing);
        } else if (account.messageTypes() & QMessage::Email) {
            retVal = d_ptr->sendEmail(outgoing);
        }

        QMessagePrivate* privateMessage = QMessagePrivate::implementation(message);
        privateMessage->_id = outgoing.id();
    }
    
    if (retVal == false) {
        d_ptr->setFinished(retVal);
    }
    return retVal;
}
bool QMessageFilterPrivate::filter(const QMessage &message, const QMessageFilterPrivate &filter)
{
    if ((filter._field == QMessageFilterPrivate::None) &&
        (filter._filterList.count() == 0)) {
        if (filter._notFilter) {
            return false;
        } else {
            return true;
        }
    }

    Qt::CaseSensitivity caseSensitivity = (filter._matchFlags & QMessageDataComparator::MatchCaseSensitive) ? Qt::CaseSensitive : Qt::CaseInsensitive;

    switch (filter._field) {
    case QMessageFilterPrivate::Id:
        {
        if (filter._comparatorType == QMessageFilterPrivate::Equality) {
            QMessageDataComparator::EqualityComparator cmp(static_cast<QMessageDataComparator::EqualityComparator>(filter._comparatorValue));
            if (cmp == QMessageDataComparator::Equal) {
                if (message.id().toString() == filter._value.toString()) {
                    return true;
                }
            } else { // NotEqual
                if (message.id().toString() != filter._value.toString()) {
                    return true;
                }
            }
        } else if (filter._comparatorType == QMessageFilterPrivate::Inclusion) {
            QMessageDataComparator::InclusionComparator cmp(static_cast<QMessageDataComparator::InclusionComparator>(filter._comparatorValue));
            if (filter._ids.count() > 0) { // QMessageIdList
               if (cmp == QMessageDataComparator::Includes) {
                   if (filter._ids.contains(message.id())) {
                       return true;
                   }
               } else { // Excludes
                   if (!filter._ids.contains(message.id())) {
                       return true;
                   }
               }
            } else { // QMessageFilter
               if (cmp == QMessageDataComparator::Includes) {
                   // TODO:
               } else { // Excludes
                   // TODO:
               }
            }
        }        
        break;
        }
    case QMessageFilterPrivate::Type:
        {
        QMessage::Type type = static_cast<QMessage::Type>(filter._value.toInt());
        if (filter._comparatorType == QMessageFilterPrivate::Equality) {
            QMessageDataComparator::EqualityComparator cmp(static_cast<QMessageDataComparator::EqualityComparator>(filter._comparatorValue));
            if (cmp == QMessageDataComparator::Equal) {
                if (message.type() == type) {
                    return true;
                }
            } else { // NotEqual
                if (message.type() != type) {
                    return true;
                }
            }
        } else if (filter._comparatorType == QMessageFilterPrivate::Inclusion) {
            QMessageDataComparator::InclusionComparator cmp(static_cast<QMessageDataComparator::InclusionComparator>(filter._comparatorValue));
            if (cmp == QMessageDataComparator::Includes) {
                if ((message.type() & type) == message.type()) {
                    return true;
                }
            } else { // Excludes
            if ((message.type() & type) == 0) {
                    return true;
                }
            }
        }
        break;
        }
    case QMessageFilterPrivate::Sender:
        {
        if (filter._comparatorType == QMessageFilterPrivate::Equality) {
            QMessageDataComparator::EqualityComparator cmp(static_cast<QMessageDataComparator::EqualityComparator>(filter._comparatorValue));
            if (cmp == QMessageDataComparator::Equal) {
                if (filter._value.toString().length() > 0) {
                    if (message.from().addressee().compare(filter._value.toString(),caseSensitivity) == 0) {
                        return true;
                    }
                }
            } else { // NotEqual
                if (filter._value.toString().length() > 0) {
                    if (message.from().addressee().compare(filter._value.toString(),caseSensitivity) != 0) {
                        return true;
                    }
                } else {
                    return true;
                }
            }
        } else if (filter._comparatorType == QMessageFilterPrivate::Inclusion) {
            QMessageDataComparator::InclusionComparator cmp(static_cast<QMessageDataComparator::InclusionComparator>(filter._comparatorValue));
            if (cmp == QMessageDataComparator::Includes) {
                if (message.from().addressee().contains(filter._value.toString(),caseSensitivity)) {
                    return true;
                }
            } else { // Excludes
            if (!message.from().addressee().contains(filter._value.toString(),caseSensitivity)) {
                    return true;
                }
            }
        }
        break;
        }
    case QMessageFilterPrivate::Recipients: // to, cc & bcc fields
        {
        if (filter._comparatorType == QMessageFilterPrivate::Inclusion) {
            QMessageDataComparator::InclusionComparator cmp(static_cast<QMessageDataComparator::InclusionComparator>(filter._comparatorValue));
            bool includes = false;
            // Check to addresses
            QMessageAddressList addrList = message.to();
            for (int i=0; i < addrList.count(); i++) {
                if (addrList[i].addressee().contains(filter._value.toString(),caseSensitivity)) {
                    includes = true;
                    break;
                }
            }
            if (!includes) {
                // Check cc addresses
                addrList = message.cc();
                for (int i=0; i < addrList.count(); i++) {
                    if (addrList[i].addressee().contains(filter._value.toString(),caseSensitivity)) {
                        includes = true;
                        break;
                    }
                }
            }
            if (!includes) {
                // Check bcc addresses
                addrList = message.bcc();
                for (int i=0; i < addrList.count(); i++) {
                    if (addrList[i].addressee().contains(filter._value.toString(),caseSensitivity)) {
                        includes = true;
                        break;
                    }
                }
            }
            if (cmp == QMessageDataComparator::Includes) {
                if (includes) {
                    return true;
                }
            } else { // Excludes
                if (!includes) {
                    return true;
                }
            }
        }
        break;
        }
    case QMessageFilterPrivate::Subject:
        {
        if (filter._comparatorType == QMessageFilterPrivate::Equality) {
            QMessageDataComparator::EqualityComparator cmp(static_cast<QMessageDataComparator::EqualityComparator>(filter._comparatorValue));
            if (cmp == QMessageDataComparator::Equal) {
                if (filter._value.toString().length() > 0) {
                    if (message.subject().compare(filter._value.toString(),caseSensitivity) == 0) {
                        return true;
                    }
                }
            } else { // NotEqual
                if (filter._value.toString().length() > 0) {
                    if (message.subject().compare(filter._value.toString(),caseSensitivity) != 0) {
                        return true;
                    }
                } else {
                    return true;
                }
            }
        } else if (filter._comparatorType == QMessageFilterPrivate::Inclusion) {
            QMessageDataComparator::InclusionComparator cmp(static_cast<QMessageDataComparator::InclusionComparator>(filter._comparatorValue));
            if (cmp == QMessageDataComparator::Includes) {
                if (message.subject().contains(filter._value.toString(),caseSensitivity)) {
                    return true;
                }
            } else { // Excludes
            if (!message.subject().contains(filter._value.toString(),caseSensitivity)) {
                    return true;
                }
            }
        }
        break;
        }
    case QMessageFilterPrivate::TimeStamp:
        {
        if (filter._comparatorType == QMessageFilterPrivate::Equality) {
            QMessageDataComparator::EqualityComparator cmp(static_cast<QMessageDataComparator::EqualityComparator>(filter._comparatorValue));
            if (cmp == QMessageDataComparator::Equal) {
                if (message.date() == filter._value.toDateTime()) {
                    return true;
                }
            } else { // NotEqual
                if (message.date() != filter._value.toDateTime()) {
                    return true;
                }
            }
        } else if (filter._comparatorType == QMessageFilterPrivate::Relation) {
            QMessageDataComparator::RelationComparator cmp(static_cast<QMessageDataComparator::RelationComparator>(filter._comparatorValue));
            if (cmp == QMessageDataComparator::LessThan) {
                if (message.date() < filter._value.toDateTime()) {
                    return true;
                }
            } else if (cmp == QMessageDataComparator::LessThanEqual) {
                if (message.date() <= filter._value.toDateTime()) {
                    return true;
                }
            } else if (cmp == QMessageDataComparator::GreaterThan) {
                if (message.date() > filter._value.toDateTime()) {
                    return true;
                }
            } else { // GreaterThanEqual
                if (message.date() >= filter._value.toDateTime()) {
                    return true;
                }
            }
        }
        break;
        }
    case QMessageFilterPrivate::ReceptionTimeStamp:
        {
        if (filter._comparatorType == QMessageFilterPrivate::Equality) {
            QMessageDataComparator::EqualityComparator cmp(static_cast<QMessageDataComparator::EqualityComparator>(filter._comparatorValue));
            if (cmp == QMessageDataComparator::Equal) {
                if (message.date() == filter._value.toDateTime()) {
                    return true;
                }
            } else { // NotEqual
                if (message.date() != filter._value.toDateTime()) {
                    return true;
                }
            }
        } else if (filter._comparatorType == QMessageFilterPrivate::Relation) {
            QMessageDataComparator::RelationComparator cmp(static_cast<QMessageDataComparator::RelationComparator>(filter._comparatorValue));
            if (cmp == QMessageDataComparator::LessThan) {
                if (message.receivedDate() < filter._value.toDateTime()) {
                    return true;
                }
            } else if (cmp == QMessageDataComparator::LessThanEqual) {
                if (message.receivedDate() <= filter._value.toDateTime()) {
                    return true;
                }
            } else if (cmp == QMessageDataComparator::GreaterThan) {
                if (message.receivedDate() > filter._value.toDateTime()) {
                    return true;
                }
            } else { // GreaterThanEqual
                if (message.receivedDate() >= filter._value.toDateTime()) {
                    return true;
                }
            }
        }
        break;
        }
    case QMessageFilterPrivate::Status:
        {
        if (filter._comparatorType == QMessageFilterPrivate::Equality) {
            QMessageDataComparator::EqualityComparator cmp(static_cast<QMessageDataComparator::EqualityComparator>(filter._comparatorValue));
            if (filter._value.toInt() == 0) {
                if (cmp == QMessageDataComparator::Equal) {
                    return false;
                } else {
                    return true;
                }
            }
            QMessage::Status status = static_cast<QMessage::Status>(filter._value.toInt());
            if (cmp == QMessageDataComparator::Equal) {
                if ((message.status() & status) == status) {
                    return true;
                }
            } else { // NotEqual
                if (!((message.status() & status) == status)) {
                    return true;
                }
            }
        } else if (filter._comparatorType == QMessageFilterPrivate::Inclusion) {
            QMessageDataComparator::InclusionComparator cmp(static_cast<QMessageDataComparator::InclusionComparator>(filter._comparatorValue));
            if (filter._value.toInt() == 0) {
                if (cmp == QMessageDataComparator::Includes) {
                    if (filter._notFilterForComparator) {
                        return true;
                    } else {
                        return false;
                    }
                } else {
                    if (filter._notFilterForComparator) {
                        return true;
                    } else {
                        return false;
                    }
                }
            }
            if (cmp == QMessageDataComparator::Includes) {
                if ((message.status() | filter._value.toInt()) == message.status()) {
                    if (filter._notFilterForComparator) {
                        return false;
                    } else { 
                        return true;
                    }
                } else {
                    if (filter._notFilterForComparator) {
                        return true;
                    }
                }
            } else { // Excludes
                int mask = 15 - filter._value.toInt(); // 15 = 0b1111
                if ((message.status() & mask) == message.status()) {
                    if (filter._notFilterForComparator) {
                        return false;
                    } else { 
                        return true;
                    }
                } else {
                    if (filter._notFilterForComparator) {
                        return true;
                    }
                }
            }
        }
        break;
        }
    case QMessageFilterPrivate::Priority:
        {
        QMessageDataComparator::EqualityComparator cmp(static_cast<QMessageDataComparator::EqualityComparator>(filter._comparatorValue));
        if (cmp == QMessageDataComparator::Equal) {
            if (message.priority() == filter._value.toInt()) {
                return true;
            }
        } else { // NotEqual
            if (message.priority() != filter._value.toInt()) {
                return true;
            }
        }
        break;
        }
    case QMessageFilterPrivate::Size:
        {
        if (filter._comparatorType == QMessageFilterPrivate::Equality) {
            QMessageDataComparator::EqualityComparator cmp(static_cast<QMessageDataComparator::EqualityComparator>(filter._comparatorValue));
            if (cmp == QMessageDataComparator::Equal) {
                if (message.size() == filter._value.toInt()) {
                    return true;
                }
            } else { // NotEqual
                if (message.size() != filter._value.toInt()) {
                    return true;
                }
            }
        } else if (filter._comparatorType == QMessageFilterPrivate::Relation) {
            QMessageDataComparator::RelationComparator cmp(static_cast<QMessageDataComparator::RelationComparator>(filter._comparatorValue));
            if (cmp == QMessageDataComparator::LessThan) {
                if (message.size() < filter._value.toInt()) {
                    return true;
                }
            } else if (cmp == QMessageDataComparator::LessThanEqual) {
                if (message.size() <= filter._value.toInt()) {
                    return true;
                }
            } else if (cmp == QMessageDataComparator::GreaterThan) {
                if (message.size() > filter._value.toInt()) {
                    return true;
                }
            } else { // GreaterThanEqual
                if (message.size() >= filter._value.toInt()) {
                    return true;
                }
            }
        }
        break;
        }        
    case QMessageFilterPrivate::ParentAccountId:
        {
        if (filter._comparatorType == QMessageFilterPrivate::Equality) {
            QMessageDataComparator::EqualityComparator cmp(static_cast<QMessageDataComparator::EqualityComparator>(filter._comparatorValue));
            if (cmp == QMessageDataComparator::Equal) {
                if (message.parentAccountId().toString() == filter._value.toString()) {
                    return true;
                }
            } else { // NotEqual
                if (message.parentAccountId().toString() != filter._value.toString()) {
                    return true;
                }
            }
        } else if (filter._comparatorType == QMessageFilterPrivate::Inclusion) {
            QMessageDataComparator::InclusionComparator cmp(static_cast<QMessageDataComparator::InclusionComparator>(filter._comparatorValue));
            if (cmp == QMessageDataComparator::Includes) {
                //TODO:
            } else { // Excludes
                //TODO:
            }
        }
        break;
        }
    case QMessageFilterPrivate::StandardFolder:
        {
        QMessageDataComparator::EqualityComparator cmp(static_cast<QMessageDataComparator::EqualityComparator>(filter._comparatorValue));
        QMessage::StandardFolder standardFolder = static_cast<QMessage::StandardFolder>(filter._value.toInt()); 
        if (cmp == QMessageDataComparator::Equal) {
            if (message.standardFolder() == standardFolder) {
                return true;
            }
        } else { // NotEqual
            if (message.standardFolder() != standardFolder) {
                return true;
            }
        }
        break;
        }
    case QMessageFilterPrivate::ParentFolderId:
        {
        if (filter._comparatorType == QMessageFilterPrivate::Equality) {
            QMessageDataComparator::EqualityComparator cmp(static_cast<QMessageDataComparator::EqualityComparator>(filter._comparatorValue));
            if (cmp == QMessageDataComparator::Equal) {
                if (message.parentFolderId().toString() == filter._value.toString()) {
                    return true;
                }
            } else { // NotEqual
                if (message.parentFolderId().toString() != filter._value.toString()) {
                    return true;
                }
            }
        } else if (filter._comparatorType == QMessageFilterPrivate::Inclusion) {
            QMessageDataComparator::InclusionComparator cmp(static_cast<QMessageDataComparator::InclusionComparator>(filter._comparatorValue));
            if (cmp == QMessageDataComparator::Includes) {
                // TODO:
            } else { // Excludes
                // TODO:
            }
        }
        break;
        }
    case QMessageFilterPrivate::AncestorFolderIds:
        {
        if (filter._comparatorType == QMessageFilterPrivate::Inclusion) {
            QMessageDataComparator::InclusionComparator cmp(static_cast<QMessageDataComparator::InclusionComparator>(filter._comparatorValue));
            if (!filter._value.isNull()) { // QMessageFolderId
                if (cmp == QMessageDataComparator::Includes) {
                    // TODO:
                } else { // Excludes
                    // TODO:
                }
            } else { // QMessageFolderFilter
                if (cmp == QMessageDataComparator::Includes) {
                    // TODO:
                } else { // Excludes
                    // TODO:
                }
            }
        }
        break;
        }
    case QMessageFilterPrivate::ParentAccountIdFilter:
    case QMessageFilterPrivate::ParentFolderIdFilter:
    case QMessageFilterPrivate::None:
        break;
    }

    return false;
}