NeoMutt  2021-02-05-666-ge300cd
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_commands.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 65 of file score.c.

66 {
67  const bool c_score = cs_subset_bool(NeoMutt->sub, "score");
68  if (OptNeedRescore && c_score)
69  {
70  const short c_sort = cs_subset_sort(NeoMutt->sub, "sort");
71  const short c_sort_aux = cs_subset_sort(NeoMutt->sub, "sort_aux");
72  if (((c_sort & SORT_MASK) == SORT_SCORE) || ((c_sort_aux & SORT_MASK) == SORT_SCORE))
73  {
74  OptNeedResort = true;
75  if (mutt_using_threads())
76  OptSortSubthreads = true;
77  }
78 
79  mutt_debug(LL_NOTIFY, "NT_SCORE: %p\n", m);
80  notify_send(m->notify, NT_SCORE, 0, NULL);
81  }
82  OptNeedRescore = false;
83 }
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:73
Log of notifications.
Definition: logging.h:45
WHERE bool OptNeedResort
(pseudo) used to force a re-sort
Definition: options.h:42
Sort by the email&#39;s score.
Definition: sort2.h:52
WHERE bool OptNeedRescore
(pseudo) set when the &#39;score&#39; command is used
Definition: options.h:41
Container for Accounts, Notifications.
Definition: neomutt.h:36
short cs_subset_sort(const struct ConfigSubset *sub, const char *name)
Get a sort config item by name.
Definition: helpers.c:292
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
#define mutt_using_threads()
Definition: mutt_thread.h:95
Email scoring has changed.
Definition: notify_type.h:51
WHERE bool OptSortSubthreads
(pseudo) used when $sort_aux changes
Definition: options.h:53
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39
struct Notify * notify
Notifications: NotifyMailbox, EventMailbox.
Definition: mailbox.h:148
#define SORT_MASK
Mask for the sort id.
Definition: sort2.h:78
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
+ 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 161 of file score.c.

162 {
163  struct Score *tmp = NULL;
164  struct PatternCache cache = { 0 };
165 
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;
181 
182  const short c_score_threshold_delete =
183  cs_subset_number(NeoMutt->sub, "score_threshold_delete");
184  const short c_score_threshold_flag =
185  cs_subset_number(NeoMutt->sub, "score_threshold_flag");
186  const short c_score_threshold_read =
187  cs_subset_number(NeoMutt->sub, "score_threshold_read");
188 
189  if (e->score <= c_score_threshold_delete)
190  mutt_set_flag_update(m, e, MUTT_DELETE, true, upd_mbox);
191  if (e->score <= c_score_threshold_read)
192  mutt_set_flag_update(m, e, MUTT_READ, true, upd_mbox);
193  if (e->score >= c_score_threshold_flag)
194  mutt_set_flag_update(m, e, MUTT_FLAG, true, upd_mbox);
195 }
struct PatternList * pat
Definition: score.c:53
Flagged messages.
Definition: mutt.h:98
static struct Score * ScoreList
Definition: score.c:59
short cs_subset_number(const struct ConfigSubset *sub, const char *name)
Get a number config item by name.
Definition: helpers.c:169
Container for Accounts, Notifications.
Definition: neomutt.h:36
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
int val
Definition: score.c:54
int score
Message score.
Definition: email.h:89
#define SLIST_FIRST(head)
Definition: queue.h:229
Messages to be deleted.
Definition: mutt.h:94
Messages that have been read.
Definition: mutt.h:92
Scoring rule for email.
Definition: score.c:50
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:1097
struct Score * next
Definition: score.c:56
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39
Cache commonly-used patterns.
Definition: lib.h:105
bool exact
if this rule matches, don&#39;t evaluate any more
Definition: score.c:55
#define MUTT_MATCH_FULL_ADDRESS
Match the full address.
Definition: lib.h:95
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ ScoreList

struct Score* ScoreList = NULL
static

Definition at line 59 of file score.c.