• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

mailcommon

  • sources
  • kde-4.14
  • kdepim
  • mailcommon
  • search
  • searchrule
searchruledate.cpp
Go to the documentation of this file.
1 /*
2  Copyright (c) 2015 Montel Laurent <montel@kde.org>
3 
4  This program is free software; you can redistribute it and/or modify it
5  under the terms of the GNU General Public License, version 2, as
6  published by the Free Software Foundation.
7 
8  This program is distributed in the hope that it will be useful, but
9  WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License along
14  with this program; if not, write to the Free Software Foundation, Inc.,
15  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16 */
17 
18 #include "searchruledate.h"
19 
20 #include <QDateTime>
21 
22 #include "filterlog.h"
23 using MailCommon::FilterLog;
24 
25 #include <KMime/KMimeMessage>
26 #include <KGlobal>
27 
28 using namespace MailCommon;
29 
30 SearchRuleDate::SearchRuleDate( const QByteArray &field,
31  Function func,
32  const QString &contents )
33  : SearchRule( field, func, contents )
34 {
35 }
36 
37 
38 QString SearchRuleDate::informationAboutNotValidRules() const
39 {
40  //KF5 add i18n
41  return QLatin1String("Date is not valid.");
42 }
43 
44 bool SearchRuleDate::isEmpty() const
45 {
46  return !QDate::fromString( contents(), Qt::ISODate ).isValid();
47 }
48 
49 bool SearchRuleDate::matches( const Akonadi::Item &item ) const
50 {
51  const KMime::Message::Ptr msg = item.payload<KMime::Message::Ptr>();
52 
53 
54  const QDate msgDate = msg->date()->dateTime().date();
55  const QDate dateValue = QDate::fromString( contents(), Qt::ISODate );
56  bool rc = matchesInternal( dateValue, msgDate );
57  if ( FilterLog::instance()->isLogging() ) {
58  QString msg = ( rc ? "<font color=#00FF00>1 = </font>"
59  : "<font color=#FF0000>0 = </font>" );
60  msg += FilterLog::recode( asString() );
61  msg += " ( <i>" + contents() + "</i> )"; //TODO change with locale?
62  FilterLog::instance()->add( msg, FilterLog::RuleResult );
63  }
64  return rc;
65 }
66 
67 bool SearchRuleDate::matchesInternal( const QDate& dateValue,
68  const QDate& msgDate ) const
69 {
70  switch ( function() ) {
71  case SearchRule::FuncEquals:
72  return ( dateValue == msgDate );
73 
74  case SearchRule::FuncNotEqual:
75  return ( dateValue != msgDate );
76 
77  case FuncIsGreater:
78  return ( msgDate > dateValue );
79 
80  case FuncIsLessOrEqual:
81  return ( msgDate <= dateValue );
82 
83  case FuncIsLess:
84  return ( msgDate < dateValue );
85 
86  case FuncIsGreaterOrEqual:
87  return ( msgDate >= dateValue );
88 
89  default:
90  ;
91  }
92  return false;
93 }
94 
95 SearchRule::RequiredPart SearchRuleDate::requiredPart() const
96 {
97  return SearchRule::Envelope;
98 }
99 
100 
101 
102 void SearchRuleDate::addQueryTerms( Akonadi::SearchTerm &groupTerm, bool &emptyIsNotAnError ) const
103 {
104  using namespace Akonadi;
105  emptyIsNotAnError = false;
106 
107  const QDate date = QDate::fromString( contents(), Qt::ISODate );
108  EmailSearchTerm term(EmailSearchTerm::HeaderOnlyDate, date, akonadiComparator());
109  term.setIsNegated( isNegated() );
110  groupTerm.addSubTerm(term);
111 }
112 
113 
MailCommon::SearchRuleDate::matches
virtual bool matches(const Akonadi::Item &item) const
Tries to match the rule against the KMime::Message in the given item.
Definition: searchruledate.cpp:49
MailCommon::SearchRule::FuncIsGreaterOrEqual
Definition: searchrule.h:66
MailCommon::FilterLog::recode
static QString recode(const QString &plain)
Returns an escaped version of the log which can be used in a HTML document.
Definition: filterlog.cpp:228
QByteArray
MailCommon::SearchRuleDate::isEmpty
virtual bool isEmpty() const
Determines whether the rule is worth considering.
Definition: searchruledate.cpp:44
MailCommon::SearchRule::akonadiComparator
Akonadi::SearchTerm::Condition akonadiComparator() const
Converts the rule function into the corresponding Akonadi query operator.
Definition: searchrule.cpp:526
MailCommon::SearchRuleDate::SearchRuleDate
SearchRuleDate(const QByteArray &field=QByteArray(), Function function=FuncContains, const QString &contents=QString())
Creates new date search rule.
Definition: searchruledate.cpp:30
MailCommon::SearchRuleDate::matchesInternal
bool matchesInternal(const QDate &dateValue, const QDate &msgDate) const
A helper method for the main matches() method.
Definition: searchruledate.cpp:67
MailCommon::FilterLog::instance
static FilterLog * instance()
Returns the single global instance of the filter log.
Definition: filterlog.cpp:107
MailCommon::FilterLog
KMail Filter Log Collector.
Definition: filterlog.h:55
filterlog.h
QDate::fromString
QDate fromString(const QString &string, Qt::DateFormat format)
MailCommon::SearchRule::Function
Function
Describes operators for comparison of field and contents.
Definition: searchrule.h:55
MailCommon::SearchRule::FuncNotEqual
Definition: searchrule.h:60
MailCommon::SearchRule::asString
const QString asString() const
Returns the rule as string for debugging purpose.
Definition: searchrule.cpp:516
MailCommon::SearchRule::contents
QString contents() const
Returns the contents of the rule.
Definition: searchrule.cpp:511
QDate::isValid
bool isValid() const
QDate
MailCommon::SearchRuleDate::addQueryTerms
virtual void addQueryTerms(Akonadi::SearchTerm &groupTerm, bool &emptyIsNotAnError) const
Adds query terms to the given term group.
Definition: searchruledate.cpp:102
MailCommon::SearchRuleDate::requiredPart
virtual RequiredPart requiredPart() const
Returns the required part from the item that is needed for the search to operate. ...
Definition: searchruledate.cpp:95
MailCommon::SearchRule::RequiredPart
RequiredPart
Definition: searchrule.h:79
QString
MailCommon::SearchRule::isNegated
bool isNegated() const
Helper that returns whether the rule has a negated function.
Definition: searchrule.cpp:567
MailCommon::SearchRuleDate::informationAboutNotValidRules
virtual QString informationAboutNotValidRules() const
Definition: searchruledate.cpp:38
MailCommon::SearchRule
This class represents one search pattern rule.
Definition: searchrule.h:38
MailCommon::SearchRule::Envelope
Definition: searchrule.h:80
MailCommon::SearchRule::FuncIsGreater
Definition: searchrule.h:63
MailCommon::SearchRule::FuncIsLessOrEqual
Definition: searchrule.h:64
QLatin1String
MailCommon::FilterLog::add
void add(const QString &entry, ContentType type)
Adds the given log entry under the given content type to the log.
Definition: filterlog.cpp:164
searchruledate.h
MailCommon::SearchRule::FuncIsLess
Definition: searchrule.h:65
MailCommon::SearchRule::FuncEquals
Definition: searchrule.h:59
MailCommon::FilterLog::RuleResult
Log all rule matching results.
Definition: filterlog.h:76
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:31:41 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

mailcommon

Skip menu "mailcommon"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer
  • pimprint

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal