[prev in list] [next in list] [prev in thread] [next in thread]
List: kmail-devel
Subject: new filter-rule "is in addressbook", patch #2
From: Martin =?iso-8859-15?q?K=F6bele?= <martin () mkoebele ! de>
Date: 2003-11-09 19:04:01
[Download RAW message or body]
Hi,
this patch considers Ingo's whishes and complains.
Changed behaviour: Any field is usable, however only a field which contains an
email-address makes sense (obviously).
Martin
PS: see the first mail in kde-pim.
["addressbook_filter_rule2.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 18:38:14 -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 18:38:14 -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,8 @@
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 +283,17 @@ 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(field()));
+ if (msgContents.isEmpty())
+ return false;
+ }
+
return matchesInternal( msgContents );
}
@@ -325,6 +336,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 +436,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 18:38:14 -0000
@@ -97,6 +97,8 @@ private:
QPushButton* mRuleEditBut;
QDialog* mRegExpEditDialog;
QStringList mFilterFieldList, mFilterFuncList, mStatiList;
+ bool mChangeValue; //used for the new is-in-addressbook-filter
+ QString mOldValue;
};
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 18:38:14 -0000
@@ -31,7 +31,9 @@
KMSearchRuleWidget::KMSearchRuleWidget(QWidget *parent, KMSearchRule *aRule, const \
char *name, bool headersOnly, bool absoluteDates) : QHBox(parent,name),
mRuleEditBut(0),
- mRegExpEditDialog(0)
+ mRegExpEditDialog(0),
+ mChangeValue(false),
+ mOldValue("")
{
initLists( headersOnly, absoluteDates ); // sFilter{Func,Field}List are local to \
KMSearchRuleWidget initWidget();
@@ -96,7 +98,20 @@ 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)
+ {
+ mOldValue = mRuleValue->text();
+ mRuleValue->setText("Addressbook"); //just a dummy-value, otherwise the rule is \
not saved to kmailrc + mChangeValue = true;
+ }
+ else if (mChangeValue)
+ {
+ mRuleValue->setText(mOldValue);
+ mChangeValue = false;
+ }
}
@@ -235,6 +250,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("is in addressbook"));
+ mFilterFuncList.append(i18n("is not in addressbook"));
}
//---------- initialize list of filter operators
_______________________________________________
KMail Developers mailing list
kmail@kde.org
https://mail.kde.org/mailman/listinfo/kmail
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic