From: Pierre Habouzit Date: Sun, 26 Nov 2006 17:40:06 +0000 (+0100) Subject: simplify mutt_write_references. X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=commitdiff_plain;h=20a3dd763b0692acb4fa0938af35db0da0cd5508 simplify mutt_write_references. wibble --- diff --git a/sendlib.c b/sendlib.c index cfb71cf..4fa7f73 100644 --- a/sendlib.c +++ b/sendlib.c @@ -1308,31 +1308,22 @@ void mutt_write_address_list (address_t * adr, FILE * fp, int linelen, fputc ('\n', fp); } -/* arbitrary number of elements to grow the array by */ -#define REF_INC 16 - -#define TrimRef 10 - /* need to write the list in reverse because they are stored in reverse order * when parsed to speed up threading */ -void mutt_write_references (string_list_t * r, FILE * f) +void mutt_write_references(string_list_t *r, FILE *f) { - string_list_t **ref = NULL; - int refcnt = 0, refmax = 0; + string_list_t *refs[10]; + int i; - for (; (TrimRef == 0 || refcnt < TrimRef) && r; r = r->next) { - if (refcnt == refmax) - p_realloc(&ref, refmax += REF_INC); - ref[refcnt++] = r; - } - - while (refcnt-- > 0) { - fputc (' ', f); - fputs (ref[refcnt]->data, f); - } + p_clear(refs, countof(refs)); + for (i = 0; i < countof(refs) && r; r = r->next) { + refs[i++] = r; + } - p_delete(&ref); + while (i-- > 0) { + fprintf(f, " %s", refs[i]->data); + } } static int edit_header(int mode, const char *s) @@ -1572,12 +1563,6 @@ const char *mutt_fqdn (short may_hide_host) return p; } -/* normalized character (we're stricter than RFC2822, 3.6.4) */ -static char mutt_normalized_char(char c) -{ - return (isalnum(c) || strchr(".!#$%&'*+-/=?^_`{|}~", c)) ? c : '.'; -} - static void mutt_gen_localpart(char *buf, unsigned int len, const char *fmt) { #define APPEND_FMT(fmt, arg) \ @@ -1605,7 +1590,8 @@ static void mutt_gen_localpart(char *buf, unsigned int len, const char *fmt) int c = *fmt++; if (c != '%') { - APPEND_BYTE(mutt_normalized_char(c)); + /* normalized character (we're stricter than RFC2822, 3.6.4) */ + APPEND_BYTE((isalnum(c) || strchr(".!#$%&'*+-/=?^_`{|}~", c)) ? c : '.'); continue; } @@ -1657,7 +1643,6 @@ static void mutt_gen_localpart(char *buf, unsigned int len, const char *fmt) break; default: /* invalid formats are replaced by '.' */ APPEND_BYTE('.'); - m_strncat(buf, len, ".", 1); } } @@ -1669,16 +1654,16 @@ static void mutt_gen_localpart(char *buf, unsigned int len, const char *fmt) static char *mutt_gen_msgid (void) { - char buf[SHORT_STRING]; - char localpart[SHORT_STRING]; - const char *fqdn; + char buf[SHORT_STRING]; + char localpart[SHORT_STRING]; + const char *fqdn; - if (!(fqdn = mutt_fqdn(0))) - fqdn = NONULL(Hostname); + if (!(fqdn = mutt_fqdn(0))) + fqdn = NONULL(Hostname); - mutt_gen_localpart(localpart, sizeof(localpart), MsgIdFormat); - snprintf(buf, sizeof(buf), "<%s@%s>", localpart, fqdn); - return m_strdup(buf); + mutt_gen_localpart(localpart, sizeof(localpart), MsgIdFormat); + snprintf(buf, sizeof(buf), "<%s@%s>", localpart, fqdn); + return m_strdup(buf); } static RETSIGTYPE alarm_handler (int sig __attribute__ ((unused)))