Hello.

Kopete has no anti-spam functions, so i wrote this small patch. With it kopete 
can reject messages from contacts which are not in contact list. 

Currently works only with ICQ protocol.

Closes bug #83841.

Kopete version: 0.12.7
--- /protocols/oscar/icq/icqaccount.cpp	2008-02-13 14:37:43.000000000 +0500
+++ /protocols/oscar/icq/icqaccount.cpp	2008-06-21 19:49:56.000000000 +0500
@@ -23,9 +23,11 @@
 #include <kpopupmenu.h>
 #include <kmdcodec.h>
 #include <kmessagebox.h>
+#include <kpassivepopup.h>
 
 #include "kopeteawayaction.h"
 #include "kopetemessage.h"
+#include "kopetemetacontact.h"
 #include "kopetecontactlist.h"
 #include "kopeteuiglobal.h"
 
@@ -86,6 +88,7 @@
 	QString nickName = configGroup()->readEntry("NickName", QString::null);
 	mWebAware = configGroup()->readBoolEntry( "WebAware", false );
 	mHideIP = configGroup()->readBoolEntry( "HideIP", true );
+	mReceiveFromList = configGroup()->readBoolEntry( "ReceiveFromList", false );
 	mInitialStatusMessage = QString::null;
 
 	QObject::connect( Kopete::ContactList::self(), SIGNAL( globalIdentityChanged( const QString&, const QVariant& ) ),
@@ -172,6 +175,7 @@
 		Oscar::Settings* oscarSettings = engine()->clientSettings();
 		oscarSettings->setWebAware( configGroup()->readBoolEntry( "WebAware", false ) );
 		oscarSettings->setHideIP( configGroup()->readBoolEntry( "HideIP", true ) );
+		oscarSettings->setReceiveFromList( configGroup()->readBoolEntry( "ReceiveFromList", false ) );
 		//FIXME: also needed for the other call to setStatus (in setPresenceTarget)
 		DWORD status = pres.toOscarStatus();
 
@@ -212,6 +216,37 @@
 }
 
 
+void ICQAccount::settingsChanged()
+{
+	mReceiveFromList = configGroup()->readBoolEntry( "ReceiveFromList", false );
+}
+
+void ICQAccount::messageReceived( const Oscar::Message& message )
+{
+	bool rejectMessage = false;
+	if ( ( mReceiveFromList) & ( message.properties() == Oscar::Message::Normal ) )
+	{
+		QString sender = Oscar::normalize( message.sender() );
+		if 	( contacts()[sender] ) 
+		{
+			OscarContact* ocSender = static_cast<OscarContact *> ( contacts()[sender] ); 
+			if ( ocSender->metaContact()->isTemporary() )
+				rejectMessage = true;
+		}
+		else
+			rejectMessage = true;
+	}
+	if ( rejectMessage )
+	{	
+		KPassivePopup::message( i18n( "Message was rejected", "Message from %1 was rejected" )
+		                        .arg( message.sender() ),
+								"", myself()->onlineStatus().protocolIcon(),
+								Kopete::UI::Global::mainWidget() );
+		return;	
+	}
+	OscarAccount::messageReceived( message );
+}
+
 void ICQAccount::slotToggleInvisible()
 {
 	using namespace ICQ;
@@ -392,7 +427,6 @@
 	return Kopete::Message::escape( message );
 }
 
-
 void ICQAccount::slotGlobalIdentityChanged( const QString& key, const QVariant& value )
 {
 	//do something with the photo

--- /protocols/oscar/icq/icqaccount.h	2006-10-01 23:26:54.000000000 +0500
+++ /protocols/oscar/icq/icqaccount.h	2008-06-21 19:38:18.000000000 +0500
@@ -65,6 +65,8 @@
 	void connectWithPassword( const QString &password );
 
 	void setUserProfile( const QString &profile );
+	
+	void settingsChanged();
 
 protected:
 	virtual OscarContact *createNewContact( const QString &contactId, Kopete::MetaContact *parentContact, const SSI& ssiItem );
@@ -74,6 +76,7 @@
 protected slots:
 	virtual void disconnected( DisconnectReason reason );
 
+	virtual void messageReceived( const Oscar::Message& message );
 
 private:
 	ICQ::Presence presence();
@@ -97,6 +100,7 @@
 private:
 	bool mWebAware;
 	bool mHideIP;
+	bool mReceiveFromList;
 	QString mInitialStatusMessage;
 	OscarVisibilityDialog* m_visibilityDialog;
 };

