@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 {
/*
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;
} 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) {
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);
}
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);
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 */
s = vskipspaces(s);
if (*s == '!') {
s = vskipspaces(s + 1);
- not = 1;
+ neg = 1;
}
if ((err = REGCOMP (rx, s, REG_NOSUB)) != 0) {
regfree (Mask.rx);
p_delete(&Mask.rx);
Mask.rx = rx;
- Mask.not = not;
+ Mask.neg = neg;
destroy_state (&state);
if (state.imap_browse) {
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];
{
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];
if (*s->dptr == '!') {
s->dptr = vskipspaces(s->dptr + 1);
- not = 1;
+ neg = 1;
}
mutt_extract_token (&pattern, s, 0);
/* 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)) {
ptr->pattern = pat;
ptr->rx.pattern = pattern.data;
ptr->rx.rx = rx;
- ptr->rx.not = not;
+ ptr->rx.neg = neg;
return 0;
error:
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 */
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);
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;
}
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);
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);
/* 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;
}
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)
s = (char*) val;
if (m_strcmp(dst->option, "mask") == 0 && *s == '!') {
- not = 1;
+ neg = 1;
s++;
}
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 ();
(*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)) {
}
}
-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)))
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)))
{
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;
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)))
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 *);
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;
{"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}
};
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);
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;
m_strreplace(&rx->tpl, tpl);
rx->nmatch = 0;
+ if (m_strisempty(rx->tpl))
+ return;
while ((p = strchr(p, '%'))) {
if (isdigit(*++p)) {
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);
mime-token.h
mime-token.c
+mime.c
+mime.li
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();
};