From 455a2390989dfcfc90899785b0d8e9ac94ebd28e Mon Sep 17 00:00:00 2001 From: Pierre Habouzit Date: Sat, 19 May 2007 14:39:19 +0200 Subject: [PATCH] Move score_* to mod_score Signed-off-by: Pierre Habouzit --- .gitignore | 1 + CMakeLists.txt | 2 +- globals.h | 4 ---- init.h | 38 ++-------------------------------- lib-lua/lua-token.gperf | 4 ++++ lib-lua/runtime.c | 10 +++++---- lib-mx/mx.c | 5 +++-- lib-ui/curs_main.c | 1 + mutt.h | 1 - protos.h | 4 ---- score.c => score.cpkg | 45 +++++++++++++++++++++++++++++++++++++---- score.h | 19 +++++++++++++++++ sort.c | 3 ++- 13 files changed, 80 insertions(+), 57 deletions(-) rename score.c => score.cpkg (72%) create mode 100644 score.h diff --git a/.gitignore b/.gitignore index 68048ae..0ba6bc7 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ alias.c buffy.c charset.c crypt.c +score.c config.h charset.gperf diff --git a/CMakeLists.txt b/CMakeLists.txt index c72e2ae..1632fe3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -318,6 +318,7 @@ MADMUTT_SOURCES(madmuttsrc madmuttgen buffy.cpkg charset.cpkg crypt.cpkg + score.cpkg account.c attach.c @@ -345,7 +346,6 @@ MADMUTT_SOURCES(madmuttsrc madmuttgen recvattach.c recvcmd.c remailer.c - score.c send.c sendlib.c send_smtp.c diff --git a/globals.h b/globals.h index 35b9c89..2aea9ea 100644 --- a/globals.h +++ b/globals.h @@ -153,10 +153,6 @@ WHERE short WriteInc; WHERE short MaxDispRecips; WHERE short MaxLineLength; -WHERE short ScoreThresholdDelete; -WHERE short ScoreThresholdRead; -WHERE short ScoreThresholdFlag; - WHERE short DrawFullLine INITVAL (0); WHERE short SidebarWidth; diff --git a/init.h b/init.h index b8dfcc3..49b87d2 100644 --- a/init.h +++ b/init.h @@ -11,13 +11,9 @@ * please see the file GPL in the top level source directory. */ -#ifdef _MAKEDOC -# include "config.h" -#else -# include "sort.h" -#endif - +#include "sort.h" #include "mutt.h" +#include "score.h" #ifndef _MAKEDOC #define DT_MASK 0x0f @@ -1969,36 +1965,6 @@ struct option_t MuttVars[] = { ** possibly including eventual real names. When it is \fIunset\fP, Madmutt will ** override any such real names with the setting of the $realname variable. */ - {"score", DT_BOOL, R_NONE, OPTSCORE, "yes" }, - /* - ** .pp - ** When this variable is \fIunset\fP, scoring is turned off. This can - ** be useful to selectively disable scoring for certain folders when the - ** ``$$score_threshold_delete'' variable and friends are used. - ** - */ - {"score_threshold_delete", DT_NUM, R_NONE, UL &ScoreThresholdDelete, "-1" }, - /* - ** .pp - ** Messages which have been assigned a score equal to or lower than the value - ** of this variable are automatically marked for deletion by Madmutt. Since - ** Madmutt scores are always greater than or equal to zero, the default setting - ** of this variable will never mark a message for deletion. - */ - {"score_threshold_flag", DT_NUM, R_NONE, UL &ScoreThresholdFlag, "9999" }, - /* - ** .pp - ** Messages which have been assigned a score greater than or equal to this - ** variable's value are automatically marked ``flagged''. - */ - {"score_threshold_read", DT_NUM, R_NONE, UL &ScoreThresholdRead, "-1" }, - /* - ** .pp - ** Messages which have been assigned a score equal to or lower than the value - ** of this variable are automatically marked as read by Madmutt. Since - ** Madmutt scores are always greater than or equal to zero, the default setting - ** of this variable will never mark a message read. - */ #ifdef USE_NNTP {"nntp_save_unsubscribed", DT_BOOL, R_NONE, OPTSAVEUNSUB, "no" }, /* diff --git a/lib-lua/lua-token.gperf b/lib-lua/lua-token.gperf index 73c6594..b223dc1 100644 --- a/lib-lua/lua-token.gperf +++ b/lib-lua/lua-token.gperf @@ -130,6 +130,7 @@ exit 0 ## dsn_notify ## dsn_return ## editor +## enable ## envelope_from_address ## file_charset ## force_tls @@ -160,6 +161,9 @@ exit 0 ## spam_separator ## starttls ## sysconfdir +## threshold_delete +## threshold_flag +## threshold_read ## tmpdir ## use_8bitmime ## use_domain diff --git a/lib-lua/runtime.c b/lib-lua/runtime.c index 55bdeef..1957a9c 100644 --- a/lib-lua/runtime.c +++ b/lib-lua/runtime.c @@ -20,11 +20,12 @@ #include #include -#include "../alias.h" #include "../mutt.h" -#include "../charset.h" -#include "../buffy.h" -#include "../crypt.h" +#include "../alias.li" +#include "../buffy.li" +#include "../charset.li" +#include "../crypt.li" +#include "../score.li" #include static lua_State *L; @@ -48,6 +49,7 @@ void luaM_initialize(void) {"Buffy", luaopen_Buffy}, {"mod_ssl", luaopen_mod_ssl}, {"mod_crypt", luaopen_mod_crypt}, + {"mod_score", luaopen_mod_score}, }; int i; diff --git a/lib-mx/mx.c b/lib-mx/mx.c index 10d9d12..d5cf676 100644 --- a/lib-mx/mx.c +++ b/lib-mx/mx.c @@ -26,6 +26,7 @@ #include "copy.h" #include "keymap.h" #include "compress.h" +#include "score.h" #include "dotlock.h" #include @@ -1202,7 +1203,7 @@ void mx_update_context (CONTEXT * ctx, int new_messages) /* p_delete(&h->env->supersedes); should I ? */ if (h2) { h2->superseded = 1; - if (!ctx->counting && option (OPTSCORE)) + if (!ctx->counting && mod_score.enable) mutt_score_message (ctx, h2, 1); } } @@ -1214,7 +1215,7 @@ void mx_update_context (CONTEXT * ctx, int new_messages) if (ctx->subj_hash && h->env->real_subj) hash_insert (ctx->subj_hash, h->env->real_subj, h); - if (option (OPTSCORE)) + if (mod_score.enable) mutt_score_message (ctx, h, 0); } diff --git a/lib-ui/curs_main.c b/lib-ui/curs_main.c index 799d08b..ffa670d 100644 --- a/lib-ui/curs_main.c +++ b/lib-ui/curs_main.c @@ -27,6 +27,7 @@ #include "recvattach.h" #include "buffy.h" #include "thread.h" +#include "score.h" #include diff --git a/mutt.h b/mutt.h index 815b091..4a5db76 100644 --- a/mutt.h +++ b/mutt.h @@ -277,7 +277,6 @@ enum { OPTREVALIAS, OPTREVNAME, OPTREVREAL, - OPTSCORE, OPTSIGDASHES, OPTSORTRE, OPTSPAMSEP, diff --git a/protos.h b/protos.h index 3cc4cad..1753546 100644 --- a/protos.h +++ b/protos.h @@ -53,7 +53,6 @@ void mutt_account_hook (const char *url); void mutt_add_to_reference_headers (ENVELOPE * env, ENVELOPE * curenv, string_list_t *** pp, string_list_t *** qq); int mutt_bounce_message (FILE * fp, HEADER *, address_t *); -void mutt_check_rescore (CONTEXT *); void mutt_default_save (char *, ssize_t, HEADER *); void mutt_display_address (ENVELOPE *); void mutt_edit_content_type (HEADER *, BODY *, FILE *); @@ -80,7 +79,6 @@ void mutt_pipe_message (HEADER *); void mutt_print_message (HEADER *); void mutt_safe_path (char *s, ssize_t l, address_t * a); void mutt_save_path (char *s, ssize_t l, address_t * a); -void mutt_score_message (CONTEXT *, HEADER *, int); void mutt_select_fcc (char *, ssize_t, HEADER *); #define mutt_select_file(A,B,C) _mutt_select_file(A,B,C,NULL,NULL) @@ -129,8 +127,6 @@ int mutt_parse_hook (BUFFER *, BUFFER *, unsigned long, BUFFER *); int mutt_parse_macro (BUFFER *, BUFFER *, unsigned long, BUFFER *); int mutt_parse_push (BUFFER *, BUFFER *, unsigned long, BUFFER *); int mutt_parse_rc_line (const char *, BUFFER *, BUFFER *); -int mutt_parse_score (BUFFER *, BUFFER *, unsigned long, BUFFER *); -int mutt_parse_unscore (BUFFER *, BUFFER *, unsigned long, BUFFER *); int mutt_parse_unhook (BUFFER *, BUFFER *, unsigned long, BUFFER *); int mutt_query_variables (string_list_t * queries); int _mutt_save_message (HEADER *, CONTEXT *, int, int, int); diff --git a/score.c b/score.cpkg similarity index 72% rename from score.c rename to score.cpkg index 7bf3811..40adf78 100644 --- a/score.c +++ b/score.cpkg @@ -12,6 +12,41 @@ #include "mutt.h" #include "sort.h" #include "pattern.h" +#include "score.h" +@import "lib-lua/base.cpkg" + +@package mod_score { + bool enable = 1; + /* + ** .pp + ** When this variable is \fIunset\fP, scoring is turned off. This can + ** be useful to selectively disable scoring for certain folders when the + ** ``$$score_threshold_delete'' variable and friends are used. + ** + */ + int threshold_flag = 9999; + /* + ** .pp + ** Messages which have been assigned a score greater than or equal to this + ** variable's value are automatically marked ``flagged''. + */ + int threshold_delete = -1; + /* + ** .pp + ** Messages which have been assigned a score equal to or lower than the value + ** of this variable are automatically marked for deletion by Madmutt. Since + ** Madmutt scores are always greater than or equal to zero, the default setting + ** of this variable will never mark a message for deletion. + */ + int threshold_read = -1; + /* + ** .pp + ** Messages which have been assigned a score equal to or lower than the value + ** of this variable are automatically marked as read by Madmutt. Since + ** Madmutt scores are always greater than or equal to zero, the default setting + ** of this variable will never mark a message read. + */ +}; typedef struct score_t { char *str; @@ -36,7 +71,7 @@ void mutt_check_rescore (CONTEXT * ctx) { int i; - if (option (OPTNEEDRESCORE) && option (OPTSCORE)) { + if (option (OPTNEEDRESCORE) && mod_score.enable) { if ((Sort & SORT_MASK) == SORT_SCORE || (SortAux & SORT_MASK) == SORT_SCORE) { set_option (OPTNEEDRESORT); @@ -117,11 +152,11 @@ void mutt_score_message (CONTEXT * ctx, HEADER * hdr, int upd_ctx) if (hdr->score < 0) hdr->score = 0; - if (hdr->score <= ScoreThresholdDelete) + if (hdr->score <= mod_score.threshold_delete) _mutt_set_flag (ctx, hdr, M_DELETE, 1, upd_ctx); - if (hdr->score <= ScoreThresholdRead) + if (hdr->score <= mod_score.threshold_flag) _mutt_set_flag (ctx, hdr, M_READ, 1, upd_ctx); - if (hdr->score >= ScoreThresholdFlag) + if (hdr->score >= mod_score.threshold_flag) _mutt_set_flag (ctx, hdr, M_FLAG, 1, upd_ctx); } @@ -148,3 +183,5 @@ int mutt_parse_unscore(BUFFER * buf, BUFFER * s, set_option (OPTNEEDRESCORE); return 0; } + +/* vim:set ft=c: */ diff --git a/score.h b/score.h new file mode 100644 index 0000000..5af0405 --- /dev/null +++ b/score.h @@ -0,0 +1,19 @@ +/* + * Copyright notice from original mutt: + * Copyright (C) 1996-2000 Michael R. Elkins + * + * This file is part of mutt-ng, see http://www.muttng.org/. + * It's licensed under the GNU General Public License, + * please see the file GPL in the top level source directory. + */ + +#ifndef MUTT_SCORE_H +#define MUTT_SCORE_H + +void mutt_check_rescore (CONTEXT *); +int mutt_parse_score (BUFFER *, BUFFER *, unsigned long, BUFFER *); +void mutt_score_message (CONTEXT *, HEADER *, int); +int mutt_parse_unscore (BUFFER *, BUFFER *, unsigned long, BUFFER *); + +#include "score.li" +#endif diff --git a/sort.c b/sort.c index dc1ab61..505679c 100644 --- a/sort.c +++ b/sort.c @@ -15,6 +15,7 @@ #include "alias.h" #include "sort.h" #include "thread.h" +#include "score.h" #include "mutt_idna.h" #define SORTCODE(x) (Sort & SORT_REVERSE) ? -(x) : x @@ -267,7 +268,7 @@ void mutt_sort_headers (CONTEXT * ctx, int init) if (!ctx->quiet) mutt_message _("Sorting mailbox..."); - if (option (OPTNEEDRESCORE) && option (OPTSCORE)) { + if (option (OPTNEEDRESCORE) && mod_score.enable) { for (i = 0; i < ctx->msgcount; i++) mutt_score_message (ctx, ctx->hdrs[i], 1); } -- 2.20.1