X-Git-Url: https://git.llucax.com/software/mutt-debian.git/blobdiff_plain/14c29200cb58d3c4a0830265f2433849781858d0..6e0cd7b3aec391b9acd16011500a03d9924f334f:/muttlib.c diff --git a/muttlib.c b/muttlib.c index e0820da..590bef7 100644 --- a/muttlib.c +++ b/muttlib.c @@ -1,6 +1,6 @@ /* - * Copyright (C) 1996-2000 Michael R. Elkins - * Copyright (C) 1999-2000 Thomas Roessler + * Copyright (C) 1996-2000,2007 Michael R. Elkins + * Copyright (C) 1999-2008 Thomas Roessler * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -252,6 +252,21 @@ LIST *mutt_add_list_n (LIST *head, const void *data, size_t len) return head; } +LIST *mutt_find_list (LIST *l, const char *data) +{ + LIST *p = l; + + while (p) + { + if (data == p->data) + return p; + if (data && p->data && mutt_strcmp (p->data, data) == 0) + return p; + p = p->next; + } + return NULL; +} + void mutt_free_list (LIST **list) { LIST *p; @@ -734,7 +749,7 @@ void mutt_merge_envelopes(ENVELOPE* base, ENVELOPE** extra) void _mutt_mktemp (char *s, const char *src, int line) { snprintf (s, _POSIX_PATH_MAX, "%s/mutt-%s-%d-%d-%d", NONULL (Tempdir), NONULL(Hostname), (int) getuid(), (int) getpid (), Counter++); - dprint (1, (debugfile, "%s:%d: mutt_mktemp returns \"%s\".\n", src, line, s)); + dprint (3, (debugfile, "%s:%d: mutt_mktemp returns \"%s\".\n", src, line, s)); unlink (s); } @@ -746,6 +761,7 @@ void mutt_free_alias (ALIAS **p) { t = *p; *p = (*p)->next; + mutt_alias_delete_reverse (t); FREE (&t->name); rfc822_free_address (&t->addr); FREE (&t); @@ -753,11 +769,12 @@ void mutt_free_alias (ALIAS **p) } /* collapse the pathname using ~ or = when possible */ -void mutt_pretty_mailbox (char *s) +void mutt_pretty_mailbox (char *s, size_t buflen) { char *p = s, *q = s; size_t len; url_scheme_t scheme; + char tmp[PATH_MAX]; scheme = url_check_scheme (s); @@ -779,24 +796,34 @@ void mutt_pretty_mailbox (char *s) q = strchr (p, '\0'); p = q; } - - /* first attempt to collapse the pathname */ - while (*p) + + /* cleanup path */ + if (strstr (p, "//") || strstr (p, "/./")) { - if (*p == '/' && p[1] == '/') + /* first attempt to collapse the pathname, this is more + * lightweight than realpath() and doesn't resolve links + */ + while (*p) { - *q++ = '/'; - p += 2; - } - else if (p[0] == '/' && p[1] == '.' && p[2] == '/') - { - *q++ = '/'; - p += 3; + if (*p == '/' && p[1] == '/') + { + *q++ = '/'; + p += 2; + } + else if (p[0] == '/' && p[1] == '.' && p[2] == '/') + { + *q++ = '/'; + p += 3; + } + else + *q++ = *p++; } - else - *q++ = *p++; + *q = 0; } - *q = 0; + else if (strstr (p, "..") && + (scheme == U_UNKNOWN || scheme == U_FILE) && + realpath (p, tmp)) + strfcpy (p, tmp, buflen - (p - s)); if (mutt_strncmp (s, Maildir, (len = mutt_strlen (Maildir))) == 0 && s[len] == '/') @@ -1081,7 +1108,7 @@ void mutt_FormatString (char *dest, /* output buffer */ if ((pid = mutt_create_filter(command->data, NULL, &filter, NULL))) { n = fread(dest, 1, destlen /* already decremented */, filter); - fclose(filter); + safe_fclose (&filter); dest[n] = '\0'; while (dest[n-1] == '\n' || dest[n-1] == '\r') dest[--n] = '\0'; @@ -1612,13 +1639,13 @@ int mutt_buffer_printf (BUFFER* buf, const char* fmt, ...) safe_realloc (&buf->data, buf->dsize); buf->dptr = buf->data + doff; len = vsnprintf (buf->dptr, len, fmt, ap_retry); - va_end (ap_retry); } if (len > 0) buf->dptr += len; va_end (ap); - + va_end (ap_retry); + return len; }