NeoMutt  2023-11-03-107-g582dc1
Teaching an old dog new tricks
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.


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.

  • 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

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?


Definition at line 64 of file score.c.

66 const bool c_score = cs_subset_bool(NeoMutt->sub, "score");
67 if (OptNeedRescore && c_score)
68 {
69 const enum SortType c_sort = cs_subset_sort(NeoMutt->sub, "sort");
70 const enum SortType c_sort_aux = cs_subset_sort(NeoMutt->sub, "sort_aux");
71 if (((c_sort & SORT_MASK) == SORT_SCORE) || ((c_sort_aux & SORT_MASK) == SORT_SCORE))
72 {
73 OptNeedResort = true;
75 OptSortSubthreads = true;
76 }
78 mutt_debug(LL_NOTIFY, "NT_SCORE: %p\n", (void *) m);
79 notify_send(m->notify, NT_SCORE, 0, NULL);
80 }
81 OptNeedRescore = false;
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:48
short cs_subset_sort(const struct ConfigSubset *sub, const char *name)
Get a sort config item by name.
Definition: helpers.c:267
bool OptNeedRescore
(pseudo) set when the 'score' command is used
Definition: globals.c:73
bool OptSortSubthreads
(pseudo) used when $sort_aux changes
Definition: globals.c:80
bool OptNeedResort
(pseudo) used to force a re-sort
Definition: globals.c:74
#define mutt_debug(LEVEL,...)
Definition: logging2.h:89
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:112
Email scoring has changed.
Definition: notify_type.h:54
#define SORT_MASK
Mask for the sort id.
Definition: sort2.h:74
Methods for sorting.
Definition: sort2.h:38
Sort by the email's score.
Definition: sort2.h:48
struct Notify * notify
Notifications: NotifyMailbox, EventMailbox.
Definition: mailbox.h:144
Container for Accounts, Notifications.
Definition: neomutt.h:41
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:45
+ 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.

upd_mboxIf true, update the Mailbox too

Definition at line 161 of file score.c.

163 struct Score *tmp = NULL;
164 struct PatternCache cache = { 0 };
166 e->score = 0; /* in case of re-scoring */
167 for (tmp = ScoreList; tmp; tmp = tmp->next)
168 {
169 if (mutt_pattern_exec(SLIST_FIRST(tmp->pat), MUTT_MATCH_FULL_ADDRESS, NULL, e, &cache) > 0)
170 {
171 if (tmp->exact || (tmp->val == 9999) || (tmp->val == -9999))
172 {
173 e->score = tmp->val;
174 break;
175 }
176 e->score += tmp->val;
177 }
178 }
179 if (e->score < 0)
180 e->score = 0;
182 const short c_score_threshold_delete = cs_subset_number(NeoMutt->sub, "score_threshold_delete");
183 const short c_score_threshold_flag = cs_subset_number(NeoMutt->sub, "score_threshold_flag");
184 const short c_score_threshold_read = cs_subset_number(NeoMutt->sub, "score_threshold_read");
186 if (e->score <= c_score_threshold_delete)
187 mutt_set_flag(m, e, MUTT_DELETE, true, upd_mbox);
188 if (e->score <= c_score_threshold_read)
189 mutt_set_flag(m, e, MUTT_READ, true, upd_mbox);
190 if (e->score >= c_score_threshold_flag)
191 mutt_set_flag(m, e, MUTT_FLAG, true, upd_mbox);
short cs_subset_number(const struct ConfigSubset *sub, const char *name)
Get a number config item by name.
Definition: helpers.c:144
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:1127
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:53
Messages that have been read.
Definition: mutt.h:72
Flagged messages.
Definition: mutt.h:78
Messages to be deleted.
Definition: mutt.h:74
Match the full address.
Definition: lib.h:106
#define SLIST_FIRST(head)
Definition: queue.h:229
static struct Score * ScoreList
Linked list of email scoring rules.
Definition: score.c:58
int score
Message score.
Definition: email.h:114
Cache commonly-used patterns.
Definition: lib.h:117
Scoring rule for email.
Definition: score.c:49
bool exact
If this rule matches, don't evaluate any more.
Definition: score.c:53
struct PatternList * pat
Definition: score.c:51
int val
Definition: score.c:52
struct Score * next
Linked list.
Definition: score.c:54
+ Here is the call graph for this function:
+ Here is the caller graph for this function: