diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2011-12-21 17:40:17 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2011-12-21 17:40:17 +0200 |
commit | 690b1bf8506e50cb85d2634ba2db2fddbff99dfe (patch) | |
tree | 8a8892d675060991fc4103d83462a188c5fc511c /examples | |
parent | 924bc7276b9626615d7030fa565d0876bbfd9409 (diff) | |
download | mailutils-690b1bf8506e50cb85d2634ba2db2fddbff99dfe.tar.gz mailutils-690b1bf8506e50cb85d2634ba2db2fddbff99dfe.tar.bz2 |
Fix API for obtaining full email address.
Old API relied on passing a pointer to the buffer string and its size,
which is defective. The new API, in addtion to that, provides functions
for obtaining a pointer to the statically allocated original value, a
pointer to dynamically allocated copy, and a function for formatting the
address directly to a MU stream.
Two functions are marked as deprecated: mu_address_to_string and
mu_address_format_string. Both assume a pointer to an allocated string
of a fixed size, which is far from being convenient nor reliable enough.
* include/mailutils/address.h (MU_ADDR_HINT_ADDR): Rename to
MU_ADDR_HINT_PRINTABLE
(mu_address)<addr>: Rename to printable.
(mu_address_sget_printable,mu_address_aget_printable)
(mu_address_get_printable): New protos.
(mu_stream_format_address): New proto.
(mu_address_to_string)
(mu_address_format_string): Mark as deprecated.
(mu_validate_email): New proto.
* examples/mta.c: Use mu_address_sget_printable instead
of (mu_address_to_string)
* libmailutils/address/addrstream.c: New file.
* libmailutils/address/Makefile.am (libaddress_la_SOURCES): Add
addrstream.c
* libmailutils/address/address.c (mu_address_format_string): Rewrite using
streams.
(mu_address_to_string): Rewrite as a wrapper over
mu_address_get_printable.
(mu_address_sget_printable,mu_address_aget_printable)
(mu_address_get_printable): New functions.
* libmailutils/mime/mimehdr.c (_mime_header_parse): Initialize rc.
* mail/util.c (util_merge_addresses): Use mu_address_aget_printable.
* mh/mh.h (mh_annotate): Both string args are const.
* mh/mh_init.c (mh_annotate): Likewise.
* mh/mh_format.c (builtin_formataddr): Use mu_address_sget_printable.
* mh/mh_whatnow.c (anno_data)<field,value>: Both are consts.
(annotate): Use mu_address_sget_printable.
* mh/send.c (set_address_header): Use mu_address_sget_printable.
* mu/imap.c (format_email): Use mu_stream_format_address.
* python/libmu_py/address.c (api_address_to_string): Likewise.
Diffstat (limited to 'examples')
-rw-r--r-- | examples/addr.c | 4 | ||||
-rw-r--r-- | examples/mta.c | 17 |
2 files changed, 6 insertions, 15 deletions
diff --git a/examples/addr.c b/examples/addr.c index 9373f6494..2928eac87 100644 --- a/examples/addr.c +++ b/examples/addr.c @@ -112,8 +112,8 @@ addr_fieldptr_by_mask (mu_address_t addr, int mask) { switch (mask) { - case MU_ADDR_HINT_ADDR: - return &addr->addr; + case MU_ADDR_HINT_PRINTABLE: + return &addr->printable; case MU_ADDR_HINT_COMMENTS: return &addr->comments; diff --git a/examples/mta.c b/examples/mta.c index c9572b969..4008f78ac 100644 --- a/examples/mta.c +++ b/examples/mta.c @@ -437,26 +437,17 @@ message_finalize (mu_message_t msg, int warn) if (finalize_option && !have_to) { - size_t n; + char const *sptr; int c; - c = mu_address_to_string (recipients, NULL, 0, &n); + c = mu_address_sget_printable (recipients, &sptr); if (c) { - mu_error ("%s: mu_address_to_string failure: %s", + mu_error ("%s: mu_address_sget_printable failure: %s", progname, mu_strerror (c)); return 1; } - value = malloc (n + 1); - if (!value) - { - mu_error ("%s: not enough memory", progname); - return 1; - } - - mu_address_to_string (recipients, value, n + 1, &n); - mu_header_set_value (header, MU_HEADER_TO, value, 1); - free (value); + mu_header_set_value (header, MU_HEADER_TO, sptr, 1); } return 0; } |