commit-mailutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[SCM] GNU Mailutils branch, master, updated. release-2.2-543-g690b1bf


From: Sergey Poznyakoff
Subject: [SCM] GNU Mailutils branch, master, updated. release-2.2-543-g690b1bf
Date: Wed, 21 Dec 2011 22:14:12 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU Mailutils".

http://git.savannah.gnu.org/cgit/mailutils.git/commit/?id=690b1bf8506e50cb85d2634ba2db2fddbff99dfe

The branch, master has been updated
       via  690b1bf8506e50cb85d2634ba2db2fddbff99dfe (commit)
       via  924bc7276b9626615d7030fa565d0876bbfd9409 (commit)
      from  7919e2d260bd7971d75126d544b352b749c3fa74 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 690b1bf8506e50cb85d2634ba2db2fddbff99dfe
Author: Sergey Poznyakoff <address@hidden>
Date:   Wed Dec 21 17:40:17 2011 +0200

    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.

commit 924bc7276b9626615d7030fa565d0876bbfd9409
Author: Sergey Poznyakoff <address@hidden>
Date:   Wed Dec 21 17:35:45 2011 +0200

    imap4d: Fix fetch in case of message/rfc822
    
    This case requires full recursion.
    
    * imap4d/fetch.c (bodystructure): Call fetch_bodystructure0.

-----------------------------------------------------------------------

Summary of changes:
 examples/addr.c                                    |    4 +-
 examples/mta.c                                     |   17 +--
 imap4d/fetch.c                                     |    4 +-
 include/mailutils/address.h                        |   33 +++-
 libmailutils/address/Makefile.am                   |    1 +
 libmailutils/address/address.c                     |  209 +++++++++++---------
 .../mu_scm.h => libmailutils/address/addrstream.c  |   70 ++++---
 libmailutils/address/parse822.c                    |    6 +-
 libmailutils/base/assoc.c                          |    4 +-
 libmailutils/mime/mimehdr.c                        |    2 +-
 mail/util.c                                        |   23 +--
 mh/mh.h                                            |    3 +-
 mh/mh_format.c                                     |    9 +-
 mh/mh_init.c                                       |    2 +-
 mh/mh_whatnow.c                                    |   12 +-
 mh/send.c                                          |    9 +-
 mu/imap.c                                          |    7 +-
 python/libmu_py/address.c                          |    9 +-
 18 files changed, 224 insertions(+), 200 deletions(-)
 copy libmu_scm/mu_scm.h => libmailutils/address/addrstream.c (51%)

diff --git a/examples/addr.c b/examples/addr.c
index 9373f64..2928eac 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 c9572b9..4008f78 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;
 }
diff --git a/imap4d/fetch.c b/imap4d/fetch.c
index d1698b6..fed2e3f 100644
--- a/imap4d/fetch.c
+++ b/imap4d/fetch.c
@@ -312,6 +312,8 @@ fetch_envelope0 (mu_message_t msg)
   return RESP_OK;
 }
 
+static int fetch_bodystructure0 (mu_message_t message, int extension);
+
 /* The basic fields of a non-multipart body part are in the following order:
    body type:
    A string giving the content media type name as defined in [MIME-IMB].
@@ -490,7 +492,7 @@ bodystructure (mu_message_t msg, int extension)
       io_sendf (")");
       /* Add body structure of the encapsulated message.  */
       io_sendf ("(");
-      bodystructure (emsg, extension);
+      fetch_bodystructure0 (emsg, extension);
       io_sendf (")");
       /* Size in text lines of the encapsulated message.  */
       mu_message_lines (emsg, &lines);
