[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#284334: kopete: [PATCH v2] Drop messages from user not in your contact list.



Hello, 

I used my patch for a few days and found that spammers use auth request for 
spamming too. So I dercide to drop all messages including auth requests from 
users not in contact list. I am too lazy to write confire options for message 
droping functionality so I attach modified patch.

If upstream is willing I can add configure options.

Here is the patch:
diff -Nur --exclude=Makefile.in kdenetwork-3.5.5.clean/kopete/protocols/oscar/icq/icqaccount.cpp kdenetwork-3.5.5/kopete/protocols/oscar/icq/icqaccount.cpp
--- kdenetwork-3.5.5.clean/kopete/protocols/oscar/icq/icqaccount.cpp	2006-10-02 00:26:54.000000000 +0700
+++ kdenetwork-3.5.5/kopete/protocols/oscar/icq/icqaccount.cpp	2007-07-23 09:02:30.000000000 +0700
@@ -174,6 +174,7 @@
 		oscarSettings->setHideIP( configGroup()->readBoolEntry( "HideIP", true ) );
 		oscarSettings->setRequireAuth( configGroup()->readBoolEntry( "RequireAuth", false ) );
 		oscarSettings->setRespectRequireAuth( configGroup()->readBoolEntry( "RespectRequireAuth", true ) );
+		oscarSettings->setDropNotInList( configGroup()->readBoolEntry( "DropNotInList", false ) );
 		//FIXME: also needed for the other call to setStatus (in setPresenceTarget)
 		DWORD status = pres.toOscarStatus();
 
diff -Nur --exclude=Makefile.in kdenetwork-3.5.5.clean/kopete/protocols/oscar/icq/ui/icqeditaccountui.ui kdenetwork-3.5.5/kopete/protocols/oscar/icq/ui/icqeditaccountui.ui
--- kdenetwork-3.5.5.clean/kopete/protocols/oscar/icq/ui/icqeditaccountui.ui	2006-10-02 00:26:54.000000000 +0700
+++ kdenetwork-3.5.5/kopete/protocols/oscar/icq/ui/icqeditaccountui.ui	2007-07-23 09:02:30.000000000 +0700
@@ -331,13 +331,27 @@
                             </widget>
                             <widget class="QCheckBox" row="1" column="0">
                                 <property name="name">
+                                    <cstring>chkDropNotInList</cstring>
+                                </property>
+                                <property name="text">
+                                    <string>Drop messages from users not in contact list</string>
+                                </property>
+                                <property name="toolTip" stdset="0">
+                                    <string>Enable spam protection, which will not show you messages from users not at your contact list.</string>
+                                </property>
+                                <property name="whatsThis" stdset="0">
+                                    <string>Enable spam protection, which will not show you messages from users not at your contact list.  Check this box, and kopete will drop any messages from users not at your contact list.</string>
+                                </property>
+                            </widget>
+                            <widget class="QCheckBox" row="2" column="0">
+                                <property name="name">
                                     <cstring>chkRespectRequireAuth</cstring>
                                 </property>
                                 <property name="text">
                                     <string>Respect other contacts' &amp;wish to require authorization</string>
                                 </property>
                             </widget>
-                            <widget class="QCheckBox" row="2" column="0">
+                            <widget class="QCheckBox" row="3" column="0">
                                 <property name="name">
                                     <cstring>chkHideIP</cstring>
                                 </property>
@@ -351,7 +365,7 @@
                                     <string>Checking this box will not allow people to see what your IP address if they view your ICQ user details such as name, address, or age.</string>
                                 </property>
                             </widget>
-                            <widget class="QCheckBox" row="3" column="0">
+                            <widget class="QCheckBox" row="4" column="0">
                                 <property name="name">
                                     <cstring>chkWebAware</cstring>
                                 </property>
diff -Nur --exclude=Makefile.in kdenetwork-3.5.5.clean/kopete/protocols/oscar/icq/ui/icqeditaccountwidget.cpp kdenetwork-3.5.5/kopete/protocols/oscar/icq/ui/icqeditaccountwidget.cpp
--- kdenetwork-3.5.5.clean/kopete/protocols/oscar/icq/ui/icqeditaccountwidget.cpp	2006-10-02 00:26:54.000000000 +0700
+++ kdenetwork-3.5.5/kopete/protocols/oscar/icq/ui/icqeditaccountwidget.cpp	2007-07-23 09:02:30.000000000 +0700
@@ -77,6 +77,9 @@
 
         bool configValue = mAccount->configGroup()->readBoolEntry( "RequireAuth", false );
 		mAccountSettings->chkRequireAuth->setChecked( configValue );
+        
+		configValue = mAccount->configGroup()->readBoolEntry( "DropNotInList", false );
+		mAccountSettings->chkDropNotInList->setChecked( configValue );
 
         configValue = mAccount->configGroup()->readBoolEntry( "RespectRequireAuth", true );
 		mAccountSettings->chkRespectRequireAuth->setChecked( configValue );
@@ -130,6 +133,9 @@
     bool configValue = mAccountSettings->chkRequireAuth->isChecked();
 	mAccount->configGroup()->writeEntry( "RequireAuth", configValue );
 
+	configValue = mAccountSettings->chkDropNotInList->isChecked();
+	mAccount->configGroup()->writeEntry( "DropNotInList", configValue );
+
     configValue = mAccountSettings->chkRespectRequireAuth->isChecked();
 	mAccount->configGroup()->writeEntry( "RespectRequireAuth", configValue );
 
diff -Nur --exclude=Makefile.in kdenetwork-3.5.5.clean/kopete/protocols/oscar/liboscar/oscarsettings.cpp kdenetwork-3.5.5/kopete/protocols/oscar/liboscar/oscarsettings.cpp
--- kdenetwork-3.5.5.clean/kopete/protocols/oscar/liboscar/oscarsettings.cpp	2005-09-10 15:20:23.000000000 +0700
+++ kdenetwork-3.5.5/kopete/protocols/oscar/liboscar/oscarsettings.cpp	2007-07-23 09:02:30.000000000 +0700
@@ -59,6 +59,16 @@
 	return m_respectRequireAuth;
 }
 
