return true;
}
- if (mutt_regexlist_match(Alternates, addr->mailbox))
+ if (mutt_regexlist_match(&Alternates, addr->mailbox))
{
mutt_debug(5, "yes, %s matched by alternates.\n", addr->mailbox);
- if (mutt_regexlist_match(UnAlternates, addr->mailbox))
+ if (mutt_regexlist_match(&UnAlternates, addr->mailbox))
mutt_debug(5, "but, %s matched by unalternates.\n", addr->mailbox);
else
return true;
bool Weed = false; ///< Config: Filter headers when displaying/forwarding/printing/replying
/* Global variables */
-struct RegexList *NoSpamList = NULL;
+struct RegexList NoSpamList = STAILQ_HEAD_INITIALIZER(NoSpamList);
struct ReplaceList *SpamList = NULL;
struct ListHead Ignore = STAILQ_HEAD_INITIALIZER(Ignore);
struct ListHead UnIgnore = STAILQ_HEAD_INITIALIZER(UnIgnore);
/* Global variables */
extern struct ListHead Ignore;
-extern struct RegexList * NoSpamList;
+extern struct RegexList NoSpamList;
extern struct ReplaceList *SpamList;
extern struct ListHead UnIgnore;
if (mutt_replacelist_match(SpamList, buf, sizeof(buf), line))
{
- if (!mutt_regexlist_match(NoSpamList, line))
+ if (!mutt_regexlist_match(&NoSpamList, line))
{
/* if spam tag already exists, figure out how to amend it */
if (e->spam && *buf)
WHERE struct ListHead InlineAllow INITVAL(STAILQ_HEAD_INITIALIZER(InlineAllow));
WHERE struct ListHead InlineExclude INITVAL(STAILQ_HEAD_INITIALIZER(InlineExclude));
-WHERE struct RegexList *Alternates;
-WHERE struct RegexList *UnAlternates;
-WHERE struct RegexList *MailLists;
-WHERE struct RegexList *UnMailLists;
-WHERE struct RegexList *SubscribedLists;
-WHERE struct RegexList *UnSubscribedLists;
+WHERE struct RegexList Alternates INITVAL(STAILQ_HEAD_INITIALIZER(Alternates));
+WHERE struct RegexList UnAlternates INITVAL(STAILQ_HEAD_INITIALIZER(UnAlternates));
+WHERE struct RegexList MailLists INITVAL(STAILQ_HEAD_INITIALIZER(MailLists));
+WHERE struct RegexList UnMailLists INITVAL(STAILQ_HEAD_INITIALIZER(UnMailLists));
+WHERE struct RegexList SubscribedLists INITVAL(STAILQ_HEAD_INITIALIZER(SubscribedLists));
+WHERE struct RegexList UnSubscribedLists INITVAL(STAILQ_HEAD_INITIALIZER(UnSubscribedLists));
WHERE struct ReplaceList *SubjectRegexList;
WHERE unsigned short Counter;
return;
mutt_hash_delete(Groups, g->name, g);
mutt_addr_free(&g->as);
- mutt_regexlist_free(&g->rs);
+ mutt_regexlist_free(g->rs);
FREE(&g->name);
FREE(&g);
}
*/
static int group_add_regex(struct Group *g, const char *s, int flags, struct Buffer *err)
{
- return mutt_regexlist_add(&g->rs, s, flags, err);
+ return mutt_regexlist_add(g->rs, s, flags, err);
}
/**
*/
static int group_remove_regex(struct Group *g, const char *s)
{
- return mutt_regexlist_remove(&g->rs, s);
+ return mutt_regexlist_remove(g->rs, s);
}
/**
} digest;
struct Md5Ctx ctx;
struct ReplaceList *spam = NULL;
- struct RegexList *nospam = NULL;
hcachever = HCACHEVER;
}
/* Mix in user's nospam list */
- for (nospam = NoSpamList; nospam; nospam = nospam->next)
+ struct RegexListNode *np = NULL;
+ STAILQ_FOREACH(np, &NoSpamList, entries)
{
- mutt_md5_process(nospam->regex->pattern, &ctx);
+ mutt_md5_process(np->regex->pattern, &ctx);
}
/* Get a hash and take its bytes as an (unsigned int) hash version */
*/
bool mutt_is_mail_list(struct Address *addr)
{
- if (!mutt_regexlist_match(UnMailLists, addr->mailbox))
- return mutt_regexlist_match(MailLists, addr->mailbox);
+ if (!mutt_regexlist_match(&UnMailLists, addr->mailbox))
+ return mutt_regexlist_match(&MailLists, addr->mailbox);
return false;
}
*/
bool mutt_is_subscribed_list(struct Address *addr)
{
- if (!mutt_regexlist_match(UnMailLists, addr->mailbox) &&
- !mutt_regexlist_match(UnSubscribedLists, addr->mailbox))
+ if (!mutt_regexlist_match(&UnMailLists, addr->mailbox) &&
+ !mutt_regexlist_match(&UnSubscribedLists, addr->mailbox))
{
- return mutt_regexlist_match(SubscribedLists, addr->mailbox);
+ return mutt_regexlist_match(&SubscribedLists, addr->mailbox);
}
return false;
}
}
FREE(&templ.data);
}
-
/* If not, try to remove from the nospam list. */
else
{
return 0;
}
-
/* MUTT_NOSPAM is for nospam commands. */
else if (data == MUTT_NOSPAM)
{
* @retval 0 Success, Regex compiled and added to the list
* @retval -1 Error, see message in 'err'
*/
-int mutt_regexlist_add(struct RegexList **rl, const char *str, int flags, struct Buffer *err)
+int mutt_regexlist_add(struct RegexList *rl, const char *str, int flags, struct Buffer *err)
{
- struct RegexList *t = NULL, *last = NULL;
+ struct RegexListNode *t = NULL, *last = NULL;
struct Regex *rx = NULL;
if (!str || !*str)
}
/* check to make sure the item is not already on this rl */
- for (last = *rl; last; last = last->next)
+ STAILQ_FOREACH_FROM(last, rl, entries)
{
if (mutt_str_strcasecmp(rx->pattern, last->regex->pattern) == 0)
{
last = NULL;
break;
}
- if (!last->next)
+ if (!STAILQ_NEXT(last, entries))
break;
}
- if (!*rl || last)
+ if (STAILQ_EMPTY(rl) || last)
{
t = mutt_regexlist_new();
t->regex = rx;
if (last)
- last->next = t;
+ STAILQ_INSERT_TAIL(rl, t, entries);
else
- *rl = t;
+ STAILQ_INSERT_HEAD(rl, t, entries);
}
else /* duplicate */
mutt_regex_free(&rx);
* mutt_regexlist_free - Free a RegexList object
* @param rl RegexList to free
*/
-void mutt_regexlist_free(struct RegexList **rl)
+void mutt_regexlist_free(struct RegexList *rl)
{
- struct RegexList *p = NULL;
+ struct RegexListNode *np = STAILQ_FIRST(rl), *next = NULL;
if (!rl)
return;
- while (*rl)
+ while (np)
{
- p = *rl;
- *rl = (*rl)->next;
- mutt_regex_free(&p->regex);
- FREE(&p);
+ mutt_regex_free(&np->regex);
+ next = STAILQ_NEXT(np, entries);
+ FREE(&np);
+ np = next;
}
+
}
/**
*/
bool mutt_regexlist_match(struct RegexList *rl, const char *str)
{
+ struct RegexListNode *np = NULL;
if (!str)
return false;
-
- for (; rl; rl = rl->next)
+ STAILQ_FOREACH(np, rl, entries)
{
- if (!rl->regex || !rl->regex->regex)
+ if (!np->regex || !np->regex->regex)
continue;
- if (regexec(rl->regex->regex, str, 0, NULL, 0) == 0)
+ if (regexec(np->regex->regex, str, 0, NULL, 0) == 0)
{
- mutt_debug(5, "%s matches %s\n", str, rl->regex->pattern);
+ mutt_debug(5, "%s matches %s\n", str, np->regex->pattern);
return true;
}
}
* mutt_regexlist_new - Create a new RegexList
* @retval ptr New RegexList object
*/
-struct RegexList *mutt_regexlist_new(void)
+struct RegexListNode *mutt_regexlist_new(void)
{
- return mutt_mem_calloc(1, sizeof(struct RegexList));
+ return mutt_mem_calloc(1, sizeof(struct RegexListNode));
}
/**
*
* If the pattern is "*", then all the Regexes are removed.
*/
-int mutt_regexlist_remove(struct RegexList **rl, const char *str)
+int mutt_regexlist_remove(struct RegexList *rl, const char *str)
{
- struct RegexList *p = NULL, *last = NULL;
+ struct RegexListNode *np = STAILQ_FIRST(rl), *next = NULL;
int rc = -1;
if (mutt_str_strcmp("*", str) == 0)
}
else
{
- p = *rl;
- last = NULL;
- while (p)
+ while(np)
{
- if (mutt_str_strcasecmp(str, p->regex->pattern) == 0)
- {
- mutt_regex_free(&p->regex);
- if (last)
- last->next = p->next;
- else
- (*rl) = p->next;
- FREE(&p);
- rc = 0;
- }
- else
- {
- last = p;
- p = p->next;
- }
+ if (mutt_str_strcasecmp(str, np->regex->pattern) == 0)
+ mutt_regex_free(&np->regex);
+ next = STAILQ_NEXT(np, entries);
+ FREE(&np);
+ np = next;
}
+ rc = 0;
}
return rc;
}
#include <stddef.h>
#include <regex.h>
#include <stdbool.h>
+#include "mutt/queue.h"
struct Buffer;
};
/**
- * struct RegexList - List of regular expressions
+ * struct RegexListNode - List of regular expressions
*/
-struct RegexList
+struct RegexListNode
{
- struct Regex *regex; /**< Regex containing a regular expression */
- struct RegexList *next; /**< Next item in list */
+ struct Regex *regex; /**< Regex containing a regular expression */
+ STAILQ_ENTRY(RegexListNode) entries; /**< Next item in list */
};
+STAILQ_HEAD(RegexList, RegexListNode);
+
/**
* struct ReplaceList - List of regular expressions
*/
struct Regex * mutt_regex_create(const char *str, int flags, struct Buffer *err);
void mutt_regex_free(struct Regex **r);
-int mutt_regexlist_add(struct RegexList **rl, const char *str, int flags, struct Buffer *err);
-void mutt_regexlist_free(struct RegexList **rl);
+int mutt_regexlist_add(struct RegexList *rl, const char *str, int flags, struct Buffer *err);
+void mutt_regexlist_free(struct RegexList *rl);
bool mutt_regexlist_match(struct RegexList *rl, const char *str);
-struct RegexList * mutt_regexlist_new(void);
-int mutt_regexlist_remove(struct RegexList **rl, const char *str);
+struct RegexListNode * mutt_regexlist_new(void);
+int mutt_regexlist_remove(struct RegexList *rl, const char *str);
int mutt_replacelist_add(struct ReplaceList **rl, const char *pat, const char *templ, struct Buffer *err);
char * mutt_replacelist_apply(struct ReplaceList *rl, char *buf, size_t buflen, const char *str);