diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2009-04-15 17:49:12 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2009-04-15 17:49:12 +0300 |
commit | d971eaba5417d3a06c332d1a6bf1929bb51f4d90 (patch) | |
tree | d2a95f66c434485732c2ea74c0ff2d83a0e5dcdd /mh/mh_whom.c | |
parent | b1594c2aaaaf49641fa93d568a41613c6d8de9aa (diff) | |
download | mailutils-d971eaba5417d3a06c332d1a6bf1929bb51f4d90.tar.gz mailutils-d971eaba5417d3a06c332d1a6bf1929bb51f4d90.tar.bz2 |
Improve RFC822 address parsing.
* examples/addr.c: Allow to modify hints via command line (-v)
and within the shell (\...).
* include/mailutils/address.h (MU_ADDR_HINT_*): New defines.
(struct _mu_address): Definition.
(mu_address_create_hint): New prototype.
* include/mailutils/parse822.h (mu_parse822_address_list)
(mu_parse822_mail_box, mu_parse822_group)
(mu_parse822_address, mu_parse822_route_addr)
(mu_parse822_route, mu_parse822_addr_spec)
(mu_parse822_unix_mbox, mu_parse822_local_part): Take hint and hint flags.
* mailbox/parse822.c: Likewise.
* libproto/include/Makefile.am (noinst_HEADERS): Remove address0.h
* libproto/include/address0.h: Removed.
* mailbox/address.c (mu_address_create_hint): New function.
(mu_address_create): Rewrite using mu_address_create_hint.
* mh/mh_init.c (mh_expand_aliases): Use mu_header_sget_field_name
* mh/mh_whom.c (mh_alias_expand): Rewrite using mu_address_create_hint.
This fixes parsing addresses similar to "a@b <a@b>".
* mh/send.c: New command line option --preserve (--keep)
Diffstat (limited to 'mh/mh_whom.c')
-rw-r--r-- | mh/mh_whom.c | 82 |
1 files changed, 30 insertions, 52 deletions
diff --git a/mh/mh_whom.c b/mh/mh_whom.c index 1fb3410ca..70371c73a 100644 --- a/mh/mh_whom.c +++ b/mh/mh_whom.c @@ -1,5 +1,5 @@ /* GNU Mailutils -- a suite of utilities for electronic mail - Copyright (C) 2003, 2005, 2006, 2007 Free Software Foundation, Inc. + Copyright (C) 2003, 2005, 2006, 2007, 2009 Free Software Foundation, Inc. GNU Mailutils is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -51,69 +51,47 @@ ismydomain (char *p) return strcasecmp (domain, p + 1) == 0; } +/* FIXME: incl is not used */ int mh_alias_expand (const char *str, mu_address_t *paddr, int *incl) { - int argc; - char **argv; - int i; - char *buf; - mu_address_t exaddr = NULL; - + size_t i, count; + mu_address_t addr; + int status; + if (incl) *incl = 0; - mu_argcv_get (str, ",", NULL, &argc, &argv); - for (i = 0; i < argc;) + status = mu_address_create_hint (&addr, str, NULL, 0); + if (status) { - if (i + 1 == argc) - { - if (mh_alias_get_address (argv[i], &exaddr, incl) == 0) - { - free (argv[i]); - memcpy (&argv[i], &argv[i+1], - (argc - i + 1) * sizeof (argv[0])); - argc--; - } - else - i++; - } - else if (argv[i + 1][0] == ',') + mu_error (_("Bad address `%s': %s"), str, mu_strerror (status)); + return 1; + } + + mu_address_get_count (addr, &count); + for (i = 1; i <= count; i++) + { + mu_address_t subaddr = NULL; + const char *key; + + if (mu_address_sget_domain (addr, i, &key) == 0 && key == NULL) { - if (mh_alias_get_address (argv[i], &exaddr, incl) == 0) - { - free (argv[i]); - free (argv[i+1]); - memcpy (&argv[i], &argv[i+2], - (argc - i) * sizeof (argv[0])); - argc -= 2; - } - else - i += 2; + if (mu_address_sget_local_part (addr, i, &key) == 0 + && mh_alias_get_address (key, paddr, incl) == 0) + continue; } - else + + status = mu_address_get_nth (addr, i, &subaddr); + if (status) { - for (; i < argc; i++) - if (argv[i][0] == ',') - { - i++; - break; - } + mu_error (_("%s: cannot get address #%lu: %s"), + str, (unsigned long) i, mu_strerror (status)); + continue; } - } - if (argc) - { - int status; - mu_argcv_string (argc, argv, &buf); - if ((status = mu_address_create (paddr, buf))) - mu_error (_("Bad address `%s': %s"), buf, mu_strerror (status)); - free (buf); + mu_address_union (paddr, subaddr); + mu_address_destroy (&subaddr); } - - mu_argcv_free (argc, argv); - - mu_address_union (paddr, exaddr); - mu_address_destroy (&exaddr); return 0; } |