Permalink
Browse files

when building message cache dirs, mkdir new and tmp

makes cache dirs get recognized as Maildirs to enable reading them
as offline backups
  • Loading branch information...
jcs committed Apr 24, 2012
1 parent 0becac3 commit 80a51932048ca3860d6fac30c6eed7a105cc1e57
Showing with 17 additions and 1 deletion.
  1. +17 −1 bcache.c
View
@@ -25,6 +25,7 @@
#include <errno.h>
#include <dirent.h>
#include <stdio.h>
#include <libgen.h>
#include "mutt.h"
#include "account.h"
@@ -65,7 +66,7 @@ static int bcache_path(ACCOUNT *account, const char *mailbox,
mutt_encode_path (path, sizeof (path), NONULL (mailbox));
len = snprintf (dst, dstlen-1, "%s/%s%s%s", MessageCachedir,
len = snprintf (dst, dstlen-1, "%s/%s%s%scur/", MessageCachedir,
host, path,
(*path && path[mutt_strlen (path) - 1] == '/') ? "" : "/");
@@ -129,6 +130,7 @@ FILE* mutt_bcache_get(body_cache_t *bcache, const char *id)
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;
@@ -157,6 +159,20 @@ FILE* mutt_bcache_put(body_cache_t *bcache, const char *id, int tmp)
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));

0 comments on commit 80a5193

Please sign in to comment.