kmail

kmsearchpattern.h
1 // kmsearchpattern.h
2 // Author: Marc Mutz <Marc@Mutz.com>
3 // This code is under GPL!
4 
5 #ifndef _kmsearchpattern_h_
6 #define _kmsearchpattern_h_
7 
8 #include <tdelocale.h>
9 #include <tqptrlist.h>
10 #include <tqstring.h>
11 #include <tqcstring.h>
12 #include "kmmsgbase.h" // for KMMsgStatus
13 
14 class KMMessage;
15 class TDEConfig;
16 class DwBoyerMoore;
17 class DwString;
18 
19 
20 // maximum number of filter rules per filter
21 const int FILTER_MAX_RULES=8;
22 
31 {
32 public:
40  enum Function { FuncNone = -1,
41  FuncContains=0, FuncContainsNot,
42  FuncEquals, FuncNotEqual,
43  FuncRegExp, FuncNotRegExp,
44  FuncIsGreater, FuncIsLessOrEqual,
45  FuncIsLess, FuncIsGreaterOrEqual,
46  FuncIsInAddressbook, FuncIsNotInAddressbook,
47  FuncIsInCategory, FuncIsNotInCategory,
48  FuncHasAttachment, FuncHasNoAttachment};
49  KMSearchRule ( const TQCString & field=0, Function=FuncContains,
50  const TQString &contents=TQString() );
51  KMSearchRule ( const KMSearchRule &other );
52 
53  const KMSearchRule & operator=( const KMSearchRule & other );
54 
57  static KMSearchRule* createInstance( const TQCString & field=0,
58  Function function=FuncContains,
59  const TQString & contents=TQString() );
60 
61  static KMSearchRule* createInstance( const TQCString & field,
62  const char * function,
63  const TQString & contents );
64 
65  static KMSearchRule * createInstance( const KMSearchRule & other );
66 
72  static KMSearchRule* createInstanceFromConfig( const TDEConfig * config, int aIdx );
73 
74  virtual ~KMSearchRule() {};
75 
80  virtual bool matches( const KMMessage * msg ) const = 0;
81 
86  virtual bool matches( const DwString & str, KMMessage & msg,
87  const DwBoyerMoore * headerField=0,
88  int headerLen=-1 ) const;
89 
94  virtual bool isEmpty() const = 0;
95 
98  virtual bool requiresBody() const { return true; }
99 
100 
106  void writeConfig( TDEConfig * config, int aIdx ) const;
107 
110  Function function() const { return mFunction; }
111 
113  void setFunction( Function aFunction ) { mFunction = aFunction; }
114 
125  TQCString field() const { return mField; }
126 
129  void setField( const TQCString & field ) { mField = field; }
130 
133  TQString contents() const { return mContents; }
135  void setContents( const TQString & aContents ) { mContents = aContents; }
136 
138  const TQString asString() const;
139 
140 private:
141  static Function configValueToFunc( const char * str );
142  static TQString functionToString( Function function );
143 
144  TQCString mField;
145  Function mFunction;
146  TQString mContents;
147 };
148 
149 
150 // subclasses representing the different kinds of searches
151 
159 {
160 public:
161  KMSearchRuleString( const TQCString & field=0, Function function=FuncContains,
162  const TQString & contents=TQString() );
163  KMSearchRuleString( const KMSearchRuleString & other );
164  const KMSearchRuleString & operator=( const KMSearchRuleString & other );
165 
166  virtual ~KMSearchRuleString();
167  virtual bool isEmpty() const ;
168  virtual bool requiresBody() const;
169 
170  virtual bool matches( const KMMessage * msg ) const;
171 
175  virtual bool matches( const DwString & str, KMMessage & msg,
176  const DwBoyerMoore * headerField=0,
177  int headerLen=-1 ) const;
178 
180  bool matchesInternal( const TQString & msgContents ) const;
181 
182 private:
183  const DwBoyerMoore *mBmHeaderField;
184 };
185 
186 
194 {
195 public:
196  KMSearchRuleNumerical( const TQCString & field=0, Function function=FuncContains,
197  const TQString & contents=TQString() );
198  virtual bool isEmpty() const ;
199 
200  virtual bool matches( const KMMessage * msg ) const;
201 
203  bool matchesInternal( long numericalValue, long numericalMsgContents,
204  const TQString & msgContents ) const;
205 };
206 
207 
208 namespace KMail {
209 // The below are used in several places and here so they are accessible.
210  struct MessageStatus {
211  const char * const text;
212  const char * const icon;
213  };
214 
215  // If you change the ordering here; also do it in the enum below
216  static const MessageStatus StatusValues[] = {
217  { I18N_NOOP( "Important" ), "kmmsgflag" },
218  { I18N_NOOP( "New" ), "kmmsgnew" },
219  { I18N_NOOP( "Unread" ), "kmmsgunseen" },
220  { I18N_NOOP( "Read" ), "kmmsgread" },
221  { I18N_NOOP( "Old" ), 0 },
222  { I18N_NOOP( "Deleted" ), "kmmsgdel" },
223  { I18N_NOOP( "Replied" ), "kmmsgreplied" },
224  { I18N_NOOP( "Forwarded" ), "kmmsgforwarded" },
225  { I18N_NOOP( "Queued" ), "kmmsgqueued" },
226  { I18N_NOOP( "Sent" ), "kmmsgsent" },
227  { I18N_NOOP( "Watched" ), "kmmsgwatched" },
228  { I18N_NOOP( "Ignored" ), "kmmsgignored" },
229  { I18N_NOOP( "Spam" ), "kmmsgspam" },
230  { I18N_NOOP( "Ham" ), "kmmsgham" },
231  { I18N_NOOP( "To Do" ), "kmmsgtodo" },
232  { I18N_NOOP( "Invitation" ), "kmmsginvitation" },
233  { I18N_NOOP( "Has Attachment"), "kmmsgattachment" } //must be last
234  };
235  // If you change the ordering here; also do it in the array above
236  enum StatusValueTypes {
237  StatusImportant = 0,
238  StatusNew = 1,
239  StatusUnread = 2,
240  StatusRead = 3,
241  StatusOld = 4,
242  StatusDeleted = 5,
243  StatusReplied = 6,
244  StatusForwarded = 7,
245  StatusQueued = 8,
246  StatusSent = 9,
247  StatusWatched = 10,
248  StatusIgnored = 11,
249  StatusSpam = 12,
250  StatusHam = 13,
251  StatusToDo = 14,
252  StatusInvitation = 15,
253  StatusHasAttachment = 16 //must be last
254  };
255 
256  static const int StatusValueCount =
257  sizeof( StatusValues ) / sizeof( MessageStatus );
258  // we want to show all status entries in the quick search bar, but only the
259  // ones up to attachment in the search/filter dialog, because there the
260  // attachment case is handled separately.
261  static const int StatusValueCountWithoutHidden = StatusValueCount - 1;
262 }
263 
270 {
271 public:
272  KMSearchRuleStatus( const TQCString & field=0, Function function=FuncContains,
273  const TQString & contents=TQString() );
274  KMSearchRuleStatus( int status, Function function=FuncContains );
275 
276  virtual bool isEmpty() const ;
277  virtual bool matches( const KMMessage * msg ) const;
278  //Not possible to implement this form for status searching
279  virtual bool matches( const DwString &, KMMessage &,
280  const DwBoyerMoore *,
281  int ) const;
282  static KMMsgStatus statusFromEnglishName(const TQString&);
283  private:
284  KMMsgStatus mStatus;
285 };
286 
287 // ------------------------------------------------------------------------
288 
307 class KMSearchPattern : public TQPtrList<KMSearchRule>
308 {
309 
310 public:
316  enum Operator { OpAnd, OpOr };
325  KMSearchPattern( const TDEConfig * config=0 );
326 
329 
339  bool matches( const KMMessage * msg, bool ignoreBody = false ) const;
340  bool matches( const DwString & str, bool ignoreBody = false ) const;
341  bool matches( TQ_UINT32 sernum, bool ignoreBody = false ) const;
342 
345  bool requiresBody() const;
346 
351  void purify();
352 
365  void readConfig( const TDEConfig * config );
372  void writeConfig( TDEConfig * config ) const;
373 
375  TQString name() const { return mName; }
378  void setName( const TQString & newName ) { mName = newName ; }
379 
381  KMSearchPattern::Operator op() const { return mOperator; }
383  void setOp( KMSearchPattern::Operator aOp ) { mOperator = aOp; }
384 
386  TQString asString() const;
387 
389  const KMSearchPattern & operator=( const KMSearchPattern & aPattern );
390 
391 private:
399  void importLegacyConfig( const TDEConfig * config );
402  void init();
403 
404  TQString mName;
405  Operator mOperator;
406 };
407 
408 #endif /* _kmsearchpattern_h_ */
This is a Mime Message.
Definition: kmmessage.h:68
This class is an abstraction of a search over messages.
bool requiresBody() const
Returns true if the pattern only depends the DwString that backs a message.
KMSearchPattern::Operator op() const
Get the filter operator.
~KMSearchPattern()
Destructor.
void readConfig(const TDEConfig *config)
Reads a search pattern from a TDEConfig.
bool matches(const KMMessage *msg, bool ignoreBody=false) const
The central function of this class.
KMSearchPattern(const TDEConfig *config=0)
Constructor that initializes from a given TDEConfig group, if given.
void setOp(KMSearchPattern::Operator aOp)
Set the filter operator.
void setName(const TQString &newName)
Set the name of the search pattern.
Operator
Boolean operators that connect the return values of the individual rules.
TQString name() const
Get the name of the search pattern.
void purify()
Removes all empty rules from the list.
const KMSearchPattern & operator=(const KMSearchPattern &aPattern)
Overloaded assignment operator.
TQString asString() const
Returns the pattern as string.
void writeConfig(TDEConfig *config) const
Writes itself into config.
This class represents a search to be performed against a numerical value, such as the age of the mess...
virtual bool isEmpty() const
Determine whether the rule is worth considering.
bool matchesInternal(long numericalValue, long numericalMsgContents, const TQString &msgContents) const
Helper for the main matches() method.
virtual bool matches(const KMMessage *msg) const
Tries to match the rule against the given KMMessage.
This class represents a search to be performed against the status of a messsage.
virtual bool matches(const KMMessage *msg) const
Tries to match the rule against the given KMMessage.
virtual bool isEmpty() const
Determine whether the rule is worth considering.
This class represents a search to be performed against a string.
virtual bool requiresBody() const
Returns true if the rule depends on a complete message, otherwise returns false.
virtual bool matches(const KMMessage *msg) const
Tries to match the rule against the given KMMessage.
bool matchesInternal(const TQString &msgContents) const
Helper for the main matches() method.
virtual bool isEmpty() const
Determine whether the rule is worth considering.
Incoming mail is sent through the list of mail filter rules before it is placed in the associated mai...
void setFunction(Function aFunction)
Set filter function.
virtual bool matches(const KMMessage *msg) const =0
Tries to match the rule against the given KMMessage.
void setContents(const TQString &aContents)
Set the value.
static KMSearchRule * createInstanceFromConfig(const TDEConfig *config, int aIdx)
Initialize the object from a given config file.
static KMSearchRule * createInstance(const TQCString &field=0, Function function=FuncContains, const TQString &contents=TQString())
Create a search rule of a certain type by instantiating the appro- priate subclass depending on the f...
TQCString field() const
Return message header field name (without the trailing ':').
virtual bool requiresBody() const
Returns true if the rule depends on a complete message, otherwise returns false.
const TQString asString() const
Returns the rule as string.
TQString contents() const
Return the value.
void setField(const TQCString &field)
Set message header field name (make sure there's no trailing colon ':')
virtual bool isEmpty() const =0
Determine whether the rule is worth considering.
Function
Operators for comparison of field and contents.
void writeConfig(TDEConfig *config, int aIdx) const
Save the object into a given config file.
folderdiaquotatab.h
Definition: aboutdata.cpp:40