From: Pierre Habouzit Date: Thu, 29 Mar 2007 23:28:38 +0000 (+0200) Subject: move smap/nospam into the mime module. X-Git-Url: http://git.madism.org/?a=commitdiff_plain;h=11a177822f648694f442b3038fdc60a4e50e6edb;p=apps%2Fmadmutt.git move smap/nospam into the mime module. Signed-off-by: Pierre Habouzit --- diff --git a/globals.h b/globals.h index 5ab1bb2..b3289d7 100644 --- a/globals.h +++ b/globals.h @@ -166,8 +166,6 @@ WHERE rx_t *MailLists INITVAL (0); WHERE rx_t *UnMailLists INITVAL (0); WHERE rx_t *SubscribedLists INITVAL (0); WHERE rx_t *UnSubscribedLists INITVAL (0); -WHERE rx_t *SpamList INITVAL (0); -WHERE rx_t *NoSpamList INITVAL (0); /* bit vector for boolean variables */ #ifdef MAIN_C diff --git a/init.c b/init.c index ff02dce..775cb21 100644 --- a/init.c +++ b/init.c @@ -557,52 +557,6 @@ add_to_rx_list(rx_t **list, const char *s, int flags, BUFFER *err) return 0; } -static int add_to_spam_list(rx_t **list, const char *pat, - const char *templ, BUFFER * err) -{ - rx_t *rx; - - if (m_strisempty(pat) || !templ) - return 0; - - if (!(rx = rx_compile (pat, REG_ICASE))) { - snprintf (err->data, err->dsize, _("Bad regexp: %s"), pat); - return -1; - } - - /* check to make sure the item is not already on this list */ - while (*list) { - if (!ascii_strcasecmp(rx->pattern, (*list)->pattern)) { - rx_t *tmp = rx_list_pop(list); - rx_delete(&tmp); - } else { - list = &(*list)->next; - } - } - - *list = rx; - rx_set_template(rx, templ); - return 0; -} - -static int remove_from_spam_list (rx_t ** list, const char *pat) -{ - int nremoved = 0; - - while (*list) { - if (!m_strcmp((*list)->pattern, pat)) { - rx_t *spam = rx_list_pop(list); - rx_delete(&spam); - nremoved++; - } else { - list = &(*list)->next; - } - } - - return nremoved; -} - - static void remove_from_list(string_list_t **l, const char *str) { if (!m_strcmp("*", str)) { @@ -722,74 +676,6 @@ static int parse_unalternates (BUFFER * buf, BUFFER * s, return 0; } -static int parse_spam_list (BUFFER * buf, BUFFER * s, unsigned long data, - BUFFER * err) -{ - BUFFER templ; - - p_clear(&templ, 1); - - /* Insist on at least one parameter */ - if (!MoreArgs (s)) { - if (data == M_SPAM) - m_strcpy(err->data, err->dsize, _("spam: no matching pattern")); - else - m_strcpy(err->data, err->dsize, _("nospam: no matching pattern")); - return -1; - } - - /* Extract the first token, a regexp */ - mutt_extract_token (buf, s, 0); - - /* data should be either M_SPAM or M_NOSPAM. M_SPAM is for spam commands. */ - if (data == M_SPAM) { - /* If there's a second parameter, it's a template for the spam tag. */ - if (MoreArgs (s)) { - mutt_extract_token (&templ, s, 0); - - /* Add to the spam list. */ - if (add_to_spam_list (&SpamList, buf->data, templ.data, err) != 0) { - p_delete(&templ.data); - return -1; - } - p_delete(&templ.data); - } - - /* If not, try to remove from the nospam list. */ - else { - remove_from_rx_list (&NoSpamList, buf->data); - } - - return 0; - } - - /* M_NOSPAM is for nospam commands. */ - else if (data == M_NOSPAM) { - /* nospam only ever has one parameter. */ - - /* "*" is a special case. */ - if (!m_strcmp(buf->data, "*")) { - rx_list_wipe(&SpamList); - rx_list_wipe(&NoSpamList); - return 0; - } - - /* If it's on the spam list, just remove it. */ - if (remove_from_spam_list (&SpamList, buf->data) != 0) - return 0; - - /* Otherwise, add it to the nospam list. */ - if (add_to_rx_list (&NoSpamList, buf->data, REG_ICASE, err) != 0) - return -1; - - return 0; - } - - /* This should not happen. */ - m_strcpy(err->data, err->dsize, "This is no good at all."); - return -1; -} - static int parse_unlist (BUFFER * buf, BUFFER * s, unsigned long data, BUFFER * err __attribute__ ((unused))) { diff --git a/init.h b/init.h index 8be3a84..92eed15 100644 --- a/init.h +++ b/init.h @@ -778,6 +778,7 @@ struct option_t MuttVars[] = { ** top of threads in the thread tree. Note that when $$hide_limited is ** \fIset\fP, this option will have no effect. */ + {"history", DT_NUM, R_NONE, UL &HistSize, "10" }, /* ** .pp ** This variable controls the size (in number of strings remembered) of @@ -3405,7 +3406,6 @@ const struct mapping_t SortKeyMethods[] = { /* functions used to parse commands in a rc file */ static int parse_list (BUFFER *, BUFFER *, unsigned long, BUFFER *); -static int parse_spam_list (BUFFER *, BUFFER *, unsigned long, BUFFER *); static int parse_unlist (BUFFER *, BUFFER *, unsigned long, BUFFER *); static int parse_attachments (BUFFER *, BUFFER *, unsigned long, BUFFER *); static int parse_unattachments (BUFFER *, BUFFER *, unsigned long, BUFFER *); @@ -3475,8 +3475,6 @@ struct command_t Commands[] = { {"toggle", parse_set, M_SET_INV}, {"unset", parse_set, M_SET_UNSET}, {"source", parse_source, 0}, - {"nospam", parse_spam_list, M_NOSPAM}, - {"spam", parse_spam_list, M_SPAM}, {"subscribe", parse_subscribe, 0}, {"unalias", parse_unalias, 0}, {"unalternates", parse_unalternates, 0}, diff --git a/lib-mime/mime.cpkg b/lib-mime/mime.cpkg index e953211..1e97613 100644 --- a/lib-mime/mime.cpkg +++ b/lib-mime/mime.cpkg @@ -52,6 +52,8 @@ const char *BodyEncodings[] = { "x-uuencoded", }; +rx_t *SpamList = NULL, *NoSpamList = NULL; + @package Mime { /* ** .pp @@ -62,6 +64,23 @@ const char *BodyEncodings[] = { ** separator. */ string_t spam_separator = m_strdup(","); + + void spam(rx_t rx, const string_t tpl) { + rx_set_template(rx, tpl); + rx_list_append(&SpamList, rx); + RETURN(); + }; + + void nospam(rx_t rx) { + if (!m_strcmp(rx->pattern, "*")) { + rx_list_wipe(&SpamList); + rx_list_wipe(&NoSpamList); + rx_delete(&rx); + } else { + rx_list_append(&NoSpamList, rx); + } + RETURN(); + }; }; /****************************************************************************/ diff --git a/lib-mime/mime.h b/lib-mime/mime.h index 8feddfe..7c0b7d3 100644 --- a/lib-mime/mime.h +++ b/lib-mime/mime.h @@ -38,6 +38,7 @@ extern const char MimeSpecials[]; extern const char *BodyTypes[]; extern const char *BodyEncodings[]; +extern rx_t *SpamList, *NoSpamList; /* MIME encoding/decoding global vars */ diff --git a/mutt.h b/mutt.h index 336ebe1..28f8287 100644 --- a/mutt.h +++ b/mutt.h @@ -206,10 +206,6 @@ enum { #define M_SEL_MULTI (1<<1) #define M_SEL_FOLDER (1<<2) -/* flags for parse_spam_list */ -#define M_SPAM 1 -#define M_NOSPAM 2 - /* boolean vars */ enum { OPTALLOW8BIT,