MessageHandlerAsyncResult Handler::doHandle(Message &message) { if (!m_enabled || message.property("service", false)) { return makeAsyncResult(Accept, QString()); } Contact *contact = qobject_cast<Contact*>(message.chatUnit()->buddy()); if (!contact || contact->isInList()) { return makeAsyncResult(Accept, QString()); } Info::Ptr info = contact->property(ANTISPAM_PROPERTY).value<Info::Ptr>(); if (info.isNull()) { info = Info::Ptr::create(); contact->setProperty(ANTISPAM_PROPERTY, qVariantFromValue(info)); } if (info->trusted) { return makeAsyncResult(Accept, QString()); } if (!message.isIncoming()) { if (!message.property("autoreply", false)) info->trusted = true; return makeAsyncResult(Accept, QString()); } //check message body foreach (const QString &answer, m_answers) { if (message.text().compare(answer, Qt::CaseInsensitive) == 0) { Message message(m_success); message.setChatUnit(contact); contact->sendMessage(message); info->trusted = true; return makeAsyncResult(Accept, QString()); } } if (info->lastQuestionTime.isValid() && qAbs(info->lastQuestionTime.secsTo(QDateTime::currentDateTime())) < 5 * 60) { return makeAsyncResult(Reject, QString()); } Message replyMessage(m_question); replyMessage.setChatUnit(contact); replyMessage.setProperty("autoreply", true); contact->sendMessage(replyMessage); info->lastQuestionTime = QDateTime::currentDateTime(); QString reason = tr("Message from %1 blocked on suspicion of spam."). arg(contact->title()); return makeAsyncResult(Error, reason); }
MessageHandlerAsyncResult MetaContactMessageHandler::doHandle(Message &message) { if (message.isIncoming() && !qobject_cast<MetaContactImpl*>(message.chatUnit())) { Q_ASSERT(message.chatUnit()); if (MetaContactImpl *contact = qobject_cast<MetaContactImpl*>(message.chatUnit()->metaContact())) { Contact *rawContact = 0; ChatUnit *u = message.chatUnit(); while (u) { if ((rawContact = qobject_cast<Contact*>(u))) break; u = u->upperUnit(); } if (rawContact && contact->getActiveContact() != rawContact) contact->setActiveContact(rawContact); } } return makeAsyncResult(Accept, QString()); }