2 * Copyright (C) 2006 Thomas Roessler <roessler@does-not-exist.org>
3 * Copyright (C) 2009 Rocco Rutte <pdmef@gmx.net>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 #include "mutt_curses.h"
26 #include "mutt_regex.h"
34 #include <sys/utsname.h>
38 group_t *mutt_pattern_group (const char *k)
45 if (!(p = hash_find (Groups, k)))
47 dprint (2, (debugfile, "mutt_pattern_group: Creating group %s.\n", k));
48 p = safe_calloc (1, sizeof (group_t));
49 p->name = safe_strdup (k);
50 hash_insert (Groups, p->name, p, 0);
56 static void mutt_group_remove (group_t *g)
60 hash_delete (Groups, g->name, g, NULL);
61 rfc822_free_address (&g->as);
62 mutt_free_rx_list (&g->rs);
67 int mutt_group_context_clear (group_context_t **ctx)
70 for ( ; ctx && *ctx; (*ctx) = t)
72 mutt_group_remove ((*ctx)->g);
74 FREE(ctx); /* __FREE_CHECKED__ */
79 static int empty_group (group_t *g)
83 return !g->as && !g->rs;
86 void mutt_group_context_add (group_context_t **ctx, group_t *group)
88 for (; *ctx; ctx = &((*ctx)->next))
90 if ((*ctx)->g == group)
94 *ctx = safe_calloc (1, sizeof (group_context_t));
98 void mutt_group_context_destroy (group_context_t **ctx)
101 for (; *ctx; *ctx = p)
104 FREE (ctx); /* __FREE_CHECKED__ */
108 void mutt_group_add_adrlist (group_t *g, ADDRESS *a)
117 for (p = &g->as; *p; p = &((*p)->next))
120 q = rfc822_cpy_adr (a, 0);
121 q = mutt_remove_xrefs (g->as, q);
125 static int mutt_group_remove_adrlist (group_t *g, ADDRESS *a)
134 for (p = a; p; p = p->next)
135 rfc822_remove_from_adrlist (&g->as, p->mailbox);
140 static int mutt_group_add_rx (group_t *g, const char *s, int flags, BUFFER *err)
142 return mutt_add_to_rx_list (&g->rs, s, flags, err);
145 static int mutt_group_remove_rx (group_t *g, const char *s)
147 return mutt_remove_from_rx_list (&g->rs, s);
150 void mutt_group_context_add_adrlist (group_context_t *ctx, ADDRESS *a)
152 for (; ctx; ctx = ctx->next)
153 mutt_group_add_adrlist (ctx->g, a);
156 int mutt_group_context_remove_adrlist (group_context_t *ctx, ADDRESS * a)
160 for (; (!rv) && ctx; ctx = ctx->next)
162 rv = mutt_group_remove_adrlist (ctx->g, a);
163 if (empty_group (ctx->g))
164 mutt_group_remove (ctx->g);
170 int mutt_group_context_add_rx (group_context_t *ctx, const char *s, int flags, BUFFER *err)
174 for (; (!rv) && ctx; ctx = ctx->next)
175 rv = mutt_group_add_rx (ctx->g, s, flags, err);
180 int mutt_group_context_remove_rx (group_context_t *ctx, const char *s)
184 for (; (!rv) && ctx; ctx = ctx->next)
186 rv = mutt_group_remove_rx (ctx->g, s);
187 if (empty_group (ctx->g))
188 mutt_group_remove (ctx->g);
194 int mutt_group_match (group_t *g, const char *s)
200 if (mutt_match_rx_list (s, g->rs))
202 for (ap = g->as; ap; ap = ap->next)
203 if (ap->mailbox && !mutt_strcasecmp (s, ap->mailbox))