NeoMutt  2021-10-22-8-g9cb437
Teaching an old dog new tricks
DOXYGEN
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 "email/lib.h"
#include "core/lib.h"
#include "mutt.h"
#include "score.h"
#include "pattern/lib.h"
#include "context.h"
#include "init.h"
#include "mutt_globals.h"
#include "mutt_thread.h"
#include "options.h"
#include "protos.h"
+ Include dependency graph for score.c:

Go to the source code of this file.

Data Structures

struct  Score
 Scoring rule for email. More...
 

Functions

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

Variables

static struct ScoreScoreList = NULL
 

Detailed Description

Routines for adding user scores to emails.

Authors
  • Michael R. Elkins

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

◆ mutt_check_rescore()

void mutt_check_rescore ( struct Mailbox m)

Do the emails need to have their scores recalculated?

Parameters
mMailbox

Definition at line 64 of file score.c.

65 {
66  const bool c_score = cs_subset_bool(NeoMutt->sub, "score");
67  if (OptNeedRescore && c_score)
68  {
69  const short c_sort = cs_subset_sort(NeoMutt->sub, "sort");
70  const short 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;
74  if (mutt_using_threads())
75  OptSortSubthreads = true;
76  }
77 
78  mutt_debug(LL_NOTIFY, "NT_SCORE: %p\n", m);
79  notify_send(m->notify, NT_SCORE, 0, NULL);
80  }
81  OptNeedRescore = false;
82 }
#define mutt_debug(LEVEL,...)
Definition: logging.h:84
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:73
short cs_subset_sort(const struct ConfigSubset *sub, const char *name)
Get a sort config item by name.
Definition: helpers.c:292
@ LL_NOTIFY
Log of notifications.
Definition: logging.h:45
bool notify_send(struct Notify *notify, enum NotifyType event_type, int event_subtype, void *event_data)
Send out a notification message.
Definition: notify.c:171
#define mutt_using_threads()
Definition: mutt_thread.h:100
@ NT_SCORE
Email scoring has changed.
Definition: notify_type.h:51
bool OptNeedRescore
(pseudo) set when the 'score' command is used
Definition: options.h:47
bool OptSortSubthreads
(pseudo) used when $sort_aux changes
Definition: options.h:59
bool OptNeedResort
(pseudo) used to force a re-sort
Definition: options.h:48
#define SORT_MASK
Mask for the sort id.
Definition: sort2.h:78
@ SORT_SCORE
Sort by the email's score.
Definition: sort2.h:52
struct Notify * notify
Notifications: NotifyMailbox, EventMailbox.
Definition: mailbox.h:148
Container for Accounts, Notifications.
Definition: neomutt.h:37
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39
+ 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 160 of file score.c.

161 {
162  struct Score *tmp = NULL;
163  struct PatternCache cache = { 0 };
164 
165  e->score = 0; /* in case of re-scoring */
166  for (tmp = ScoreList; tmp; tmp = tmp->next)
167  {
168  if (mutt_pattern_exec(SLIST_FIRST(tmp->pat), MUTT_MATCH_FULL_ADDRESS, NULL, e, &cache) > 0)
169  {
170  if (tmp->exact || (tmp->val == 9999) || (tmp->val == -9999))
171  {
172  e->score = tmp->val;
173  break;
174  }
175  e->score += tmp->val;
176  }
177  }
178  if (e->score < 0)
179  e->score = 0;
180 
181  const short c_score_threshold_delete =
182  cs_subset_number(NeoMutt->sub, "score_threshold_delete");
183  const short c_score_threshold_flag =
184  cs_subset_number(NeoMutt->sub, "score_threshold_flag");
185  const short c_score_threshold_read =
186  cs_subset_number(NeoMutt->sub, "score_threshold_read");
187 
188  if (e->score <= c_score_threshold_delete)
189  mutt_set_flag_update(m, e, MUTT_DELETE, true, upd_mbox);
190  if (e->score <= c_score_threshold_read)
191  mutt_set_flag_update(m, e, MUTT_READ, true, upd_mbox);
192  if (e->score >= c_score_threshold_flag)
193  mutt_set_flag_update(m, e, MUTT_FLAG, true, upd_mbox);
194 }
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:1099
void mutt_set_flag_update(struct Mailbox *m, struct Email *e, enum MessageType flag, bool bf, bool upd_mbox)
Set a flag on an email.
Definition: flags.c:51
short cs_subset_number(const struct ConfigSubset *sub, const char *name)
Get a number config item by name.
Definition: helpers.c:169
@ 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
#define MUTT_MATCH_FULL_ADDRESS
Match the full address.
Definition: lib.h:95
#define SLIST_FIRST(head)
Definition: queue.h:229
static struct Score * ScoreList
Definition: score.c:58
int score
Message score.
Definition: email.h:113
Cache commonly-used patterns.
Definition: lib.h:106
Scoring rule for email.
Definition: score.c:50
bool exact
if this rule matches, don't evaluate any more
Definition: score.c:54
struct PatternList * pat
Definition: score.c:52
int val
Definition: score.c:53
struct Score * next
Definition: score.c:55
+ Here is the caller graph for this function:

Variable Documentation

◆ ScoreList

struct Score* ScoreList = NULL
static

Definition at line 58 of file score.c.