NeoMutt  2024-10-02-37-gfa9146
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
score.h File Reference

Routines for adding user scores to emails. More...

#include <stdbool.h>
#include <stdint.h>
#include "core/lib.h"
+ Include dependency graph for score.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void mutt_check_rescore (struct Mailbox *m)
 Do the emails need to have their scores recalculated?
 
enum CommandResult mutt_parse_score (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'score' command - Implements Command::parse() -.
 
enum CommandResult mutt_parse_unscore (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'unscore' command - Implements Command::parse() -.
 
void mutt_score_message (struct Mailbox *m, struct Email *e, bool upd_mbox)
 Apply scoring to an email.
 

Detailed Description

Routines for adding user scores to emails.

Authors
  • Richard Russon

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file score.h.

Function Documentation

◆ mutt_check_rescore()

void mutt_check_rescore ( struct Mailbox m)

Do the emails need to have their scores recalculated?

Parameters
mMailbox

Definition at line 67 of file score.c.

68{
69 const bool c_score = cs_subset_bool(NeoMutt->sub, "score");
70 if (OptNeedRescore && c_score)
71 {
72 const enum SortType c_sort = cs_subset_sort(NeoMutt->sub, "sort");
73 const enum SortType c_sort_aux = cs_subset_sort(NeoMutt->sub, "sort_aux");
74 if (((c_sort & SORT_MASK) == SORT_SCORE) || ((c_sort_aux & SORT_MASK) == SORT_SCORE))
75 {
76 OptNeedResort = true;
78 OptSortSubthreads = true;
79 }
80
81 mutt_debug(LL_NOTIFY, "NT_SCORE: %p\n", (void *) m);
82 notify_send(m->notify, NT_SCORE, 0, NULL);
83 }
84 OptNeedRescore = false;
85}
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:47
short cs_subset_sort(const struct ConfigSubset *sub, const char *name)
Get a sort config item by name.
Definition: helpers.c:266
bool OptNeedRescore
(pseudo) set when the 'score' command is used
Definition: globals.c:65
bool OptSortSubthreads
(pseudo) used when $sort_aux changes
Definition: globals.c:72
bool OptNeedResort
(pseudo) used to force a re-sort
Definition: globals.c:66
#define mutt_debug(LEVEL,...)
Definition: logging2.h:89
@ LL_NOTIFY
Log of notifications.
Definition: logging2.h:48
bool notify_send(struct Notify *notify, enum NotifyType event_type, int event_subtype, void *event_data)
Send out a notification message.
Definition: notify.c:173
#define mutt_using_threads()
Definition: mutt_thread.h:114
@ NT_SCORE
Email scoring has changed.
Definition: notify_type.h:54
#define SORT_MASK
Mask for the sort id.
Definition: sort2.h:70
SortType
Methods for sorting.
Definition: sort2.h:34
@ SORT_SCORE
Sort by the email's score.
Definition: sort2.h:44
struct Notify * notify
Notifications: NotifyMailbox, EventMailbox.
Definition: mailbox.h:145
Container for Accounts, Notifications.
Definition: neomutt.h:42
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:46
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_score_message()

void mutt_score_message ( struct Mailbox m,
struct Email e,
bool  upd_mbox 
)

Apply scoring to an email.

Parameters
mMailbox
eEmail
upd_mboxIf true, update the Mailbox too

Definition at line 164 of file score.c.

165{
166 struct Score *tmp = NULL;
167 struct PatternCache cache = { 0 };
168
169 e->score = 0; /* in case of re-scoring */
170 for (tmp = ScoreList; tmp; tmp = tmp->next)
171 {
172 if (mutt_pattern_exec(SLIST_FIRST(tmp->pat), MUTT_MATCH_FULL_ADDRESS, NULL, e, &cache) > 0)
173 {
174 if (tmp->exact || (tmp->val == 9999) || (tmp->val == -9999))
175 {
176 e->score = tmp->val;
177 break;
178 }
179 e->score += tmp->val;
180 }
181 }
182 if (e->score < 0)
183 e->score = 0;
184
185 const short c_score_threshold_delete = cs_subset_number(NeoMutt->sub, "score_threshold_delete");
186 const short c_score_threshold_flag = cs_subset_number(NeoMutt->sub, "score_threshold_flag");
187 const short c_score_threshold_read = cs_subset_number(NeoMutt->sub, "score_threshold_read");
188
189 if (e->score <= c_score_threshold_delete)
190 mutt_set_flag(m, e, MUTT_DELETE, true, upd_mbox);
191 if (e->score <= c_score_threshold_read)
192 mutt_set_flag(m, e, MUTT_READ, true, upd_mbox);
193 if (e->score >= c_score_threshold_flag)
194 mutt_set_flag(m, e, MUTT_FLAG, true, upd_mbox);
195}
short cs_subset_number(const struct ConfigSubset *sub, const char *name)
Get a number config item by name.
Definition: helpers.c:143
bool 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:1149
void mutt_set_flag(struct Mailbox *m, struct Email *e, enum MessageType flag, bool bf, bool upd_mbox)
Set a flag on an email.
Definition: flags.c:57
@ MUTT_READ
Messages that have been read.
Definition: mutt.h:73
@ MUTT_FLAG
Flagged messages.
Definition: mutt.h:79
@ MUTT_DELETE
Messages to be deleted.
Definition: mutt.h:75
#define MUTT_MATCH_FULL_ADDRESS
Match the full address.
Definition: lib.h:105
#define SLIST_FIRST(head)
Definition: queue.h:229
static struct Score * ScoreList
Linked list of email scoring rules.
Definition: score.c:61
int score
Message score.
Definition: email.h:113
Cache commonly-used patterns.
Definition: lib.h:116
Scoring rule for email.
Definition: score.c:52
bool exact
If this rule matches, don't evaluate any more.
Definition: score.c:56
struct PatternList * pat
Definition: score.c:54
int val
Definition: score.c:55
struct Score * next
Linked list.
Definition: score.c:57
+ Here is the call graph for this function:
+ Here is the caller graph for this function: