From: Thomas Roessler Date: Wed, 12 Mar 2003 13:00:03 +0000 (+0000) Subject: We need to re-format address headers instead of just decoding them. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3d8ff1ae9191e0c4b2ccf0af5a3bec4f2bac42fa;p=neomutt We need to re-format address headers instead of just decoding them. --- diff --git a/copy.c b/copy.c index 389608edb..dfc4f2d6b 100644 --- a/copy.c +++ b/copy.c @@ -775,13 +775,75 @@ static int copy_delete_attach (BODY *b, FILE *fpin, FILE *fpout, char *date) return 0; } +/* + * This function is the equivalent of mutt_write_address_list(), + * but writes to a buffer instead of writing to a stream. + * mutt_write_address_list could be re-used if we wouldn't store + * all the decoded headers in a huge array, first. + * + * XXX - fix that. + */ + +static void format_address_header (char **h, ADDRESS *a) +{ + char buf[HUGE_STRING]; + char cbuf[STRING]; + char c2buf[STRING]; + + int l, linelen, buflen, count; + linelen = mutt_strlen (*h); + buflen = linelen + 3; + + + safe_realloc ((void **) h, buflen); + for (count = 0; a; a = a->next, count++) + { + ADDRESS *tmp = a->next; + a->next = NULL; + *buf = *cbuf = *c2buf = '\0'; + rfc822_write_address (buf, sizeof (buf), a, 0); + a->next = tmp; + + l = mutt_strlen (buf); + if (count && linelen + l > 74) + { + strcpy (cbuf, "\n\t"); /* __STRCPY_CHECKED__ */ + linelen = l + 8; + } + else + { + if (a->mailbox) + { + strcpy (cbuf, " "); /* __STRCPY_CHECKED__ */ + linelen++; + } + linelen += l; + } + if (!a->group && a->next && a->next->mailbox) + { + linelen++; + buflen++; + strcpy (c2buf, ","); /* __STRCPY_CHECKED__ */ + } + + buflen += l + mutt_strlen (cbuf) + mutt_strlen (c2buf); + safe_realloc ((void **) h, buflen); + strcat (*h, cbuf); /* __STRCAT_CHECKED__ */ + strcat (*h, buf); /* __STRCAT_CHECKED__ */ + strcat (*h, c2buf); /* __STRCAT_CHECKED__ */ + } + + /* Space for this was allocated in the beginning of this function. */ + strcat (*h, "\n"); /* __STRCAT_CHECKED__ */ +} + static int address_header_decode (char **h) { char *s = *h; - int l, ll; - + int l; + ADDRESS *a = NULL; - + switch (tolower (*s)) { case 'r': @@ -850,17 +912,13 @@ static int address_header_decode (char **h) mutt_addrlist_to_local (a); rfc2047_decode_adrlist (a); - ll = mutt_strlen (s) * 6 + 3; /* XXX -- should be safe */ - *h = safe_calloc (1, ll); + *h = safe_calloc (1, l + 2); - strncpy (*h, s, l); - strncat (*h, " ", ll); - rfc822_write_address (*h + l + 1, ll - l - 1, a, 0); - rfc822_free_address (&a); - - strncat (*h, "\n", ll); + strfcpy (*h, s, l + 1); - safe_realloc ((void **) h, mutt_strlen (*h) + 1); + format_address_header (h, a); + + rfc822_free_address (&a); FREE (&s); return 1; diff --git a/sendlib.c b/sendlib.c index 975a65fc9..acd1f1e88 100644 --- a/sendlib.c +++ b/sendlib.c @@ -1514,11 +1514,8 @@ void mutt_write_address_list (ADDRESS *adr, FILE *fp, int linelen, int display) len = mutt_strlen (buf); if (count && linelen + len > 74) { - if (count) - { - fputs ("\n\t", fp); - linelen = len + 8; /* tab is usually about 8 spaces... */ - } + fputs ("\n\t", fp); + linelen = len + 8; /* tab is usually about 8 spaces... */ } else {