[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-pim
Subject:    [Kde-pim] new filter rule, is sender in addressbook?
From:       Martin =?iso-8859-15?q?K=F6bele?= <martin () mkoebele ! de>
Date:       2003-11-09 14:06:42
[Download RAW message or body]

Hi,

I wrote a patch which adds the filter-rule: "sender is in addressbook" and 
"sender is not in addressbook".

When you select the rule it selects the "From"-value and sets the 
content-value to "Addressbook" just for the sake of writing the configuration 
to kmailrc. Didn't want to touch the mechanism of purifying and checking of 
incomplete filter-rules and configuration-files.

patch is made against the current cvs (Nov 9th).

What do you think about the patch?


Martin

["addressbook_filter_rule.diff" (text/x-diff)]

Index: kmsearchpattern.h
===================================================================
RCS file: /home/kde/kdepim/kmail/kmsearchpattern.h,v
retrieving revision 1.18
diff -u -3 -p -r1.18 kmsearchpattern.h
--- kmsearchpattern.h	16 Sep 2003 07:51:06 -0000	1.18
+++ kmsearchpattern.h	9 Nov 2003 13:59:59 -0000
@@ -40,7 +40,8 @@ public:
 		  FuncEquals, FuncNotEqual,
 		  FuncRegExp, FuncNotRegExp,
 		  FuncIsGreater, FuncIsLessOrEqual,
-		  FuncIsLess, FuncIsGreaterOrEqual };
+		  FuncIsLess, FuncIsGreaterOrEqual, 
+		  FuncIsInAddressbook, FuncIsNotInAddressbook};
   KMSearchRule ( const QCString & field=0, Function=FuncContains,
                  const QString &contents=QString::null );
   KMSearchRule ( const KMSearchRule &other );
Index: kmsearchpattern.cpp
===================================================================
RCS file: /home/kde/kdepim/kmail/kmsearchpattern.cpp,v
retrieving revision 1.45
diff -u -3 -p -r1.45 kmsearchpattern.cpp
--- kmsearchpattern.cpp	29 Oct 2003 21:12:34 -0000	1.45
+++ kmsearchpattern.cpp	9 Nov 2003 13:59:59 -0000
@@ -14,6 +14,7 @@
 #include <kdebug.h>
 #include <kconfig.h>
 
+#include <kabc/stdaddressbook.h>
 #include <qregexp.h>
 
 #include <mimelib/string.h>
@@ -23,7 +24,7 @@
 
 static const char* funcConfigNames[] =
   { "contains", "contains-not", "equals", "not-equal", "regexp",
-    "not-regexp", "greater", "less-or-equal", "less", "greater-or-equal" };
+    "not-regexp", "greater", "less-or-equal", "less", "greater-or-equal", \
"is-in-addressbook", "is-not-in-addressbook" };  static const int numFuncConfigNames \
= sizeof funcConfigNames / sizeof *funcConfigNames;  
 
@@ -281,8 +282,14 @@ bool KMSearchRuleString::matches( const 
     msgContents = msg->headerField("To") + msg->headerField("Cc")
                 + msg->headerField("Bcc");
   }  else {
-    msgContents = msg->headerField( field() );
+  	  msgContents = msg->headerField( field() );
   }
+  
+  if (function() == FuncIsInAddressbook || function() == FuncIsNotInAddressbook) {
+  	// I think only the "from"-field makes sense.
+  	msgContents = msg->getEmailAddr(msg->headerField("From"));
+  }
+  	
   return matchesInternal( msgContents );
 }
 
@@ -325,6 +332,19 @@ bool KMSearchRuleString::matchesInternal
 
   case FuncIsGreaterOrEqual:
       return ( QString::compare( msgContents.lower(), contents().lower() ) >= 0 );
+      
+  case FuncIsInAddressbook:
+  	{
+		KABC::AddressBook *stdAb = KABC::StdAddressBook::self();
+		return ( !(stdAb->findByEmail(msgContents.lower())).empty());
+	}
+	
+  case FuncIsNotInAddressbook:
+  	{
+  		KABC::AddressBook *stdAb = KABC::StdAddressBook::self();
+		return ((stdAb->findByEmail(msgContents.lower())).empty());
+	}
+	
   }
 
   return false;
