WHERE char *Maildir;
#ifdef USE_HCACHE
-WHERE char *HeaderCache;
#if defined(HAVE_GDBM)
WHERE char *HeaderCachePageSize;
#endif /* HAVE_GDBM */
WHERE char *Muttrc INITVAL (NULL);
#ifdef USE_NNTP
-WHERE char *NewsCacheDir;
WHERE char *GroupFormat;
WHERE char *NewsServer;
WHERE char *NntpUser;
idata->newMailCount = 0;
#ifdef USE_HCACHE
- if ((hc = mutt_hcache_open (HeaderCache, ctx->path))) {
+ if ((hc = mutt_hcache_open(ctx->path))) {
snprintf (buf, sizeof (buf),
"FETCH %d:%d (UID FLAGS)", msgbegin + 1, msgend + 1);
** maximum line length is determined by the terminal width and $$wrapmargin.
*/
#ifdef USE_HCACHE
- {"header_cache", DT_PATH, R_NONE, UL &HeaderCache, "~/.cache/madmutt/" },
- /*
- ** .pp
- ** Availability: Header Cache
- **
- ** .pp
- ** The $$header_cache variable points to the header cache database.
- ** .pp
- ** If $$header_cache points to a directory it will contain a header cache
- ** database per folder. If $$header_cache points to a file that file will
- ** be a single global header cache. By default it is \fIunset\fP so no
- ** header caching will be used.
- */
#if defined(HAVE_GDBM)
{"header_cache_pagesize", DT_STR, R_NONE, UL &HeaderCachePageSize, "16384"},
/*
** does not support posting to that newsgroup or a group is totally read-only, that
** posting will not have any effect.
*/
- {"nntp_cache_dir", DT_PATH, R_NONE, UL &NewsCacheDir, "~/.cache/madmutt/"},
- /*
- ** .pp
- ** Availability: NNTP
- **
- ** .pp
- ** This variable points to directory where Madmutt will cache news
- ** article headers. If \fIunset\fP, headers will not be saved at all
- ** and will be reloaded each time when you enter a newsgroup.
- ** .pp
- ** As for the header caching in connection with IMAP and/or Maildir,
- ** this drastically increases speed and lowers traffic.
- */
{"nntp_host", DT_STR, R_NONE, UL &NewsServer, "" },
/*
** .pp
## beep_new
## bindir
## ca_certificates_file
+## cachedir
## cert_file
## charset
## docdir
#include <pwd.h>
#include <lib-lua/lib-lua.h>
+#include <lib-ui/curses.h>
#include <lib-sys/unix.h>
#include "../mutt.h"
return m_strdup(NONULL(mod_core.shorthost));
}
+static void madmutt_update_cachedir(const char *dir)
+{
+ static char *cachedir = NULL;
+ char path[_POSIX_PATH_MAX];
+ char buf[HUGE_STRING];
+ struct stat st;
+
+ _mutt_expand_path(path, sizeof(path), dir, 0);
+ if (lstat(path, &st) || !S_ISDIR(st.st_mode)) {
+ snprintf(buf, sizeof(buf), _("Directory %s not exist. Create it?"),
+ dir);
+ if (mutt_yesorno(buf, M_YES) == M_YES)
+ mkdir(path, 0750);
+ }
+
+ if (lstat(path, &st) || !S_ISDIR(st.st_mode)) {
+ mutt_error(_("Cache directory not created!"));
+ return;
+ }
+ if (st.st_mode & 0027) {
+ snprintf(buf, sizeof(buf),
+ _("Directory %s is unsafe, do you want to use it ?"), dir);
+ if (mutt_yesorno(buf, M_YES) != M_YES)
+ return;
+ }
+
+ m_strreplace(&cachedir, path);
+ mod_core.cachedir = cachedir;
+}
+
+
#if defined(HAVE_QDBM)
# define HCACHE_BACKEND "qdbm"
#elif defined(HAVE_GDBM)
# define HCACHE_BACKEND NULL
#endif
+static void mod_core_init2(void)
+{
+ madmutt_update_cachedir("~/.cache/madmutt");
+}
+#define mod_core_init() do { (mod_core_init)(); mod_core_init2(); } while (0)
+
@package mod_core {
/*
** .pp
RETURN(p ? p + 1 : (CurrentFolder ?: ""));
}
};
+
+
+ const string_t cachedir = NULL;
+ void setcachedir(const string_t path) {
+ madmutt_update_cachedir(path);
+ RETURN();
+ };
};
@package MTransport {
/* }}} */
-hcache_t *mutt_hcache_open(const char *path, const char *folder)
+hcache_t *mutt_hcache_open(const char *folder)
{
- hcache_t *h = p_new(hcache_t, 1);
+ const char *path;
+ hcache_t *h;
- h->folder = m_strdup(folder);
- h->crc = generate_crc32();
-
- if (m_strisempty(path)) {
- p_delete(&h->folder);
- p_delete(&h);
+ if (m_strisempty(mod_core.cachedir)) {
return NULL;
}
- path = mutt_hcache_per_folder(path, folder);
+ h = p_new(hcache_t, 1);
+ h->folder = m_strdup(folder);
+ h->crc = generate_crc32();
+
+ path = mutt_hcache_per_folder(mod_core.cachedir, folder);
{
#if defined(HAVE_QDBM)
#ifdef USE_HCACHE
typedef struct hcache_t hcache_t;
-hcache_t *mutt_hcache_open(const char *path, const char *folder);
+hcache_t *mutt_hcache_open(const char *folder);
void mutt_hcache_close(hcache_t **db);
HEADER *mutt_hcache_restore(const void *d, HEADER **oh);
struct stat lastchanged;
int ret;
- hc = mutt_hcache_open (HeaderCache, ctx->path);
+ hc = mutt_hcache_open(ctx->path);
#endif
for (p = md, count = 0; p; p = p->next, count++) {
#ifdef USE_HCACHE
if (ctx->magic == M_MAILDIR)
- hc = mutt_hcache_open (HeaderCache, ctx->path);
+ hc = mutt_hcache_open(ctx->path);
#endif /* USE_HCACHE */
for (i = 0; i < ctx->msgcount; i++) {
}
#define nntp_cache_expand(dst, dlen, fmt, ...) \
- do { \
- snprintf((dst), (dlen), "%s/" fmt, NewsCacheDir, ##__VA_ARGS__); \
- mutt_expand_path((dst), (dlen)); \
+ do { \
+ snprintf((dst), (dlen), "%s/" fmt, mod_core.cachedir, ##__VA_ARGS__);\
+ mutt_expand_path((dst), (dlen)); \
} while (0)
/* Loads $news_cache_dir/.index into memory, loads newsserver data
* and newsgroup cache names */
static int nntp_parse_cacheindex(nntp_server_t *news)
{
- struct stat st;
- char buf[HUGE_STRING], *cp;
- char dir[_POSIX_PATH_MAX], file[_POSIX_PATH_MAX];
- FILE *idx;
nntp_data_t *data;
+ char file[_POSIX_PATH_MAX], buf[HUGE_STRING], *cp;
+ FILE *idx;
int l, m, t;
- unset_option (OPTNEWSCACHE);
- if (m_strisempty(NewsCacheDir))
+ if (m_strisempty(mod_core.cachedir)) {
+ unset_option(OPTNEWSCACHE);
return 0;
-
- m_strcpy(dir, sizeof(dir), NewsCacheDir);
- mutt_expand_path(dir, sizeof(dir));
-
- if (lstat (dir, &st) || (st.st_mode & S_IFDIR) == 0) {
- snprintf(buf, sizeof(buf), _("Directory %s not exist. Create it?"), dir);
- if (mutt_yesorno (buf, M_YES) != M_YES
- || mkdir (dir, (S_IRWXU + S_IRWXG + S_IRWXO))) {
- mutt_error _("Cache directory not created!");
-
- return -1;
- }
- mutt_clear_error ();
+ } else {
+ set_option(OPTNEWSCACHE);
}
- set_option (OPTNEWSCACHE);
-
p_delete(&news->cache);
- snprintf(buf, sizeof (buf), "%s/%s.index", dir, news->conn->account.host);
+ nntp_cache_expand(buf, sizeof(buf), "%s.index", news->conn->account.host);
if (!(idx = safe_fopen (buf, "a+")))
return 0;
rewind (idx);