diff --git a/include/mailutils/address.h b/include/mailutils/address.h
index 96640be..45742ef 100644
--- a/include/mailutils/address.h
+++ b/include/mailutils/address.h
@@ -25,7 +25,7 @@
 extern "C" {
 #endif
 
-#define MU_ADDR_HINT_ADDR       0x0001 /* Not used yet */
+#define MU_ADDR_HINT_PRINTABLE  0x0001 /* Not used yet */
 #define MU_ADDR_HINT_COMMENTS   0x0002
 #define MU_ADDR_HINT_PERSONAL   0x0004
 #define MU_ADDR_HINT_EMAIL      0x0008
@@ -42,9 +42,11 @@ extern "C" {
  */
 struct mu_address
 {
-  char *addr;
-       /* the original string that this list of addresses was created
-        * from, only present at the head of the list */
+  char *printable;
+       /* Printable representation of this address.  Normally, it is
+        * the original string that this list of addresses was created
+        * from, only present at the head of the list
+        */
 
   char *comments;
        /* the collection of comments stripped during parsing this MAILBOX */
@@ -129,8 +131,12 @@ extern int mu_address_aget_route
 
 extern int mu_address_is_group
        (mu_address_t, size_t, int*);
-
-extern int mu_address_to_string (mu_address_t, char *, size_t, size_t *);
+  
+extern int mu_address_sget_printable (mu_address_t addr, const char **sptr);
+extern int mu_address_aget_printable (mu_address_t addr, char **presult);
+extern int mu_address_get_printable (mu_address_t addr, char *buf, size_t len,
+                                    size_t *n);
+  
 extern int mu_address_get_count (mu_address_t, size_t *);
 extern int mu_address_get_group_count (mu_address_t, size_t *);
 extern int mu_address_get_email_count (mu_address_t, size_t *);
@@ -139,8 +145,21 @@ extern int mu_address_get_unix_mailbox_count 
(mu_address_t, size_t *);
 extern int mu_address_contains_email (mu_address_t addr, const char *email);
 extern int mu_address_union (mu_address_t *a, mu_address_t b);
   
-extern size_t mu_address_format_string (mu_address_t addr, char *buf, size_t 
buflen);
+extern int mu_stream_format_address (mu_stream_t str, mu_address_t addr);
+
+  /* Deprecated calls */
+  
+extern int mu_address_to_string (mu_address_t, char *, size_t, size_t *)
+  MU_DEPRECATED; /* Use mu_address_get_printable, if you really have to */
+  
+extern size_t mu_address_format_string (mu_address_t addr, char *buf,
+                                       size_t buflen)
+  MU_DEPRECATED; /* Use mu_stream_format_address, or any of the
+                   _get_printable functions */
 
+extern int mu_validate_email (mu_address_t subaddr);
+
+  
 #ifdef __cplusplus
 }
 #endif
diff --git a/libmailutils/address/Makefile.am b/libmailutils/address/Makefile.am
index bafd881..6890875 100644
--- a/libmailutils/address/Makefile.am
+++ b/libmailutils/address/Makefile.am
@@ -19,6 +19,7 @@ noinst_LTLIBRARIES = libaddress.la
 
 libaddress_la_SOURCES = \
  address.c\
+ addrstream.c\
  parse822.c
 
 INCLUDES = @MU_LIB_COMMON_INCLUDES@ -I/libmailutils
diff --git a/libmailutils/address/address.c b/libmailutils/address/address.c
index 80ddb14..19c33fa 100644
--- a/libmailutils/address/address.c
+++ b/libmailutils/address/address.c
@@ -35,6 +35,7 @@
 #include <mailutils/parse822.h>
 #include <mailutils/address.h>
 #include <mailutils/cstr.h>
+#include <mailutils/stream.h>
 
 int
 mu_address_create_null (mu_address_t *pa)
@@ -70,8 +71,8 @@ mu_address_create_hint (mu_address_t *a, const char *s, 
mu_address_t hint,
       if (!*a)
        return MU_ERR_EMPTY_ADDRESS;
 
-      (*a)->addr = strdup (s);
-      if (!(*a)->addr)
+      (*a)->printable = strdup (s);
+      if (!(*a)->printable)
        {
          mu_address_destroy (a);
          return ENOMEM;
@@ -159,8 +160,8 @@ mu_address_destroy (mu_address_t *paddress)
       mu_address_t current;
       for (; address; address = current)
        {
-         if (address->addr)
-           free (address->addr);
+         if (address->printable)
+           free (address->printable);
          if (address->comments)
            free (address->comments);
          if (address->personal)
@@ -195,19 +196,19 @@ mu_address_concatenate (mu_address_t to, mu_address_t 
*from)
   *from = NULL;
 
   /* discard the current string cache as it is now inaccurate */
-  if (to->addr)
+  if (to->printable)
     {
-      free (to->addr);
-      to->addr = NULL;
+      free (to->printable);
+      to->printable = NULL;
     }
 
   to = to->next;
 
   /* only the first address must have a cache */
-  if (to->addr)
+  if (to->printable)
     {
-      free (to->addr);
-      to->addr = NULL;
+      free (to->printable);
+      to->printable = NULL;
     }
 
   return 0;
@@ -432,8 +433,8 @@ mu_address_set_email (mu_address_t addr, size_t no, const 
char *buf)
   return 0;
 }
 
-static int
-validate_email (mu_address_t subaddr)
+int
+mu_validate_email (mu_address_t subaddr)
 {
   if (!subaddr->email)
     {
@@ -473,82 +474,45 @@ mu_address_sget_email (mu_address_t addr, size_t no, char 
const **sptr)
   if (!subaddr)
     return MU_ERR_NOENT;
 
-  validate_email (subaddr);
+  mu_validate_email (subaddr);
   *sptr = subaddr->email;
   return 0;
 }
 
 DECL_GET(email)
 DECL_AGET(email)
-
-
-
 
-#define format_char(c) do {\
- if (buflen) \
-   {\
-      *buf++ = c;\
-      buflen--;\
-   }\
- else\
-   rc++;\
-} while(0)
-
-#define format_string(str) do {\
- if (buflen) \
-   {\
-      int n = snprintf (buf, buflen, "%s", str);\
-      buf += n;\
-      buflen -= n;\
-   }\
- else\
-   rc += strlen (str);\
-} while (0)
-
 size_t
 mu_address_format_string (mu_address_t addr, char *buf, size_t buflen)
 {
-  int rc = 0;
-  int comma = 0;
-
-  for (;addr; addr = addr->next)
+  mu_stream_t str;
+  int rc;
+  
+  if (!buf)
+    rc = mu_nullstream_create (&str, MU_STREAM_WRITE);
+  else
+    rc = mu_fixed_memory_stream_create (&str, buf, buflen, MU_STREAM_WRITE);
+  if (rc == 0)
     {
-      validate_email (addr);
-      if (addr->email)
+      size_t size;
+      
+      mu_stream_stat_buffer statbuf;
+      mu_stream_set_stat (str, MU_STREAM_STAT_MASK (MU_STREAM_STAT_OUT),
+                         statbuf);
+      rc = mu_stream_format_address (str, addr);
+      mu_stream_destroy (&str);
+      if (rc)
+       return 0;
+      size = statbuf[MU_STREAM_STAT_OUT];
+      if (buf)
        {
-         int space = 0;
-
-         if (comma)
-           format_char (',');
-
-         if (addr->personal)
-           {
-             format_char ('"');
-             format_string (addr->personal);
-             format_char ('"');
-             space++;
-           }
-
-         if (addr->comments)
-           {
-             if (space)
-               format_char (' ');
-             format_char ('(');
-             format_string (addr->comments);
-             format_char (')');
-             space++;
-           }
-
-         if (space)
-           format_char (' ');
-         format_char ('<');
-         format_string (addr->email);
-         format_char ('>');
-         comma++;
+         if (size + 1 >= buflen)
+           size = buflen - 1;
+         buf[size] = 0;
        }
+      return size;
     }
-  format_char (0);
-  return rc;
+  return 0;
 }
 
 static int
@@ -593,27 +557,86 @@ mu_address_is_group (mu_address_t addr, size_t no, int 
*yes)
 }
 
 int
-mu_address_to_string (mu_address_t addr, char *buf, size_t len, size_t *n)
+mu_address_sget_printable (mu_address_t addr, const char **sptr)
 {
-  size_t i;
   if (addr == NULL)
     return EINVAL;
-  if (buf)
-    *buf = '\0';
+  if (!sptr)
+    return MU_ERR_OUT_PTR_NULL;
+  if (!addr->printable)
+    {
+      mu_stream_t str;
+      int rc;
+      
+      rc = mu_memory_stream_create (&str, MU_STREAM_RDWR);
+      if (rc)
+       return rc;
+      rc = mu_stream_format_address (str, addr);
+      if (rc == 0)
+       {
+         mu_off_t size;
+         mu_stream_size (str, &size);
+         addr->printable = malloc (size + 1);
+         if (!addr->printable)
+           rc = ENOMEM;
+         else
+           {
+             mu_stream_seek (str, 0, MU_SEEK_SET, NULL);
+             rc = mu_stream_read (str, addr->printable, size, NULL);
+             addr->printable[size] = 0;
+           }
+       }
+      mu_stream_destroy (&str);
+      if (rc)
+       return rc;
+    }
+  *sptr = addr->printable;
+  return 0;
+}
 
-  if (!addr->addr)
+int
+mu_address_aget_printable (mu_address_t addr, char **presult)
+{
+  int rc;
+  const char *s;
+
+  if (addr == NULL)
+    return EINVAL;
+  if (!presult)
+    return MU_ERR_OUT_PTR_NULL;
+  rc = mu_address_sget_printable (addr, &s);
+  if (rc == 0)
     {
-      i = mu_address_format_string (addr, NULL, 0);
-      addr->addr = malloc (i + 1);
-      if (!addr->addr)
-       return ENOMEM;
-      mu_address_format_string (addr, addr->addr, i+1);
+      char *result = strdup (s);
+      if (result)
+       *presult = result;
+      else
+       rc = ENOMEM;
     }
+  return rc;
+}
 
-  i = mu_cpystr (buf, addr->addr, len);
-  if (n)
-    *n = i;
-  return 0;
+int
+mu_address_get_printable (mu_address_t addr, char *buf, size_t len, size_t *n)
+{
+  const char *s;
+  int rc;
+  
+  rc = mu_address_sget_printable (addr, &s);
+  if (rc == 0)
+    {
+      size_t i;
+      i = mu_cpystr (buf, addr->printable, len);
+      if (n)
+       *n = i;
+    }
+  return rc;
+}
+
+int
+mu_address_to_string (mu_address_t addr, char *buf, size_t len, size_t *n)
+{
+  return mu_address_get_printable (addr, buf, len, n);
 }
 
 int
@@ -687,8 +710,8 @@ mu_address_dup (mu_address_t src)
     return NULL;
 
   /* FIXME: How about:
-    if (src->addr)
-      dst->addr = strdup (src->addr);
+    if (src->printable)
+      dst->printable = strdup (src->printable);
     ?
   */
   if (src->comments)
@@ -725,10 +748,10 @@ mu_address_union (mu_address_t *a, mu_address_t b)
     }
   else
     {
-      if ((*a)->addr)
+      if ((*a)->printable)
        {
-         free ((*a)->addr);
-         (*a)->addr = NULL;
+         free ((*a)->printable);
+         (*a)->printable = NULL;
        }
       for (last = *a; last->next; last = last->next)
        ;
diff --git a/libmu_scm/mu_scm.h b/libmailutils/address/addrstream.c
similarity index 51%
copy from libmu_scm/mu_scm.h
copy to libmailutils/address/addrstream.c
index de946c4..44fe7c8 100644
--- a/libmu_scm/mu_scm.h
+++ b/libmailutils/address/addrstream.c
@@ -1,5 +1,5 @@
 /* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 1999, 2000, 2001, 2002, 2006, 2007, 2009, 2010, 2011
+   Copyright (C) 1999, 2000, 2001, 2005, 2006, 2007, 2009, 2010, 2011
    Free Software Foundation, Inc.
 
    This library is free software; you can redistribute it and/or
@@ -16,39 +16,47 @@
    Public License along with this library.  If not, see
    <http://www.gnu.org/licenses/>. */
 
-#if defined(HAVE_CONFIG_H)
+#ifdef HAVE_CONFIG_H
 # include <config.h>
 #endif
-
 #include <stdlib.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <errno.h>
-#include <sys/time.h>
-#include <string.h>
-#include <confpaths.h>
-
-#include <mailutils/mailbox.h>
-#include <mailutils/message.h>
-#include <mailutils/header.h>
-#include <mailutils/body.h>
-#include <mailutils/registrar.h>
-#include <mailutils/error.h>
-#include <mailutils/errno.h>
 #include <mailutils/address.h>
-#include <mailutils/registrar.h>
-#include <mailutils/util.h>
-#include <mailutils/datetime.h>
 #include <mailutils/stream.h>
-#include <mailutils/debug.h>
-#include <mailutils/attribute.h>
-#include <mailutils/mailer.h>
-#include <mailutils/envelope.h>
-#include <mailutils/url.h>
-#include <mailutils/mime.h>
-#include <mailutils/registrar.h>
-#include <mailutils/mu_auth.h>
-#include <mailutils/cstr.h>
-
-#include <mailutils/guile.h>
 
+int
+mu_stream_format_address (mu_stream_t str, mu_address_t addr)
+{
+  int comma = 0;
+
+  for (;addr; addr = addr->next)
+    {
+      mu_validate_email (addr);
+      if (addr->email)
+       {
+         int space = 0;
+
+         if (comma)
+           mu_stream_write (str, ",", 1, NULL);
+
+         if (addr->personal)
+           {
+             mu_stream_printf (str, "\"%s\"", addr->personal);
+             space++;
+           }
+
+         if (addr->comments)
+           {
+             if (space)
+               mu_stream_write (str, " ", 1, NULL);
+             mu_stream_printf (str, "(%s)", addr->comments);
+             space++;
+           }
+
+         if (space)
+           mu_stream_write (str, " ", 1, NULL);
+         mu_stream_printf (str, "<%s>", addr->email);
+         comma++;
+       }
+    }
+  return mu_stream_err (str) ? mu_stream_last_error (str) : 0;
+}
diff --git a/libmailutils/address/parse822.c b/libmailutils/address/parse822.c
index 526afd1..bea2615 100644
--- a/libmailutils/address/parse822.c
+++ b/libmailutils/address/parse822.c
@@ -713,8 +713,8 @@ addr_field_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;                                   
@@ -758,7 +758,7 @@ addr_free_fields (mu_address_t a, int memflag)
 {
   char *p;
   
-  if ((p = addr_field_by_mask (a, memflag & MU_ADDR_HINT_ADDR)))
+  if ((p = addr_field_by_mask (a, memflag & MU_ADDR_HINT_PRINTABLE)))
     free (p);
   if ((p = addr_field_by_mask (a, memflag & MU_ADDR_HINT_COMMENTS)))
     free (p);
diff --git a/libmailutils/base/assoc.c b/libmailutils/base/assoc.c
index 2d21fa8..519bb2d 100644
--- a/libmailutils/base/assoc.c
+++ b/libmailutils/base/assoc.c
@@ -172,8 +172,8 @@ assoc_remove (mu_assoc_t assoc, struct _mu_assoc_elem *elem)
       while ((j < r && r <= i) || (i < j && j < r) || (r <= i && i < j));
 
       if (j != i)
-             memcpy (ASSOC_ELEM (assoc, j), ASSOC_ELEM (assoc, i),
-                     assoc->elsize);
+       memcpy (ASSOC_ELEM (assoc, j), ASSOC_ELEM (assoc, i),
+               assoc->elsize);
     }
   return 0;
 }
diff --git a/libmailutils/mime/mimehdr.c b/libmailutils/mime/mimehdr.c
index 94389b1..96dd109 100644
--- a/libmailutils/mime/mimehdr.c
+++ b/libmailutils/mime/mimehdr.c
@@ -287,7 +287,7 @@ static int
 _mime_header_parse (const char *text, char **pvalue,
                    mu_assoc_t assoc, const char *outcharset, int subset)
 {
-  int rc;
+  int rc = 0;
   struct mu_wordsplit ws;
   struct param_continuation cont;
   size_t i;
diff --git a/mail/util.c b/mail/util.c
index 747723c..fb1cf12 100644
--- a/mail/util.c
+++ b/mail/util.c
@@ -861,17 +861,13 @@ util_merge_addresses (char **addr_str, const char *value)
   rc = mu_address_union (&addr, new_addr);
   if (rc == 0)
     {
-      size_t n;
-
-      rc = mu_address_to_string (addr, NULL, 0, &n);
+      char *val;
+      
+      rc = mu_address_aget_printable (addr, &val);
       if (rc == 0)
        {
          free (*addr_str);
-         *addr_str = malloc (n + 1);
-         if (!*addr_str)
-           rc = ENOMEM;
-         else
-           mu_address_to_string (addr, *addr_str, n + 1, &n);
+         *addr_str = val;
        }
     }
 
@@ -972,15 +968,12 @@ util_header_expand (mu_header_t *phdr)
          
          if (addr)
            {
-             char *newvalue;
-             size_t n = 0;
+             const char *newvalue;
              
-             mu_address_to_string (addr, NULL, 0, &n);
-             newvalue = xmalloc (n + 1);
-             mu_address_to_string (addr, newvalue, n + 1, NULL);
+             rc = mu_address_sget_printable (addr, &newvalue);
+             if (rc == 0)
+               mu_header_set_value (hdr, name, newvalue, 1);
              mu_address_destroy (&addr);
-             mu_header_set_value (hdr, name, newvalue, 1);
-             free (newvalue);
            }
        }
       else
diff --git a/mh/mh.h b/mh/mh.h
index 0d883b9..2e0f812 100644
--- a/mh/mh.h
+++ b/mh/mh.h
@@ -358,7 +358,8 @@ typedef int (*mh_alias_enumerator_t) (char *alias, 
mu_list_t names, void *data);
 void mh_alias_enumerate (mh_alias_enumerator_t fun, void *data);
 
 
-void mh_annotate (mu_message_t msg, char *field, char *text, int date);
+void mh_annotate (mu_message_t msg, const char *field, const char *text,
+                 int date);
 
 #define MHL_DECODE       1
 #define MHL_CLEARSCREEN  2
diff --git a/mh/mh_format.c b/mh/mh_format.c
index 78bc3ed..1c5c77d 100644
--- a/mh/mh_format.c
+++ b/mh/mh_format.c
@@ -1801,7 +1801,6 @@ static void
 builtin_formataddr (struct mh_machine *mach)
 {
   mu_address_t addr, dest;
-  size_t size;
   int i;
   size_t num;
   const char *buf;
@@ -1837,12 +1836,12 @@ builtin_formataddr (struct mh_machine *mach)
        }
     }
 
