Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 209 lines (172 sloc) 4.364 kb
14c2920 Imported Upstream version 1.5.18
Antonio Radici authored
1 /*
2 * Copyright (C) 2006 Thomas Roessler <roessler@does-not-exist.org>
594a6a4 Imported Upstream version 1.5.21
Antonio Radici authored
3 * Copyright (C) 2009 Rocco Rutte <pdmef@gmx.net>
4 *
14c2920 Imported Upstream version 1.5.18
Antonio Radici authored
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.
594a6a4 Imported Upstream version 1.5.21
Antonio Radici authored
9 *
14c2920 Imported Upstream version 1.5.18
Antonio Radici authored
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.
594a6a4 Imported Upstream version 1.5.21
Antonio Radici authored
14 *
14c2920 Imported Upstream version 1.5.18
Antonio Radici authored
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.
594a6a4 Imported Upstream version 1.5.21
Antonio Radici authored
18 */
14c2920 Imported Upstream version 1.5.18
Antonio Radici authored
19
20 #if HAVE_CONFIG_H
21 # include "config.h"
22 #endif
23
24 #include "mutt.h"
25 #include "mutt_curses.h"
26 #include "mutt_regex.h"
27 #include "mbyte.h"
28 #include "charset.h"
29
30 #include <ctype.h>
31 #include <stdlib.h>
32 #include <unistd.h>
33 #include <string.h>
34 #include <sys/utsname.h>
35 #include <errno.h>
36 #include <sys/wait.h>
37
38 group_t *mutt_pattern_group (const char *k)
39 {
40 group_t *p;
594a6a4 Imported Upstream version 1.5.21
Antonio Radici authored
41
14c2920 Imported Upstream version 1.5.18
Antonio Radici authored
42 if (!k)
43 return 0;
594a6a4 Imported Upstream version 1.5.21
Antonio Radici authored
44
14c2920 Imported Upstream version 1.5.18
Antonio Radici authored
45 if (!(p = hash_find (Groups, k)))
46 {
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);
51 }
594a6a4 Imported Upstream version 1.5.21
Antonio Radici authored
52
14c2920 Imported Upstream version 1.5.18
Antonio Radici authored
53 return p;
54 }
55
594a6a4 Imported Upstream version 1.5.21
Antonio Radici authored
56 static void mutt_group_remove (group_t *g)
57 {
58 if (!g)
59 return;
60 hash_delete (Groups, g->name, g, NULL);
61 rfc822_free_address (&g->as);
62 mutt_free_rx_list (&g->rs);
63 FREE(&g->name);
64 FREE(&g);
65 }
66
67 int mutt_group_context_clear (group_context_t **ctx)
68 {
69 group_context_t *t;
70 for ( ; ctx && *ctx; (*ctx) = t)
71 {
72 mutt_group_remove ((*ctx)->g);
73 t = (*ctx)->next;
74 FREE(ctx); /* __FREE_CHECKED__ */
75 }
76 return 0;
77 }
78
79 static int empty_group (group_t *g)
80 {
81 if (!g)
82 return -1;
83 return !g->as && !g->rs;
84 }
85
14c2920 Imported Upstream version 1.5.18
Antonio Radici authored
86 void mutt_group_context_add (group_context_t **ctx, group_t *group)
87 {
88 for (; *ctx; ctx = &((*ctx)->next))
89 {
90 if ((*ctx)->g == group)
91 return;
92 }
594a6a4 Imported Upstream version 1.5.21
Antonio Radici authored
93
14c2920 Imported Upstream version 1.5.18
Antonio Radici authored
94 *ctx = safe_calloc (1, sizeof (group_context_t));
95 (*ctx)->g = group;
96 }
97
98 void mutt_group_context_destroy (group_context_t **ctx)
99 {
100 group_context_t *p;
101 for (; *ctx; *ctx = p)
102 {
103 p = (*ctx)->next;
104 FREE (ctx); /* __FREE_CHECKED__ */
105 }
106 }
107
108 void mutt_group_add_adrlist (group_t *g, ADDRESS *a)
109 {
110 ADDRESS **p, *q;
111
112 if (!g)
113 return;
114 if (!a)
115 return;
594a6a4 Imported Upstream version 1.5.21
Antonio Radici authored
116
14c2920 Imported Upstream version 1.5.18
Antonio Radici authored
117 for (p = &g->as; *p; p = &((*p)->next))
118 ;
594a6a4 Imported Upstream version 1.5.21
Antonio Radici authored
119
647ac54 Imported Upstream version 1.5.20
Antonio Radici authored
120 q = rfc822_cpy_adr (a, 0);
14c2920 Imported Upstream version 1.5.18
Antonio Radici authored
121 q = mutt_remove_xrefs (g->as, q);
122 *p = q;
123 }
124
594a6a4 Imported Upstream version 1.5.21
Antonio Radici authored
125 static int mutt_group_remove_adrlist (group_t *g, ADDRESS *a)
126 {
127 ADDRESS *p;
128
129 if (!g)
130 return -1;
131 if (!a)
132 return -1;
133
134 for (p = a; p; p = p->next)
135 rfc822_remove_from_adrlist (&g->as, p->mailbox);
136
137 return 0;
138 }
139
19304f7 Imported Upstream version 1.5.19
Antonio Radici authored
140 static int mutt_group_add_rx (group_t *g, const char *s, int flags, BUFFER *err)
14c2920 Imported Upstream version 1.5.18
Antonio Radici authored
141 {
142 return mutt_add_to_rx_list (&g->rs, s, flags, err);
143 }
144
594a6a4 Imported Upstream version 1.5.21
Antonio Radici authored
145 static int mutt_group_remove_rx (group_t *g, const char *s)
146 {
147 return mutt_remove_from_rx_list (&g->rs, s);
148 }
149
14c2920 Imported Upstream version 1.5.18
Antonio Radici authored
150 void mutt_group_context_add_adrlist (group_context_t *ctx, ADDRESS *a)
151 {
152 for (; ctx; ctx = ctx->next)
153 mutt_group_add_adrlist (ctx->g, a);
154 }
155
594a6a4 Imported Upstream version 1.5.21
Antonio Radici authored
156 int mutt_group_context_remove_adrlist (group_context_t *ctx, ADDRESS * a)
157 {
158 int rv = 0;
159
160 for (; (!rv) && ctx; ctx = ctx->next)
161 {
162 rv = mutt_group_remove_adrlist (ctx->g, a);
163 if (empty_group (ctx->g))
164 mutt_group_remove (ctx->g);
165 }
166
167 return rv;
168 }
169
14c2920 Imported Upstream version 1.5.18
Antonio Radici authored
170 int mutt_group_context_add_rx (group_context_t *ctx, const char *s, int flags, BUFFER *err)
171 {
172 int rv = 0;
594a6a4 Imported Upstream version 1.5.21
Antonio Radici authored
173
14c2920 Imported Upstream version 1.5.18
Antonio Radici authored
174 for (; (!rv) && ctx; ctx = ctx->next)
175 rv = mutt_group_add_rx (ctx->g, s, flags, err);
176
177 return rv;
178 }
179
594a6a4 Imported Upstream version 1.5.21
Antonio Radici authored
180 int mutt_group_context_remove_rx (group_context_t *ctx, const char *s)
181 {
182 int rv = 0;
183
184 for (; (!rv) && ctx; ctx = ctx->next)
185 {
186 rv = mutt_group_remove_rx (ctx->g, s);
187 if (empty_group (ctx->g))
188 mutt_group_remove (ctx->g);
189 }
190
191 return rv;
192 }
193
14c2920 Imported Upstream version 1.5.18
Antonio Radici authored
194 int mutt_group_match (group_t *g, const char *s)
195 {
196 ADDRESS *ap;
594a6a4 Imported Upstream version 1.5.21
Antonio Radici authored
197
14c2920 Imported Upstream version 1.5.18
Antonio Radici authored
198 if (s && g)
199 {
200 if (mutt_match_rx_list (s, g->rs))
201 return 1;
202 for (ap = g->as; ap; ap = ap->next)
203 if (ap->mailbox && !mutt_strcasecmp (s, ap->mailbox))
204 return 1;
205 }
206 return 0;
207 }
208
Something went wrong with that request. Please try again.