From: Rocco Rutte Date: Tue, 7 Jul 2009 11:16:59 +0000 (+0200) Subject: Make hcache+bcache paths always UTF-8. Closes #3284. X-Git-Tag: mutt-1-5-21-rel~169 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=cccdcf841fe279dd3cc2aa7307965f1791b3cc25;p=mutt Make hcache+bcache paths always UTF-8. Closes #3284. --- diff --git a/ChangeLog b/ChangeLog index 950cd0d7..c1e76a0d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2009-07-07 13:00 +0200 Rocco Rutte (376545d6909c) + + * UPDATING, globals.h, init.h, sendlib.c: Add $wrap_headers. Closes + #3135 + +2009-07-07 12:53 +0200 Rocco Rutte (0980cdb206d2) + + * doc/manual.xml.head: Manual: mention terminal setup for + charsets, more unicode pros. + + Closes #3292. + 2009-07-06 15:28 +0200 Rocco Rutte (ccab6c56b557) * doc/manual.xml.head: Manual: Add a note about when/why to use utf-8 diff --git a/UPDATING b/UPDATING index 515d9529..593f6fb3 100644 --- a/UPDATING +++ b/UPDATING @@ -6,6 +6,7 @@ The keys used are: hg tip: + ! header/body cache paths are always UTF-8 + $wrap_headers to control outgoing message's header length + all text/* parts can be displayed inline without mailcap diff --git a/bcache.c b/bcache.c index 81538d22..1ba5b727 100644 --- a/bcache.c +++ b/bcache.c @@ -1,6 +1,6 @@ /* * Copyright (C) 2006-7 Brendan Cully - * Copyright (C) 2006 Rocco Rutte + * Copyright (C) 2006, 2009 Rocco Rutte * * 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 @@ -42,6 +42,7 @@ static int bcache_path(ACCOUNT *account, const char *mailbox, char *dst, size_t dstlen) { char host[STRING]; + char path[_POSIX_PATH_MAX]; ciss_url_t url; int len; @@ -62,12 +63,14 @@ static int bcache_path(ACCOUNT *account, const char *mailbox, return -1; } - dprint (3, (debugfile, "bcache_path: URL: '%s'\n", host)); + mutt_encode_path (path, sizeof (path), NONULL (mailbox)); len = snprintf (dst, dstlen-1, "%s/%s%s%s", MessageCachedir, - host, NONULL(mailbox), - (mailbox && *mailbox && - mailbox[mutt_strlen(mailbox) - 1] == '/') ? "" : "/"); + host, NONULL (path), + (*path && path[mutt_strlen (path) - 1] == '/') ? "" : "/"); + + dprint (3, (debugfile, "bcache_path: rc: %d, path: '%s'\n", len, dst)); + if (len < 0 || len >= dstlen-1) return -1; diff --git a/doc/manual.xml.head b/doc/manual.xml.head index 6ff51f3f..5a239084 100644 --- a/doc/manual.xml.head +++ b/doc/manual.xml.head @@ -7720,10 +7720,11 @@ support as these use it (body caching requires no external library). Mutt provides optional support for caching message headers for the following types of folders: IMAP, POP, Maildir and MH. Header caching -greatly improves speed because for remote folders, headers usually only -need to be downloaded once. For Maildir and MH, reading the headers from -a single file is much faster than looking at possibly thousands of -single files (since Maildir and MH use one file per message.) +greatly speeds up opening large folders because for remote folders, +headers usually only need to be downloaded once. For Maildir and MH, +reading the headers from a single file is much faster than looking at +possibly thousands of single files (since Maildir and MH use one file +per message.) @@ -7752,7 +7753,6 @@ Both cache methods can be combined using the same directory for storage manual maintenance tasks. - In addition to caching message headers only, Mutt can also cache whole message bodies. This results in faster display of messages for POP and @@ -7762,12 +7762,36 @@ IMAP folders because messages usually have to be downloaded only once. For configuration, the variable $message_cachedir must point to a directory. There, Mutt will -create a hierarchy of subdirectories named like: -proto:user@hostname where proto is -either pop or imap. Within there for each -folder, Mutt stores messages in single files. All files can be removed -as needed if the consumed disk space becomes an issue as Mutt will -silently fetch missing items again. +create a hierarchy of subdirectories named like the account and mailbox +path the cache is for. + + + + + +Cache Directories + + +For using both, header and body caching, $header_cache and $message_cachedir can be safely set +to the same value. + + + +In a header or body cache directory, Mutt creates a directory hierarchy +named like: proto:user@hostname where +proto is either pop or +imap. Within there, for each folder, Mutt stores messages +in single files and header caches in files with the +.hcache extension. All files can be removed as needed if +the consumed disk space becomes an issue as Mutt will silently fetch +missing items again. Pathnames are always stored in UTF-8 encoding. + + + +For Maildir and MH, the header cache files are named after the MD5 +checksum of the path. diff --git a/hcache.c b/hcache.c index 8b14aef1..5195918d 100644 --- a/hcache.c +++ b/hcache.c @@ -828,19 +828,23 @@ mutt_hcache_store_raw (header_cache_t* h, const char* filename, void* data, #endif } -static char* get_foldername(const char *folder) { +static char* get_foldername(const char *folder) +{ char *p = NULL; + char path[_POSIX_PATH_MAX]; struct stat st; + mutt_encode_path (path, sizeof (path), folder); + /* if the folder is local, canonify the path to avoid * to ensure equivalent paths share the hcache */ - if (stat (folder, &st) == 0) + if (stat (path, &st) == 0) { p = safe_malloc (PATH_MAX+1); - if (!realpath (folder, p)) - mutt_str_replace (&p, folder); + if (!realpath (path, p)) + mutt_str_replace (&p, path); } else - p = safe_strdup (folder); + p = safe_strdup (path); return p; } diff --git a/muttlib.c b/muttlib.c index ab04a0de..dd5fa988 100644 --- a/muttlib.c +++ b/muttlib.c @@ -1874,3 +1874,10 @@ int mutt_match_spam_list (const char *s, SPAM_LIST *l, char *text, int x) return 0; } +void mutt_encode_path (char *dest, size_t dlen, const char *src) +{ + char *p = safe_strdup (src); + int rc = mutt_convert_string (&p, Charset, "utf-8", 0); + strfcpy (dest, rc == 0 ? p : src, dlen); + FREE (&p); +} diff --git a/protos.h b/protos.h index 4606c202..d0e1d3f1 100644 --- a/protos.h +++ b/protos.h @@ -190,6 +190,7 @@ void mutt_edit_headers (const char *, const char *, HEADER *, char *, size_t); int mutt_filter_unprintable (char **); void mutt_curses_error (const char *, ...); void mutt_curses_message (const char *, ...); +void mutt_encode_path (char *, size_t, const char *); void mutt_enter_command (void); void mutt_expand_aliases_env (ENVELOPE *); void mutt_expand_file_fmt (char *, size_t, const char *, const char *);