# $Id: mutt-message_cache_maildir.diff,v 1.3 2010/01/02 19:47:47 jcs Exp $ # # a cheap hack to mutt to make it write its message cache files into a cur/ # subdirectory as well as making sure a new/ subdirectory exists so mutt will # recognize it as a maildir mailbox. # # allows one to make a muttrc that overrides the spoolfile and folder # variables, pointing them at the mutt message cache directory tree to read # mail offline. # # see http://jcs.org/notaweblog/2008/09/29/making_mutt_useful_offline/ # # by joshua stein # --- bcache.c.orig Mon Jan 26 20:40:54 2009 +++ bcache.c Fri Jan 1 20:56:44 2010 @@ -25,6 +25,7 @@ #include #include #include +#include #include "mutt.h" #include "account.h" @@ -64,7 +65,7 @@ dprint (3, (debugfile, "bcache_path: URL: '%s'\n", host)); - len = snprintf (dst, dstlen-1, "%s/%s%s%s", MessageCachedir, + len = snprintf (dst, dstlen-1, "%s/%s%s%scur/", MessageCachedir, host, NONULL(mailbox), (mailbox && *mailbox && mailbox[mutt_strlen(mailbox) - 1] == '/') ? "" : "/"); @@ -126,6 +127,7 @@ FILE* mutt_bcache_put(body_cache_t *bcache, const char *id, int tmp) { char path[_POSIX_PATH_MAX]; + char newpath[_POSIX_PATH_MAX]; FILE* fp; char* s; struct stat sb; @@ -153,6 +155,20 @@ *s = '/'; s = strchr (s + 1, '/'); } + + /* make sure new and tmp dirs exist in parent to be like real maildirs */ + if (s = dirname(path)) { + s = dirname(s); + + snprintf (newpath, sizeof (newpath), "%s/new", s); + if (stat (newpath, &sb) < 0 && (errno != ENOENT || mkdir (newpath, 0777) < 0)) + return NULL; + + snprintf (newpath, sizeof (newpath), "%s/tmp", s); + if (stat (newpath, &sb) < 0 && (errno != ENOENT || mkdir (newpath, 0777) < 0)) + return NULL; + } else + return NULL; out: dprint (3, (debugfile, "bcache: put: '%s'\n", path));