--- /protocols/oscar/icq/ui/icqeditaccountui.ui	2008-02-13 14:37:43.000000000 +0500
+++ /protocols/oscar/icq/ui/icqeditaccountui.ui	2008-06-20 22:02:12.000000000 +0500
@@ -360,6 +360,20 @@
                                     <string>Check this box to enable ICQ's Web Aware functionality, which allows people to see your online status from ICQ's web page, and send you a message without necessarily having ICQ themselves.</string>
                                 </property>
                             </widget>
+			    <widget class="QCheckBox" row="3" column="0">
+				    <property name="name">
+					    <cstring>chkReceiveFromList</cstring>
+				    </property>
+				    <property name="text">
+					    <string>Receive messages only &amp;from people in my contact list</string>
+				    </property>
+				    <property name="checked">
+					    <bool>false</bool>
+				    </property>
+				    <property name="toolTip" stdset="0">
+					    <string>Check this box if you do not want to receive messages from unknown contacts and spammers.</string>
+				    </property>
+                            </widget>
                         </grid>
                     </widget>
                     <spacer row="3" column="0">

--- /protocols/oscar/icq/ui/icqeditaccountwidget.cpp	2008-02-13 14:37:43.000000000 +0500
+++ /protocols/oscar/icq/ui/icqeditaccountwidget.cpp	2008-06-21 19:38:43.000000000 +0500
@@ -83,6 +83,9 @@
 
         configValue = mAccount->configGroup()->readBoolEntry( "WebAware", false );
 		mAccountSettings->chkWebAware->setChecked( configValue );
+		
+	configValue = mAccount->configGroup()->readBoolEntry( "ReceiveFromList", false );
+		mAccountSettings->chkReceiveFromList->setChecked( configValue );
 
         int encodingValue = mAccount->configGroup()->readNumEntry( "DefaultEncoding", 4 );
         mProtocol->setComboFromTable( mAccountSettings->encodingCombo,
@@ -133,6 +136,9 @@
     configValue = mAccountSettings->chkWebAware->isChecked();
 	mAccount->configGroup()->writeEntry( "WebAware", configValue );
 
+    configValue = mAccountSettings->chkReceiveFromList->isChecked();
+	mAccount->configGroup()->writeEntry( "ReceiveFromList", configValue );
+
     int encodingMib = mProtocol->getCodeForCombo( mAccountSettings->encodingCombo,
                                                   mProtocol->encodings() );
     mAccount->configGroup()->writeEntry( "DefaultEncoding", encodingMib );
@@ -151,6 +157,7 @@
 	// Global Identity
 	mAccount->configGroup()->writeEntry( "ExcludeGlobalIdentity", mAccountSettings->chkGlobalIdentity->isChecked() );
 
+	mAccount->settingsChanged();
 	return mAccount;
 }
 

--- /protocols/oscar/liboscar/oscarsettings.cpp	2008-02-13 14:37:43.000000000 +0500
+++ /protocols/oscar/liboscar/oscarsettings.cpp	2008-06-20 23:31:15.000000000 +0500
@@ -59,8 +59,15 @@
 	return m_hideIP;
 }
 
+void Settings::setReceiveFromList( bool receive )
+{
+	m_ReceiveFromList = receive;
+}
 
-	
+bool Settings::ReceiveFromList() const
+{
+	return m_ReceiveFromList;
+}	
 
 
 }

--- /protocols/oscar/liboscar/oscarsettings.h	2008-02-13 14:37:43.000000000 +0500
+++ /protocols/oscar/liboscar/oscarsettings.h	2008-06-20 13:58:37.000000000 +0500
@@ -47,11 +47,15 @@
 	void setHideIP( bool hide );
 	bool hideIP() const;
 	
+	void setReceiveFromList( bool receive );
+	bool ReceiveFromList() const;
+	
 private:
 	
 	bool m_webAware;
 	bool m_requireAuth;
 	bool m_hideIP;
+	bool m_ReceiveFromList;
 };
 
 }
_______________________________________________
kopete-devel mailing list
[email protected]
https://mail.kde.org/mailman/listinfo/kopete-devel

Reply via email to