-
- /* not reached */
-}
-
-static void add_to_list (string_list_t ** list, const char *str)
-{
- string_list_t *t, *last = NULL;
-
- /* don't add a NULL or empty string to the list */
- if (!str || *str == '\0')
- return;
-
- /* check to make sure the item is not already on this list */
- for (last = *list; last; last = last->next) {
- if (ascii_strcasecmp (str, last->data) == 0) {
- /* already on the list, so just ignore it */
- last = NULL;
- break;
- }
- if (!last->next)
- break;
- }
-
- if (!*list || last) {
- t = p_new(string_list_t, 1);
- t->data = m_strdup(str);
- if (last) {
- last->next = t;
- last = last->next;
- }
- else
- *list = last = t;
- }
-}
-
-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 int add_to_spam_list(rx_t **list, const char *pat,
- const char *templ, BUFFER * err)
-{
- rx_t **last, *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 */
- for (last = list; *last; last = &(*last)->next) {
- if (!ascii_strcasecmp(rx->pattern, (*last)->pattern) == 0) {
- rx_t *tmp = rx_list_pop(last);
- rx_delete(&tmp);
- last = rx_list_last(last);
- break;
- }
- }
-
- *last = 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)
-{
- string_list_t *p, *last = NULL;
-
- if (m_strcmp("*", str) == 0)
- string_list_wipe(l); /* ``unCMD *'' means delete all current entries */
- else {
- p = *l;
- last = NULL;
- while (p) {
- if (ascii_strcasecmp (str, p->data) == 0) {
- p_delete(&p->data);
- if (last)
- last->next = p->next;
- else
- (*l) = p->next;
- p_delete(&p);
- }
- else {
- last = p;
- p = p->next;
- }
- }
- }
-}
-
-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;