From: Pierre Habouzit Date: Fri, 30 Mar 2007 10:32:06 +0000 (+0200) Subject: Move (un)?lists and (un)subscribe to MAlias. X-Git-Url: http://git.madism.org/?a=commitdiff_plain;h=80566f6aedda1e4bdcca38f9cb27101b5ba1029f;p=apps%2Fmadmutt.git Move (un)?lists and (un)subscribe to MAlias. Also minor tweaks on rx_t's Signed-off-by: Pierre Habouzit --- diff --git a/alias.cpkg b/alias.cpkg index 2651026..d1b536c 100644 --- a/alias.cpkg +++ b/alias.cpkg @@ -39,6 +39,8 @@ @import "lib-lua/base.cpkg" static rx_t *Alternates = NULL, *UnAlternates = NULL; +rx_t *MailLists = NULL, *UnMailLists = NULL; +rx_t *SubscribedLists = NULL, *UnSubscribedLists = NULL; @static_package MAlias { /* @@ -70,12 +72,36 @@ static rx_t *Alternates = NULL, *UnAlternates = NULL; rx_list_add(&Alternates, rx); RETURN(); }; - void unalternates(rx_t rx) { rx_list_remove(&Alternates, rx); rx_list_add(&UnAlternates, rx); RETURN(); }; + + void lists(rx_t rx) { + rx_list_remove(&UnMailLists, rx); + rx_list_add(&MailLists, rx); + RETURN(); + }; + void unlists(rx_t rx) { + rx_list_remove(&MailLists, rx); + rx_list_remove(&SubscribedLists, rx); + rx_list_add(&UnMailLists, rx); + RETURN(); + }; + + void subscribe(rx_t rx) { + rx_list_remove(&UnMailLists, rx); + rx_list_remove(&UnSubscribedLists, rx); + rx_list_add(&MailLists, rx); + rx_list_add(&SubscribedLists, rx_dup(rx)); + RETURN(); + }; + void unsubscribe(rx_t rx) { + rx_list_remove(&SubscribedLists, rx); + rx_list_add(&UnSubscribedLists, rx); + RETURN(); + }; }; alias_t *Aliases; diff --git a/alias.h b/alias.h index 29231bf..f785022 100644 --- a/alias.h +++ b/alias.h @@ -44,6 +44,9 @@ typedef struct alias_t { } alias_t; extern alias_t *Aliases; +extern rx_t *MailLists, *UnMailLists; +extern rx_t *SubscribedLists, *UnSubscribedLists; + DO_INIT(alias_t, alias); static inline void alias_wipe(alias_t *a) { diff --git a/browser.c b/browser.c index 4a927d9..aa91a60 100644 --- a/browser.c +++ b/browser.c @@ -462,7 +462,7 @@ static int examine_directory (MUTTMENU * menu, struct browser_state *state, nntp_sync_sidebar (data); if (m_strncmp (prefix, data->group, m_strlen(prefix)) != 0) continue; - if (!((regexec (Mask.rx, data->group, 0, NULL, 0) == 0) ^ Mask.not)) + if (!((regexec (Mask.rx, data->group, 0, NULL, 0) == 0) ^ Mask.neg)) continue; add_folder (menu, state, data->group, NULL, data, data->new); } @@ -511,7 +511,7 @@ static int examine_directory (MUTTMENU * menu, struct browser_state *state, if (m_strncmp(prefix, de->d_name, m_strlen(prefix)) != 0) continue; - if (!((regexec (Mask.rx, de->d_name, 0, NULL, 0) == 0) ^ Mask.not)) + if (!((regexec (Mask.rx, de->d_name, 0, NULL, 0) == 0) ^ Mask.neg)) continue; mutt_concat_path(buffer, sizeof(buffer), d, de->d_name); @@ -1144,7 +1144,7 @@ void _mutt_select_file (char *f, ssize_t flen, int flags, char ***files, if (mutt_get_field (_("File Mask: "), buf, sizeof (buf), 0) == 0) { regex_t *rx = p_new(regex_t, 1); char *s = buf; - int not = 0, err; + int neg = 0, err; buffy = 0; /* assume that the user wants to see everything */ @@ -1153,7 +1153,7 @@ void _mutt_select_file (char *f, ssize_t flen, int flags, char ***files, s = vskipspaces(s); if (*s == '!') { s = vskipspaces(s + 1); - not = 1; + neg = 1; } if ((err = REGCOMP (rx, s, REG_NOSUB)) != 0) { @@ -1167,7 +1167,7 @@ void _mutt_select_file (char *f, ssize_t flen, int flags, char ***files, regfree (Mask.rx); p_delete(&Mask.rx); Mask.rx = rx; - Mask.not = not; + Mask.neg = neg; destroy_state (&state); if (state.imap_browse) { diff --git a/globals.h b/globals.h index 9306abb..310479b 100644 --- a/globals.h +++ b/globals.h @@ -160,11 +160,6 @@ WHERE string_list_t *Ignore INITVAL (0); WHERE string_list_t *MimeLookupList INITVAL (0); WHERE string_list_t *UnIgnore INITVAL (0); -WHERE rx_t *MailLists INITVAL (0); -WHERE rx_t *UnMailLists INITVAL (0); -WHERE rx_t *SubscribedLists INITVAL (0); -WHERE rx_t *UnSubscribedLists INITVAL (0); - /* bit vector for boolean variables */ #ifdef MAIN_C unsigned char Options[(OPTMAX + 7) / 8]; diff --git a/hook.c b/hook.c index 0a8cc51..a84dc00 100644 --- a/hook.c +++ b/hook.c @@ -41,7 +41,7 @@ int mutt_parse_hook (BUFFER * buf __attribute__ ((unused)), BUFFER * s, { hook_t *ptr; BUFFER command, pattern; - int rc, not = 0; + int rc, neg = 0; regex_t *rx = NULL; pattern_t *pat = NULL; char path[_POSIX_PATH_MAX]; @@ -51,7 +51,7 @@ int mutt_parse_hook (BUFFER * buf __attribute__ ((unused)), BUFFER * s, if (*s->dptr == '!') { s->dptr = vskipspaces(s->dptr + 1); - not = 1; + neg = 1; } mutt_extract_token (&pattern, s, 0); @@ -110,7 +110,7 @@ int mutt_parse_hook (BUFFER * buf __attribute__ ((unused)), BUFFER * s, /* check to make sure that a matching hook doesn't already exist */ for (ptr = Hooks; ptr; ptr = ptr->next) { if (ptr->type == (int)data && - ptr->rx.not == not && !m_strcmp(pattern.data, ptr->rx.pattern)) { + ptr->rx.neg == neg && !m_strcmp(pattern.data, ptr->rx.pattern)) { if (data & (M_FOLDERHOOK | M_SENDHOOK | M_SEND2HOOK | M_MESSAGEHOOK | M_ACCOUNTHOOK | M_REPLYHOOK)) { @@ -173,7 +173,7 @@ int mutt_parse_hook (BUFFER * buf __attribute__ ((unused)), BUFFER * s, ptr->pattern = pat; ptr->rx.pattern = pattern.data; ptr->rx.rx = rx; - ptr->rx.not = not; + ptr->rx.neg = neg; return 0; error: @@ -245,7 +245,7 @@ void mutt_folder_hook (char *path) continue; if (tmp->type & M_FOLDERHOOK) { - if ((regexec (tmp->rx.rx, path, 0, NULL, 0) == 0) ^ tmp->rx.not) { + if ((regexec (tmp->rx.rx, path, 0, NULL, 0) == 0) ^ tmp->rx.neg) { if (mutt_parse_rc_line (tmp->command, &token, &err) == -1) { mutt_error ("%s", err.data); mutt_sleep (1); /* pause a moment to let the user see the error */ @@ -286,7 +286,7 @@ void mutt_message_hook (CONTEXT * ctx, HEADER * hdr, int type) continue; if (hook->type & type) - if ((mutt_pattern_exec (hook->pattern, 0, ctx, hdr) > 0) ^ hook->rx.not) + if ((mutt_pattern_exec (hook->pattern, 0, ctx, hdr) > 0) ^ hook->rx.neg) if (mutt_parse_rc_line (hook->command, &token, &err) != 0) { mutt_error ("%s", err.data); mutt_sleep (1); @@ -308,7 +308,7 @@ mutt_addr_hook (char *path, ssize_t pathlen, unsigned long type, CONTEXT * ctx, continue; if (hook->type & type) - if ((mutt_pattern_exec (hook->pattern, 0, ctx, hdr) > 0) ^ hook->rx.not) { + if ((mutt_pattern_exec (hook->pattern, 0, ctx, hdr) > 0) ^ hook->rx.neg) { mutt_make_string (path, pathlen, hook->command, ctx, hdr); return 0; } @@ -370,7 +370,7 @@ static const char *_mutt_string_hook (const char *match, int hook) for (; tmp; tmp = tmp->next) { if ((tmp->type & hook) - && ((match && regexec(tmp->rx.rx, match, 0, NULL, 0) == 0) ^ tmp->rx.not)) + && ((match && regexec(tmp->rx.rx, match, 0, NULL, 0) == 0) ^ tmp->rx.neg)) return (tmp->command); } return (NULL); @@ -396,7 +396,7 @@ void mutt_account_hook (const char *url) if (!(hook->command && (hook->type & M_ACCOUNTHOOK))) continue; - if ((regexec (hook->rx.rx, url, 0, NULL, 0) == 0) ^ hook->rx.not) { + if ((regexec (hook->rx.rx, url, 0, NULL, 0) == 0) ^ hook->rx.neg) { if (mutt_parse_rc_line (hook->command, &token, &err) == -1) { mutt_error ("%s", err.data); mutt_sleep (1); diff --git a/imap/browse.c b/imap/browse.c index 10e9e48..4ce8f30 100644 --- a/imap/browse.c +++ b/imap/browse.c @@ -384,7 +384,7 @@ static void imap_add_folder (char delim, char *folder, int noselect, /* apply filemask filter. This should really be done at menu setup rather * than at scan, since it's so expensive to scan. But that's big changes * to browser.c */ - if (!((regexec (Mask.rx, relpath, 0, NULL, 0) == 0) ^ Mask.not)) { + if (!((regexec (Mask.rx, relpath, 0, NULL, 0) == 0) ^ Mask.neg)) { p_delete(&mx.mbox); return; } diff --git a/init.c b/init.c index 3b57790..8ac9bba 100644 --- a/init.c +++ b/init.c @@ -324,7 +324,7 @@ static int rx_from_string (struct option_t* dst, const char* val, char* errbuf, ssize_t errlen) { rx_t* p = NULL; regex_t* rx = NULL; - int flags = 0, e = 0, not = 0; + int flags = 0, e = 0, neg = 0; char* s = NULL; if (!dst) @@ -351,7 +351,7 @@ static int rx_from_string (struct option_t* dst, const char* val, s = (char*) val; if (m_strcmp(dst->option, "mask") == 0 && *s == '!') { - not = 1; + neg = 1; s++; } @@ -371,7 +371,7 @@ static int rx_from_string (struct option_t* dst, const char* val, m_strreplace(&p->pattern, val); p->rx = rx; - p->not = not; + p->neg = neg; if (m_strcmp(dst->option, "reply_regexp") == 0) mutt_adjust_all_subjects (); @@ -536,27 +536,6 @@ static void add_to_list(string_list_t **list, const char *str) (*list)->data = m_strdup(str); } -static int -add_to_rx_list(rx_t **list, const char *s, int flags, BUFFER *err) -{ - rx_t *rx; - - if (m_strisempty(s)) - return 0; - - if (rx_lookup(list, s)) - return 0; - - rx = rx_compile(s, flags); - if (!rx) { - snprintf(err->data, err->dsize, "Bad regexp: %s\n", s); - return -1; - } - - rx_list_append(list, rx); - return 0; -} - static void remove_from_list(string_list_t **l, const char *str) { if (!m_strcmp("*", str)) { @@ -574,23 +553,6 @@ static void remove_from_list(string_list_t **l, const char *str) } } -static int remove_from_rx_list(rx_t **l, const char *str) -{ - if (m_strcmp("*", str) == 0) { - rx_list_wipe(l); - return 0; - } - - l = rx_lookup(l, str); - if (*l) { - rx_t *r = rx_list_pop(l); - rx_delete(&r); - return 0; - } - - return -1; -} - static int parse_unignore (BUFFER * buf, BUFFER * s, unsigned long data __attribute__ ((unused)), BUFFER * err __attribute__ ((unused))) @@ -630,16 +592,6 @@ static int parse_list(BUFFER * buf, BUFFER * s, unsigned long data, return 0; } -static void _alternates_clean (void) -{ - int i; - - if (Context && Context->msgcount) { - for (i = 0; i < Context->msgcount; i++) - Context->hdrs[i]->recip_valid = 0; - } -} - static int parse_unlist (BUFFER * buf, BUFFER * s, unsigned long data, BUFFER * err __attribute__ ((unused))) { @@ -659,22 +611,6 @@ static int parse_unlist (BUFFER * buf, BUFFER * s, unsigned long data, return 0; } -static int parse_lists (BUFFER * buf, BUFFER * s, - unsigned long data __attribute__ ((unused)), - BUFFER * err) -{ - do { - mutt_extract_token (buf, s, 0); - remove_from_rx_list (&UnMailLists, buf->data); - - if (add_to_rx_list (&MailLists, buf->data, REG_ICASE, err) != 0) - return -1; - } - while (MoreArgs (s)); - - return 0; -} - /* always wise to do what someone else did before */ static void _attachments_clean (void) { int i; @@ -909,59 +845,6 @@ static int parse_unattachments (BUFFER *buf, BUFFER *s, unsigned long data __att return parse_unattach_list(buf, s, listp, err); } -static int parse_unlists (BUFFER * buf, BUFFER * s, - unsigned long data __attribute__ ((unused)), - BUFFER * err __attribute__ ((unused))) -{ - do { - mutt_extract_token (buf, s, 0); - remove_from_rx_list (&SubscribedLists, buf->data); - remove_from_rx_list (&MailLists, buf->data); - - if (m_strcmp(buf->data, "*") && - add_to_rx_list (&UnMailLists, buf->data, REG_ICASE, err) != 0) - return -1; - } - while (MoreArgs (s)); - - return 0; -} - -static int parse_subscribe (BUFFER * buf, BUFFER * s, unsigned long data __attribute__ ((unused)), - BUFFER * err) -{ - do { - mutt_extract_token (buf, s, 0); - remove_from_rx_list (&UnMailLists, buf->data); - remove_from_rx_list (&UnSubscribedLists, buf->data); - - if (add_to_rx_list (&MailLists, buf->data, REG_ICASE, err) != 0) - return -1; - if (add_to_rx_list (&SubscribedLists, buf->data, REG_ICASE, err) != 0) - return -1; - } - while (MoreArgs (s)); - - return 0; -} - -static int parse_unsubscribe (BUFFER * buf, BUFFER * s, - unsigned long data __attribute__ ((unused)), - BUFFER * err __attribute__ ((unused))) -{ - do { - mutt_extract_token (buf, s, 0); - remove_from_rx_list (&SubscribedLists, buf->data); - - if (m_strcmp(buf->data, "*") && - add_to_rx_list (&UnSubscribedLists, buf->data, REG_ICASE, err) != 0) - return -1; - } - while (MoreArgs (s)); - - return 0; -} - static int parse_unalias (BUFFER * buf, BUFFER * s, unsigned long data __attribute__ ((unused)), BUFFER * err __attribute__ ((unused))) diff --git a/init.h b/init.h index cad0fdc..c3943fa 100644 --- a/init.h +++ b/init.h @@ -3409,8 +3409,6 @@ static int parse_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 *); -static int parse_lists (BUFFER *, BUFFER *, unsigned long, BUFFER *); -static int parse_unlists (BUFFER *, BUFFER *, unsigned long, BUFFER *); static int parse_alias (BUFFER *, BUFFER *, unsigned long, BUFFER *); static int parse_unalias (BUFFER *, BUFFER *, unsigned long, BUFFER *); static int parse_ignore (BUFFER *, BUFFER *, unsigned long, BUFFER *); @@ -3419,8 +3417,6 @@ static int parse_source (BUFFER *, BUFFER *, unsigned long, BUFFER *); static int parse_set (BUFFER *, BUFFER *, unsigned long, BUFFER *); static int parse_my_hdr (BUFFER *, BUFFER *, unsigned long, BUFFER *); static int parse_unmy_hdr (BUFFER *, BUFFER *, unsigned long, BUFFER *); -static int parse_subscribe (BUFFER *, BUFFER *, unsigned long, BUFFER *); -static int parse_unsubscribe (BUFFER *, BUFFER *, unsigned long, BUFFER *); struct command_t { const char *name; @@ -3464,23 +3460,19 @@ struct command_t Commands[] = { {"auto_view", parse_list, UL &AutoViewList}, {"hdr_order", parse_list, UL &HeaderOrderList}, {"mime_lookup", parse_list, UL &MimeLookupList}, - {"lists", parse_lists, 0}, {"my_hdr", parse_my_hdr, 0}, {"reset", parse_set, M_SET_RESET}, {"set", parse_set, 0}, {"toggle", parse_set, M_SET_INV}, {"unset", parse_set, M_SET_UNSET}, {"source", parse_source, 0}, - {"subscribe", parse_subscribe, 0}, {"unalias", parse_unalias, 0}, {"unattachments", parse_unattachments, 0}, {"unignore", parse_unignore, 0}, - {"unlists", parse_unlists, 0}, {"unalternative_order", parse_unlist, UL &AlternativeOrderList}, {"unauto_view", parse_unlist, UL &AutoViewList}, {"unhdr_order", parse_unlist, UL &HeaderOrderList}, {"unmime_lookup", parse_unlist, UL &MimeLookupList}, {"unmy_hdr", parse_unmy_hdr, 0}, - {"unsubscribe", parse_unsubscribe, 0}, {NULL, NULL, 0} }; diff --git a/lib-lib/rx.c b/lib-lib/rx.c index d89d234..58e943c 100644 --- a/lib-lib/rx.c +++ b/lib-lib/rx.c @@ -29,7 +29,8 @@ rx_t *rx_compile(const char *s, int flags) rx_t *pp = p_new(rx_t, 1); pp->pattern = m_strdup(s); - pp->rx = p_new(regex_t, 1); + pp->rx = p_new(regex_t, 1); + pp->flags = flags; if (REGCOMP(pp->rx, NONULL(s), flags) != 0) { rx_delete(&pp); @@ -38,6 +39,14 @@ rx_t *rx_compile(const char *s, int flags) return pp; } +rx_t *rx_dup(rx_t *r) +{ + rx_t *res = rx_compile(r->pattern, r->flags); + res->neg = r->neg; + rx_set_template(res, r->tpl); + return res; +} + int rx_validate(const char *s, char *errbuf, ssize_t errlen) { regex_t re; @@ -59,6 +68,8 @@ void rx_set_template(rx_t *rx, const char *tpl) m_strreplace(&rx->tpl, tpl); rx->nmatch = 0; + if (m_strisempty(rx->tpl)) + return; while ((p = strchr(p, '%'))) { if (isdigit(*++p)) { diff --git a/lib-lib/rx.h b/lib-lib/rx.h index fcaba32..6decaa6 100644 --- a/lib-lib/rx.h +++ b/lib-lib/rx.h @@ -40,16 +40,20 @@ typedef struct rx_t { struct rx_t *next; - char *pattern; /* printable version */ - regex_t *rx; /* compiled expression */ - int not; /* do not match */ + unsigned neg : 1; /* do not match */ + int flags; int nmatch; /* nb matches */ + + char *pattern; /* printable version */ char *tpl; /* out template */ + + regex_t *rx; /* compiled expression */ } rx_t; rx_t *rx_compile(const char*, int); void rx_wipe(rx_t *); +rx_t *rx_dup(rx_t *); DO_DELETE(rx_t, rx); DO_SLIST(rx_t, rx, rx_delete); diff --git a/lib-mime/.gitignore b/lib-mime/.gitignore index 5d6768d..64100ce 100644 --- a/lib-mime/.gitignore +++ b/lib-mime/.gitignore @@ -1,2 +1,4 @@ mime-token.h mime-token.c +mime.c +mime.li diff --git a/lib-mime/mime.cpkg b/lib-mime/mime.cpkg index 3da646a..7c74059 100644 --- a/lib-mime/mime.cpkg +++ b/lib-mime/mime.cpkg @@ -67,8 +67,8 @@ rx_t *SpamList = NULL, *NoSpamList = NULL; void spam(rx_t rx, const string_t tpl) { rx_set_template(rx, tpl); - rx_list_add2(&SpamList, &rx); rx_list_remove(&NoSpamList, rx); + rx_list_add2(&SpamList, &rx); RETURN(); };