NeoMutt  2025-12-11-769-g906513
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
score.c File Reference

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

#include "config.h"
#include <stdbool.h>
#include <stdlib.h>
#include "mutt/lib.h"
#include "config/lib.h"
#include "core/lib.h"
#include "gui/lib.h"
#include "mutt.h"
#include "score.h"
#include "index/lib.h"
#include "parse/lib.h"
#include "pattern/lib.h"
#include "email.h"
#include "globals.h"
#include "module_data.h"
#include "sort.h"
+ Include dependency graph for score.c:

Go to the source code of this file.

Functions

void score_list_free (struct Score **sp)
 Free a list of scoring rules.
 
enum CommandResult parse_score (const struct Command *cmd, struct Buffer *line, const struct ParseContext *pc, struct ParseError *pe)
 Parse the 'score' command - Implements Command::parse() -.
 
enum CommandResult parse_unscore (const struct Command *cmd, struct Buffer *line, const struct ParseContext *pc, struct ParseError *pe)
 Parse the 'unscore' command - Implements Command::parse() -.
 
void mutt_check_rescore (struct Mailbox *m)
 Do the emails need to have their scores recalculated?
 
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
  • Michael R. Elkins
  • Richard Russon
  • Victor Fernandes
  • Pietro Cerutti

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.c.

Function Documentation

◆ score_list_free()

void score_list_free ( struct Score ** sp)

Free a list of scoring rules.

Parameters
[out]spHead of the Score list

Definition at line 53 of file score.c.

54{
55 if (!sp)
56 return;
57
58 struct Score *sc = *sp;
59 while (sc)
60 {
61 struct Score *next = sc->next;
63 FREE(&sc->str);
64 FREE(&sc);
65 sc = next;
66 }
67 *sp = NULL;
68}
void mutt_pattern_free(struct PatternList **pat)
Free a Pattern.
Definition compile.c:830
#define FREE(x)
Free memory and set the pointer to NULL.
Definition memory.h:68
Scoring rule for email.
Definition score.h:38
char * str
String to match.
Definition score.h:39
struct PatternList * pat
Pattern to match.
Definition score.h:40
struct Score * next
Linked list.
Definition score.h:43
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_check_rescore()

void mutt_check_rescore ( struct Mailbox * m)

Do the emails need to have their scores recalculated?

Parameters
mMailbox

Definition at line 216 of file score.c.

217{
218 const bool c_score = cs_subset_bool(NeoMutt->sub, "score");
219 if (OptNeedRescore && c_score)
220 {
221 const enum EmailSortType c_sort = cs_subset_sort(NeoMutt->sub, "sort");
222 const enum EmailSortType c_sort_aux = cs_subset_sort(NeoMutt->sub, "sort_aux");
223 if (((c_sort & SORT_MASK) == EMAIL_SORT_SCORE) ||
224 ((c_sort_aux & SORT_MASK) == EMAIL_SORT_SCORE))
225 {
226 OptNeedResort = true;
227 if (mutt_using_threads())
228 OptSortSubthreads = true;
229 }
230
231 mutt_debug(LL_NOTIFY, "NT_SCORE: %p\n", (void *) m);
232 notify_send(m->notify, NT_SCORE, 0, NULL);
233 }
234 OptNeedRescore = false;
235}
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
#define SORT_MASK
Mask for the sort id.
Definition sort.h:39
bool OptNeedRescore
(pseudo) set when the 'score' command is used
Definition globals.c:51
bool OptNeedResort
(pseudo) used to force a re-sort
Definition globals.c:52
EmailSortType
Methods for sorting Emails.
Definition sort.h:53
@ EMAIL_SORT_SCORE
Sort by the email's score.
Definition sort.h:58
bool OptSortSubthreads
(pseudo) used when $sort_aux changes
Definition globals.c:57
#define mutt_debug(LEVEL,...)
Definition logging2.h:91
#define mutt_using_threads()
Definition thread.h:113
@ LL_NOTIFY
Log of notifications.
Definition logging2.h:50
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
@ NT_SCORE
Email scoring has changed.
Definition notify_type.h:54
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:49
+ 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 243 of file score.c.

244{
246 struct Score *tmp = NULL;
247 struct PatternCache cache = { 0 };
248
249 e->score = 0; /* in case of re-scoring */
250 for (tmp = mod_data->score_list; tmp; tmp = tmp->next)
251 {
252 if (mutt_pattern_exec(SLIST_FIRST(tmp->pat), MUTT_MATCH_FULL_ADDRESS, NULL, e, &cache) > 0)
253 {
254 if (tmp->exact || (tmp->val == 9999) || (tmp->val == -9999))
255 {
256 e->score = tmp->val;
257 break;
258 }
259 e->score += tmp->val;
260 }
261 }
262 if (e->score < 0)
263 e->score = 0;
264
265 const short c_score_threshold_delete = cs_subset_number(NeoMutt->sub, "score_threshold_delete");
266 const short c_score_threshold_flag = cs_subset_number(NeoMutt->sub, "score_threshold_flag");
267 const short c_score_threshold_read = cs_subset_number(NeoMutt->sub, "score_threshold_read");
268
269 if (e->score <= c_score_threshold_delete)
270 mutt_set_flag(m, e, MUTT_DELETE, true, upd_mbox);
271 if (e->score <= c_score_threshold_read)
272 mutt_set_flag(m, e, MUTT_READ, true, upd_mbox);
273 if (e->score >= c_score_threshold_flag)
274 mutt_set_flag(m, e, MUTT_FLAG, true, upd_mbox);
275}
short cs_subset_number(const struct ConfigSubset *sub, const char *name)
Get a number config item by name.
Definition helpers.c:143
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:54
@ MODULE_ID_EMAIL
ModuleEmail, Email code
Definition module_api.h:64
@ MUTT_READ
Messages that have been read.
Definition mutt.h:92
@ MUTT_FLAG
Flagged messages.
Definition mutt.h:98
@ MUTT_DELETE
Messages to be deleted.
Definition mutt.h:94
void * neomutt_get_module_data(struct NeoMutt *n, enum ModuleId id)
Get the private data for a Module.
Definition neomutt.c:665
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:1151
#define MUTT_MATCH_FULL_ADDRESS
Match the full address.
Definition lib.h:107
#define SLIST_FIRST(head)
Definition queue.h:227
Email private Module data.
Definition module_data.h:32
struct Score * score_list
Linked list of email scoring rules.
Definition module_data.h:44
int score
Message score.
Definition email.h:113
Cache commonly-used patterns.
Definition lib.h:118
bool exact
If this rule matches, don't evaluate any more.
Definition score.h:42
int val
Score to add.
Definition score.h:41
+ Here is the call graph for this function:
+ Here is the caller graph for this function: