(alias_expand): Recursively expand aliases if recursealiases is set.
Showing
1 changed file
with
65 additions
and
1 deletions
1 | /* GNU Mailutils -- a suite of utilities for electronic mail | 1 | /* GNU Mailutils -- a suite of utilities for electronic mail |
2 | Copyright (C) 1999, 2001, 2002, 2005 Free Software Foundation, Inc. | 2 | Copyright (C) 1999, 2001, 2002, 2005, 2006 Free Software Foundation, Inc. |
3 | 3 | ||
4 | GNU Mailutils is free software; you can redistribute it and/or modify | 4 | GNU Mailutils is free software; you can redistribute it and/or modify |
5 | it under the terms of the GNU General Public License as published by | 5 | it under the terms of the GNU General Public License as published by |
... | @@ -258,11 +258,75 @@ alias_destroy (char *name) | ... | @@ -258,11 +258,75 @@ alias_destroy (char *name) |
258 | } | 258 | } |
259 | } | 259 | } |
260 | 260 | ||
261 | static void | ||
262 | recursive_alias_expand (char *name, mu_list_t exlist, mu_list_t origlist) | ||
263 | { | ||
264 | mu_list_t alist; | ||
265 | mu_iterator_t itr; | ||
266 | |||
267 | if (!alias_lookup (name, &alist)) | ||
268 | { | ||
269 | if (mu_list_locate (exlist, name, NULL) == MU_ERR_NOENT) | ||
270 | mu_list_append (exlist, name); | ||
271 | return; | ||
272 | } | ||
273 | |||
274 | mu_list_get_iterator (alist, &itr); | ||
275 | for (mu_iterator_first (itr); | ||
276 | !mu_iterator_is_done (itr); | ||
277 | mu_iterator_next (itr)) | ||
278 | { | ||
279 | char *word; | ||
280 | |||
281 | mu_iterator_current (itr, (void **)&word); | ||
282 | if (mu_list_locate (origlist, word, NULL) == MU_ERR_NOENT) | ||
283 | { | ||
284 | mu_list_prepend (origlist, word); | ||
285 | recursive_alias_expand (word, exlist, origlist); | ||
286 | mu_list_remove (origlist, word); | ||
287 | } | ||
288 | } | ||
289 | mu_iterator_destroy (&itr); | ||
290 | } | ||
291 | |||
292 | static int | ||
293 | string_comp (const void *item, const void *value) | ||
294 | { | ||
295 | return strcmp (item, value); | ||
296 | } | ||
297 | |||
261 | char * | 298 | char * |
262 | alias_expand (char *name) | 299 | alias_expand (char *name) |
263 | { | 300 | { |
264 | mu_list_t list; | 301 | mu_list_t list; |
265 | 302 | ||
303 | if (util_getenv (NULL, "recursivealiases", Mail_env_boolean, 0) == 0) | ||
304 | { | ||
305 | char *s; | ||
306 | mu_list_t origlist; | ||
307 | |||
308 | int status = mu_list_create (&list); | ||
309 | if (status) | ||
310 | { | ||
311 | mu_error (_("Cannot create list: %s"), mu_strerror (status)); | ||
312 | return NULL; | ||
313 | } | ||
314 | status = mu_list_create (&origlist); | ||
315 | if (status) | ||
316 | { | ||
317 | mu_list_destroy (&origlist); | ||
318 | mu_error (_("Cannot create list: %s"), mu_strerror (status)); | ||
319 | return NULL; | ||
320 | } | ||
321 | mu_list_set_comparator (list, string_comp); | ||
322 | mu_list_set_comparator (origlist, string_comp); | ||
323 | recursive_alias_expand (name, list, origlist); | ||
324 | s = util_slist_to_string (list, ","); | ||
325 | mu_list_destroy (&origlist); | ||
326 | mu_list_destroy (&list); | ||
327 | return s; | ||
328 | } | ||
329 | |||
266 | if (!alias_lookup (name, &list)) | 330 | if (!alias_lookup (name, &list)) |
267 | return NULL; | 331 | return NULL; |
268 | return util_slist_to_string (list, ","); | 332 | return util_slist_to_string (list, ","); | ... | ... |
-
Please register or sign in to post a comment