-  if (mu_address_to_string (dest, NULL, 0, &size) == 0)
+  if (mu_address_sget_printable (dest, &buf) == 0)
     {
-      strobj_realloc (&mach->reg_str, size + 1);
-      mu_address_to_string (dest, strobj_ptr (&mach->reg_str), size + 1, NULL);
-      mu_address_destroy (&dest);
+      strobj_realloc (&mach->reg_str, strlen (buf) + 1);
+      strcpy (strobj_ptr (&mach->reg_str), buf);
     }
+  mu_address_destroy (&dest);
 }
 
 /*      putaddr    literal        print str address list with
diff --git a/mh/mh_init.c b/mh/mh_init.c
index 75976f2..fc1934a 100644
--- a/mh/mh_init.c
+++ b/mh/mh_init.c
@@ -852,7 +852,7 @@ mh_install (char *name, int automode)
 }
         
 void
-mh_annotate (mu_message_t msg, char *field, char *text, int date)
+mh_annotate (mu_message_t msg, const char *field, const char *text, int date)
 {
   mu_header_t hdr;
   mu_attribute_t attr;
diff --git a/mh/mh_whatnow.c b/mh/mh_whatnow.c
index 4b4b210..08b66fc 100644
--- a/mh/mh_whatnow.c
+++ b/mh/mh_whatnow.c
@@ -264,8 +264,8 @@ invoke (const char *compname, const char *defval, int argc, 
char **argv,
 
 struct anno_data
 {
-  char *field;
-  char *value;
+  const char *field;
+  const char *value;
   int date;
 };
 
@@ -299,16 +299,12 @@ annotate (struct mh_whatnow_env *wh)
 
       if (mu_address_get_nth (addr, i, &subaddr) == 0)
        {
-         size_t size;
          struct anno_data d;
 
-         mu_address_to_string (subaddr, NULL, 0, &size);
-         d.value = xmalloc (size + 1);
          d.field = wh->anno_field;
          d.date = i == 1;
-         mu_address_to_string (subaddr, d.value, size + 1, NULL);
-         mu_list_foreach (wh->anno_list, anno, &d);
-         free (d.value);
+         if (mu_address_sget_printable (subaddr, &d.value) == 0)
+           mu_list_foreach (wh->anno_list, anno, &d);
          mu_address_destroy (&subaddr);
        }
     }
diff --git a/mh/send.c b/mh/send.c
index 1f433b9..479e9cc 100644
--- a/mh/send.c
+++ b/mh/send.c
@@ -475,11 +475,10 @@ get_sender_personal ()
 static void
 set_address_header (mu_header_t hdr, char *name, mu_address_t addr)
 {
-  size_t s = mu_address_format_string (addr, NULL, 0);
-  char *value = xmalloc (s + 1);
-  mu_address_format_string (addr, value, s);
-  mu_header_set_value (hdr, name, value, 1);
-  free (value);
+  const char *value;
+  if (mu_address_sget_printable (addr, &value) == 0)
+    mu_header_set_value (hdr, name, value, 1);
+  /* FIXME: Error reporting */
 }
 
 void