@@ -412,8 +432,14 @@ bool KMSearchRuleNumerical::matchesInter
 
   case FuncIsGreaterOrEqual:
       return ( numericalMsgContents >= numericalValue );
-  }
-
+   
+  case FuncIsInAddressbook:  // since email-addresses are not numerical, I settle \
for false here +	return ( false);
+	
+  case FuncIsNotInAddressbook:
+	return (false);
+ }
+		
   return false;
 }
 
Index: kmsearchpatternedit.h
===================================================================
RCS file: /home/kde/kdepim/kmail/kmsearchpatternedit.h,v
retrieving revision 1.17
diff -u -3 -p -r1.17 kmsearchpatternedit.h
--- kmsearchpatternedit.h	3 Oct 2003 15:45:29 -0000	1.17
+++ kmsearchpatternedit.h	9 Nov 2003 13:59:59 -0000
@@ -97,6 +97,7 @@ private:
   QPushButton* mRuleEditBut;
   QDialog* mRegExpEditDialog;
   QStringList mFilterFieldList, mFilterFuncList, mStatiList;
+  bool mChangeValue; //used for the new is-in-addressbook-filter
 };
 
 
Index: kmsearchpatternedit.cpp
===================================================================
RCS file: /home/kde/kdepim/kmail/kmsearchpatternedit.cpp,v
retrieving revision 1.47
diff -u -3 -p -r1.47 kmsearchpatternedit.cpp
--- kmsearchpatternedit.cpp	26 Oct 2003 09:44:37 -0000	1.47
+++ kmsearchpatternedit.cpp	9 Nov 2003 13:59:59 -0000
@@ -31,7 +31,8 @@
 KMSearchRuleWidget::KMSearchRuleWidget(QWidget *parent, KMSearchRule *aRule, const \
char *name, bool headersOnly, bool absoluteDates)  : QHBox(parent,name),
     mRuleEditBut(0),
-    mRegExpEditDialog(0)
+    mRegExpEditDialog(0),
+    mChangeValue(false)
 {
   initLists( headersOnly, absoluteDates ); // sFilter{Func,Field}List are local to \
KMSearchRuleWidget  initWidget();
@@ -96,7 +97,18 @@ void KMSearchRuleWidget::editRegExp()
 
 void KMSearchRuleWidget::functionChanged( int which )
 {
-  mRuleEditBut->setEnabled( which == 4 || which == 5 );
+  mRuleEditBut->setEnabled( which == 4 || which == 5 ); //FuncRegExp, FuncNotRegExp
+  //we don't need the lineedit in that case:
+  mRuleValue->setEnabled(which != 10 && which != 11);  //FuncIsInAddressbook, \
FuncIsNotInAddressbook +  if (which == 10 || which == 11) {
+  	mRuleField->setCurrentText("From");
+	mRuleValue->setText("Addressbook"); //just a dummy-value, otherwise the rule is not \
saved to kmailrc +	mChangeValue = true;
+  }
+  else   if (mChangeValue){
+  	mRuleValue->clear();
+	mChangeValue = false;
+  }
 }
 
 
@@ -235,6 +247,8 @@ void KMSearchRuleWidget::initLists(bool 
     mFilterFuncList.append(i18n("is less than or equal to"));
     mFilterFuncList.append(i18n("is less than"));
     mFilterFuncList.append(i18n("is greater than or equal to"));
+    mFilterFuncList.append(i18n("sender is in addressbook"));
+    mFilterFuncList.append(i18n("sender is not in addressbook"));
   }
 
   //---------- initialize list of filter operators



_______________________________________________
kde-pim mailing list
kde-pim@mail.kde.org
https://mail.kde.org/mailman/listinfo/kde-pim
kde-pim home page at http://pim.kde.org/

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic