NeoMutt  2021-02-05-89-gabe350
Teaching an old dog new tricks
DOXYGEN
lib.h
Go to the documentation of this file.
1 
39 #ifndef MUTT_PATTERN_LIB_H
40 #define MUTT_PATTERN_LIB_H
41 
42 #include "config.h"
43 #include <stddef.h>
44 #include <stdbool.h>
45 #include <stdint.h>
46 #include "mutt/lib.h"
47 #include "mutt.h"
48 
49 struct AliasMenuData;
50 struct AliasView;
51 struct ConfigSet;
52 struct Context;
53 struct Email;
54 struct Envelope;
55 struct Mailbox;
56 struct Menu;
57 
58 #define MUTT_ALIAS_SIMPLESEARCH "~f %s | ~t %s | ~c %s"
59 
60 /* These Config Variables are only used in pattern.c */
61 extern bool C_ThoroughSearch;
62 
63 typedef uint8_t PatternCompFlags;
64 #define MUTT_PC_NO_FLAGS 0
65 #define MUTT_PC_FULL_MSG (1<<0)
66 #define MUTT_PC_PATTERN_DYNAMIC (1<<1)
67 #define MUTT_PC_SEND_MODE_SEARCH (1<<2)
68 
69 
72 struct Pattern
73 {
74  short op;
75  bool pat_not : 1;
76  bool all_addr : 1;
77  bool string_match : 1;
78  bool group_match : 1;
79  bool ign_case : 1;
80  bool is_alias : 1;
81  bool dynamic : 1;
82  bool sendmode : 1;
83  bool is_multi : 1;
84  int min;
85  int max;
86  struct PatternList *child;
87  union {
88  regex_t *regex;
89  struct Group *group;
90  char *str;
91  struct ListHead multi_cases;
92  } p;
93  SLIST_ENTRY(Pattern) entries;
94 };
95 SLIST_HEAD(PatternList, Pattern);
96 
97 typedef uint8_t PatternExecFlags;
98 #define MUTT_PAT_EXEC_NO_FLAGS 0
99 #define MUTT_MATCH_FULL_ADDRESS (1 << 0)
100 
101 
110 {
111  int list_all;
112  int list_one;
113  int sub_all;
114  int sub_one;
119 };
120 
129 {
171 #ifdef USE_NNTP
173 #endif
175 };
176 
177 int mutt_pattern_exec(struct Pattern *pat, PatternExecFlags flags, struct Mailbox *m,
178  struct Email *e, struct PatternCache *cache);
179 int mutt_pattern_alias_exec(struct Pattern *pat, PatternExecFlags flags,
180  struct AliasView *av, struct PatternCache *cache);
181 
182 struct PatternList *mutt_pattern_comp(struct Context *ctx, const char *s, PatternCompFlags flags, struct Buffer *err);
183 void mutt_check_simple(struct Buffer *s, const char *simple);
184 void mutt_pattern_free(struct PatternList **pat);
185 bool dlg_select_pattern(char *buf, size_t buflen);
186 
187 int mutt_which_case(const char *s);
188 int mutt_is_list_recipient(bool all_addr, struct Envelope *e);
189 int mutt_is_subscribed_list_recipient(bool all_addr, struct Envelope *e);
190 int mutt_pattern_func(struct Context *ctx, int op, char *prompt);
191 int mutt_pattern_alias_func(int op, char *prompt, char *title, struct AliasMenuData *mdata, struct Context *ctx, struct Menu *menu);
192 int mutt_search_command(struct Context *ctx, struct Mailbox *m, int cur, int op);
193 int mutt_search_alias_command(struct Context *ctx, struct Menu *menu, int cur, int op);
194 
195 bool mutt_limit_current_thread(struct Context *ctx, struct Email *e);
196 
197 #endif /* MUTT_PATTERN_LIB_H */
MUTT_PAT_PARENT
@ MUTT_PAT_PARENT
Pattern matches parent.
Definition: lib.h:133
Envelope
The header of an Email.
Definition: envelope.h:54
mutt_search_command
int mutt_search_command(struct Context *ctx, struct Mailbox *m, int cur, int op)
Perform a search.
Definition: pattern.c:493
MUTT_PAT_CRYPT_ENCRYPT
@ MUTT_PAT_CRYPT_ENCRYPT
Message is encrypted.
Definition: lib.h:164
MUTT_PAT_DATE
@ MUTT_PAT_DATE
Pattern matches 'Date:' field.
Definition: lib.h:140
Pattern::regex
regex_t * regex
Compiled regex, for non-pattern matching.
Definition: lib.h:88
MUTT_PAT_PERSONAL_RECIP
@ MUTT_PAT_PERSONAL_RECIP
Email is addressed to the user.
Definition: lib.h:159
MUTT_PAT_SCORE
@ MUTT_PAT_SCORE
Pattern matches email's score.
Definition: lib.h:153
Mailbox
A mailbox.
Definition: mailbox.h:81
MUTT_PAT_LIST
@ MUTT_PAT_LIST
Email is on mailing list.
Definition: lib.h:157
PatternCache::pers_recip_one
int pers_recip_one
~p
Definition: lib.h:116
mutt_is_list_recipient
int mutt_is_list_recipient(bool all_addr, struct Envelope *e)
Matches known mailing lists.
Definition: exec.c:440
Pattern::is_multi
bool is_multi
Multiple case (only for ~I pattern now)
Definition: lib.h:83
Buffer
String manipulation buffer.
Definition: buffer.h:33
PatternCache::sub_one
int sub_one
~u
Definition: lib.h:114
MUTT_PAT_TO
@ MUTT_PAT_TO
Pattern matches 'To:' field.
Definition: lib.h:135
MUTT_PAT_HORMEL
@ MUTT_PAT_HORMEL
Pattern matches email's spam score.
Definition: lib.h:149
MUTT_PAT_COLLAPSED
@ MUTT_PAT_COLLAPSED
Thread is collapsed.
Definition: lib.h:137
MUTT_PAT_OR
@ MUTT_PAT_OR
Either pattern can match.
Definition: lib.h:131
mutt_pattern_func
int mutt_pattern_func(struct Context *ctx, int op, char *prompt)
Perform some Pattern matching.
Definition: pattern.c:344
MUTT_PAT_PERSONAL_FROM
@ MUTT_PAT_PERSONAL_FROM
Email is from the user.
Definition: lib.h:160
MUTT_PAT_MIMETYPE
@ MUTT_PAT_MIMETYPE
Pattern matches MIME type.
Definition: lib.h:170
SLIST_HEAD
SLIST_HEAD(PatternList, Pattern)
C_ThoroughSearch
bool C_ThoroughSearch
Config: Decode headers and messages before searching them.
Definition: config.c:38
PatternCache::pers_from_all
int pers_from_all
^~P
Definition: lib.h:117
Context
The "current" mailbox.
Definition: context.h:38
Pattern::dynamic
bool dynamic
Evaluate date ranges at run time.
Definition: lib.h:81
MUTT_PAT_FROM
@ MUTT_PAT_FROM
Pattern matches 'From:' field.
Definition: lib.h:139
MUTT_PAT_PGP_KEY
@ MUTT_PAT_PGP_KEY
Message has PGP key.
Definition: lib.h:165
MUTT_PAT_SERVERSEARCH
@ MUTT_PAT_SERVERSEARCH
Server-side pattern matches.
Definition: lib.h:167
PatternCompFlags
uint8_t PatternCompFlags
Flags for mutt_pattern_comp(), e.g. MUTT_PC_FULL_MSG.
Definition: lib.h:63
MUTT_PAT_SUBJECT
@ MUTT_PAT_SUBJECT
Pattern matches 'Subject:' field.
Definition: lib.h:138
MUTT_PAT_SUBSCRIBED_LIST
@ MUTT_PAT_SUBSCRIBED_LIST
Email is on subscribed mailing list.
Definition: lib.h:158
Group
A set of email addresses.
Definition: group.h:39
PatternCache::pers_recip_all
int pers_recip_all
^~p
Definition: lib.h:115
mutt_is_subscribed_list_recipient
int mutt_is_subscribed_list_recipient(bool all_addr, struct Envelope *e)
Matches subscribed mailing lists.
Definition: exec.c:427
AliasView
GUI data wrapping an Alias.
Definition: gui.h:36
PatternType
PatternType
Types of pattern to match.
Definition: lib.h:128
MUTT_PAT_BODY
@ MUTT_PAT_BODY
Pattern matches email's body.
Definition: lib.h:147
MUTT_PAT_DRIVER_TAGS
@ MUTT_PAT_DRIVER_TAGS
Pattern matches message tags.
Definition: lib.h:168
Pattern::min
int min
Minimum for range checks.
Definition: lib.h:84
Pattern::ign_case
bool ign_case
Ignore case for local string_match searches.
Definition: lib.h:79
PatternCache::list_all
int list_all
^~l
Definition: lib.h:111
MUTT_PAT_DATE_RECEIVED
@ MUTT_PAT_DATE_RECEIVED
Pattern matches date received.
Definition: lib.h:141
MUTT_PAT_ID
@ MUTT_PAT_ID
Pattern matches email's Message-Id.
Definition: lib.h:145
lib.h
mutt_limit_current_thread
bool mutt_limit_current_thread(struct Context *ctx, struct Email *e)
Limit the email view to the current thread.
Definition: pattern.c:190
MUTT_PAT_HEADER
@ MUTT_PAT_HEADER
Pattern matches email's header.
Definition: lib.h:148
Pattern::is_alias
bool is_alias
Is there an alias for this Address?
Definition: lib.h:80
MUTT_PAT_REFERENCE
@ MUTT_PAT_REFERENCE
Pattern matches 'References:' or 'In-Reply-To:' field.
Definition: lib.h:155
MUTT_PAT_CC
@ MUTT_PAT_CC
Pattern matches 'Cc:' field.
Definition: lib.h:136
Pattern::all_addr
bool all_addr
All Addresses in the list must match.
Definition: lib.h:76
MUTT_PAT_ID_EXTERNAL
@ MUTT_PAT_ID_EXTERNAL
Message-Id is among results from an external query.
Definition: lib.h:146
MUTT_PAT_AND
@ MUTT_PAT_AND
Both patterns must match.
Definition: lib.h:130
MUTT_PAT_BROKEN
@ MUTT_PAT_BROKEN
Message is part of a broken thread.
Definition: lib.h:144
MUTT_PAT_WHOLE_MSG
@ MUTT_PAT_WHOLE_MSG
Pattern matches raw email text.
Definition: lib.h:150
MUTT_PAT_SENDER
@ MUTT_PAT_SENDER
Pattern matches sender.
Definition: lib.h:151
Pattern::string_match
bool string_match
Check a string for a match.
Definition: lib.h:77
Pattern::pat_not
bool pat_not
Pattern should be inverted (not)
Definition: lib.h:75
MUTT_PAT_THREAD
@ MUTT_PAT_THREAD
Pattern matches email thread.
Definition: lib.h:132
PatternCache::sub_all
int sub_all
^~u
Definition: lib.h:113
MUTT_PAT_MAX
@ MUTT_PAT_MAX
Definition: lib.h:174
MUTT_PAT_CHILDREN
@ MUTT_PAT_CHILDREN
Pattern matches a child email.
Definition: lib.h:134
PatternExecFlags
uint8_t PatternExecFlags
Flags for mutt_pattern_exec(), e.g. MUTT_MATCH_FULL_ADDRESS.
Definition: lib.h:97
MUTT_PAT_DUPLICATED
@ MUTT_PAT_DUPLICATED
Duplicate message.
Definition: lib.h:142
mutt_search_alias_command
int mutt_search_alias_command(struct Context *ctx, struct Menu *menu, int cur, int op)
Perform a search.
Definition: pattern.c:642
mutt_pattern_comp
struct PatternList * mutt_pattern_comp(struct Context *ctx, const char *s, PatternCompFlags flags, struct Buffer *err)
Create a Pattern.
Definition: compile.c:1082
MUTT_PAT_NEWSGROUPS
@ MUTT_PAT_NEWSGROUPS
Pattern matches newsgroup.
Definition: lib.h:172
mutt_check_simple
void mutt_check_simple(struct Buffer *s, const char *simple)
Convert a simple search into a real request.
Definition: pattern.c:111
Pattern::op
short op
Operation, e.g. MUTT_PAT_SCORE.
Definition: lib.h:74
MUTT_MT_MAX
@ MUTT_MT_MAX
Definition: mutt.h:110
dlg_select_pattern
bool dlg_select_pattern(char *buf, size_t buflen)
Show menu to select a Pattern.
Definition: dlgpattern.c:262
mutt_pattern_exec
int mutt_pattern_exec(struct Pattern *pat, PatternExecFlags flags, struct Mailbox *m, struct Email *e, struct PatternCache *cache)
Match a pattern against an email header.
Definition: exec.c:738
MUTT_PAT_CRYPT_SIGN
@ MUTT_PAT_CRYPT_SIGN
Message is signed.
Definition: lib.h:162
mutt_pattern_free
void mutt_pattern_free(struct PatternList **pat)
Free a Pattern.
Definition: compile.c:1029
Pattern::p
union Pattern::@2 p
MUTT_PAT_ADDRESS
@ MUTT_PAT_ADDRESS
Pattern matches any address field.
Definition: lib.h:161
MUTT_PAT_UNREFERENCED
@ MUTT_PAT_UNREFERENCED
Message is unreferenced in the thread.
Definition: lib.h:143
MUTT_PAT_SIZE
@ MUTT_PAT_SIZE
Pattern matches email's size.
Definition: lib.h:154
mutt_pattern_alias_exec
int mutt_pattern_alias_exec(struct Pattern *pat, PatternExecFlags flags, struct AliasView *av, struct PatternCache *cache)
Match a pattern against an alias.
Definition: exec.c:1041
MUTT_PAT_XLABEL
@ MUTT_PAT_XLABEL
Pattern matches keyword/label.
Definition: lib.h:166
mutt.h
Pattern::group
struct Group * group
Address group if group_match is set.
Definition: lib.h:89
MUTT_PAT_MESSAGE
@ MUTT_PAT_MESSAGE
Pattern matches message number.
Definition: lib.h:152
AliasMenuData
AliasMenuData - AliasView array wrapper with Pattern information.
Definition: gui.h:53
mutt_pattern_alias_func
int mutt_pattern_alias_func(int op, char *prompt, char *title, struct AliasMenuData *mdata, struct Context *ctx, struct Menu *menu)
Perform some Pattern matching for Alias.
Definition: pattern.c:241
ConfigSet
Container for lots of config items.
Definition: set.h:228
Pattern::max
int max
Maximum for range checks.
Definition: lib.h:85
MUTT_PAT_MIMEATTACH
@ MUTT_PAT_MIMEATTACH
Pattern matches number of attachments.
Definition: lib.h:169
Pattern::multi_cases
struct ListHead multi_cases
Multiple strings for ~I pattern.
Definition: lib.h:91
Pattern::str
char * str
String, if string_match is set.
Definition: lib.h:90
PatternCache::list_one
int list_one
~l
Definition: lib.h:112
Pattern::sendmode
bool sendmode
Evaluate searches in send-mode.
Definition: lib.h:82
Email
The envelope/body of an email.
Definition: email.h:37
MUTT_PAT_CRYPT_VERIFIED
@ MUTT_PAT_CRYPT_VERIFIED
Message is crypographically verified.
Definition: lib.h:163
PatternCache::pers_from_one
int pers_from_one
~P
Definition: lib.h:118
Pattern::SLIST_ENTRY
SLIST_ENTRY(Pattern) entries
Linked list.
mutt_which_case
int mutt_which_case(const char *s)
Menu
GUI selectable list of items.
Definition: mutt_menu.h:52
Pattern::group_match
bool group_match
Check a group of Addresses.
Definition: lib.h:78
Pattern
A simple (non-regex) pattern.
Definition: lib.h:72
MUTT_PAT_RECIPIENT
@ MUTT_PAT_RECIPIENT
User is a recipient of the email.
Definition: lib.h:156
PatternCache
Cache commonly-used patterns.
Definition: lib.h:109
Pattern::child
struct PatternList * child
Arguments to logical operation.
Definition: lib.h:86