diff --git a/mu/imap.c b/mu/imap.c
index 85b0f60..cf49b4b 100644
--- a/mu/imap.c
+++ b/mu/imap.c
@@ -196,12 +196,7 @@ format_email (mu_stream_t str, const char *name, 
mu_address_t addr)
   if (!addr)
     mu_stream_printf (str, "NIL");
   else
-    {
-      size_t sz = mu_address_format_string (addr, NULL, 0);
-      char *buf = xmalloc (sz + 1);
-      mu_address_format_string (addr, buf, sz);
-      mu_stream_write (str, buf, strlen (buf), NULL);
-    }
+    mu_stream_format_address (str, addr);
   mu_stream_printf (str, "\n");
 }
 
diff --git a/python/libmu_py/address.c b/python/libmu_py/address.c
index 2d3d7d6..b943838 100644
--- a/python/libmu_py/address.c
+++ b/python/libmu_py/address.c
@@ -267,17 +267,14 @@ static PyObject *
 api_address_to_string (PyObject *self, PyObject *args)
 {
   int status;
-  size_t n;
-  char buf[256];
+  char const *sptr;
   PyAddress *py_addr;
 
-  memset (buf, 0, sizeof (buf));
-
   if (!PyArg_ParseTuple (args, "O!", &PyAddressType, &py_addr))
     return NULL;
 
-  status = mu_address_to_string (py_addr->addr, buf, sizeof (buf), &n);
-  return status_object (status, PyString_FromString (buf));
+  status = mu_address_sget_printable (py_addr->addr, &sptr);
+  return status_object (status, PyString_FromString (sptr));
 }
 
 static PyMethodDef methods[] = {


hooks/post-receive
-- 
GNU Mailutils



reply via email to

[Prev in Thread] Current Thread [Next in Thread]