+void Settings::setDropNotInList( bool drop )
+{
+	m_dropNotInList = drop;
+}
+
+bool Settings::dropNotInList() const
+{
+	return m_dropNotInList;
+}
+
 void Settings::setHideIP( bool hide )
 {
 	m_hideIP = hide;
diff -Nur --exclude=Makefile.in kdenetwork-3.5.5.clean/kopete/protocols/oscar/liboscar/oscarsettings.h kdenetwork-3.5.5/kopete/protocols/oscar/liboscar/oscarsettings.h
--- kdenetwork-3.5.5.clean/kopete/protocols/oscar/liboscar/oscarsettings.h	2005-09-10 15:20:23.000000000 +0700
+++ kdenetwork-3.5.5/kopete/protocols/oscar/liboscar/oscarsettings.h	2007-07-23 09:02:30.000000000 +0700
@@ -44,6 +44,10 @@
 	bool requireAuth() const;
 	void setRespectRequireAuth( bool require );
 	bool respectRequireAuth() const;
+
+	/* Anti-spam settings */
+	void setDropNotInList( bool drop );
+	bool dropNotInList() const;
 	
 	/* Hide IP Settings */
 	void setHideIP( bool hide );
@@ -54,6 +58,7 @@
 	bool m_webAware;
 	bool m_requireAuth;
 	bool m_respectRequireAuth;
+	bool m_dropNotInList;
 	bool m_hideIP;
 };
 
diff -Nur --exclude=Makefile.in kdenetwork-3.5.5.clean/kopete/protocols/oscar/oscaraccount.cpp kdenetwork-3.5.5/kopete/protocols/oscar/oscaraccount.cpp
--- kdenetwork-3.5.5.clean/kopete/protocols/oscar/oscaraccount.cpp	2006-10-02 00:26:54.000000000 +0700
+++ kdenetwork-3.5.5/kopete/protocols/oscar/oscaraccount.cpp	2007-07-23 09:02:47.000000000 +0700
@@ -55,6 +55,7 @@
 #include "oscarutils.h"
 #include "oscarclientstream.h"
 #include "oscarconnector.h"
+#include "oscarsettings.h"
 #include "ssimanager.h"
 #include "oscarlistnonservercontacts.h"
 #include "oscarversionupdater.h"
@@ -380,19 +381,32 @@
 	}
 
 	/* Logic behind this:
-	 * If we don't have the contact yet, create it as a temporary
-	 * Create the message manager
-	 * Get the sanitized message back
-	 * Append to the chat window
+	 * 1. Check if we should drop the message.
+	 * 2. If we don't have the contact yet, create it as a temporary
+	 *    Create the message manager
+	 *    Get the sanitized message back
+	 *    Append to the chat window
 	 */
 	QString sender = Oscar::normalize( message.sender() );
-	if ( !contacts()[sender] )
+	OscarContact* ocSender = static_cast<OscarContact *> ( contacts()[sender] ); 
+
+	if (!ocSender || ocSender->metaContact()->isTemporary()) 
+	{
+		// Try to drop the message 
+		if( engine()->clientSettings()->dropNotInList() )  
+		{
+			kdWarning(OSCAR_RAW_DEBUG) << "Dropping message from '" << sender << "' because he is not in contact list (" << message.properties() << ")" << endl;
+			return;
+		}
+	}
+
+	if (!ocSender) 
 	{
 		kdDebug(OSCAR_RAW_DEBUG) << "Adding '" << sender << "' as temporary contact" << endl;
 		addContact( sender, QString::null, 0,  Kopete::Account::Temporary );
 	}
 
-	OscarContact* ocSender = static_cast<OscarContact *> ( contacts()[sender] ); //should exist now
+	ocSender = static_cast<OscarContact *> ( contacts()[sender] ); //should exist now
 
 	if ( !ocSender )
 	{



Reply to: