NeoMutt  2024-11-14-34-g5aaf0d
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
hcache.c
Go to the documentation of this file.
1
29#include "config.h"
30#include <stdbool.h>
31#include <string.h>
32#include <sys/stat.h>
33#include "mutt/lib.h"
34#include "config/lib.h"
35#include "email/lib.h"
36#include "core/lib.h"
37#include "hcache/lib.h"
38#include "edata.h"
39#include "mailbox.h"
40
46static const char *maildir_hcache_key(struct Email *e)
47{
48 return e->path + 4;
49}
50
58static size_t maildir_hcache_keylen(const char *fn)
59{
60 const char c_maildir_field_delimiter = *cc_maildir_field_delimiter();
61 const char *p = strrchr(fn, c_maildir_field_delimiter);
62 return p ? (size_t) (p - fn) : mutt_str_len(fn);
63}
64
70{
71 hcache_close(ptr);
72}
73
81int maildir_hcache_delete(struct HeaderCache *hc, struct Email *e)
82{
83 if (!hc || !e)
84 return 0;
85
86 const char *key = maildir_hcache_key(e);
87 size_t keylen = maildir_hcache_keylen(key);
88
89 return hcache_delete_email(hc, key, keylen);
90}
91
97{
98 if (!m)
99 return NULL;
100
101 const char *const c_header_cache = cs_subset_path(NeoMutt->sub, "header_cache");
102
103 return hcache_open(c_header_cache, mailbox_path(m), NULL, true);
104}
105
113struct Email *maildir_hcache_read(struct HeaderCache *hc, struct Email *e, const char *fn)
114{
115 if (!hc || !e)
116 return NULL;
117
118 struct stat st_lastchanged = { 0 };
119 int rc = 0;
120
121 const char *key = maildir_hcache_key(e);
122 size_t keylen = maildir_hcache_keylen(key);
123
124 struct HCacheEntry hce = hcache_fetch_email(hc, key, keylen, 0);
125 if (!hce.email)
126 return NULL;
127
128 const bool c_maildir_header_cache_verify = cs_subset_bool(NeoMutt->sub, "maildir_header_cache_verify");
129 if (c_maildir_header_cache_verify)
130 rc = stat(fn, &st_lastchanged);
131
132 if ((rc == 0) && (st_lastchanged.st_mtime <= hce.uidvalidity))
133 {
136 hce.email->old = e->old;
137 hce.email->path = mutt_str_dup(e->path);
138 maildir_parse_flags(hce.email, fn);
139 }
140 else
141 {
142 email_free(&hce.email);
143 }
144
145 return hce.email;
146}
147
155int maildir_hcache_store(struct HeaderCache *hc, struct Email *e)
156{
157 if (!hc || !e)
158 return 0;
159
160 const char *key = maildir_hcache_key(e);
161 size_t keylen = maildir_hcache_keylen(key);
162
163 return hcache_store_email(hc, key, keylen, e, 0);
164}
const char * cs_subset_path(const struct ConfigSubset *sub, const char *name)
Get a path config item by name.
Definition: helpers.c:168
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:47
Convenience wrapper for the config headers.
const char * cc_maildir_field_delimiter(void)
Get the cached value of $maildir_field_delimiter.
Definition: config_cache.c:131
Convenience wrapper for the core headers.
static const char * mailbox_path(const struct Mailbox *m)
Get the Mailbox's path string.
Definition: mailbox.h:223
void email_free(struct Email **ptr)
Free an Email.
Definition: email.c:46
Structs that make up an email.
void maildir_edata_free(void **ptr)
Free the private Email data - Implements Email::edata_free() -.
Definition: edata.c:38
struct HeaderCache * hcache_open(const char *path, const char *folder, hcache_namer_t namer, bool create)
Multiplexor for StoreOps::open.
Definition: hcache.c:471
int hcache_delete_email(struct HeaderCache *hc, const char *key, size_t keylen)
Multiplexor for StoreOps::delete_record.
Definition: hcache.c:739
void hcache_close(struct HeaderCache **ptr)
Multiplexor for StoreOps::close.
Definition: hcache.c:542
struct HCacheEntry hcache_fetch_email(struct HeaderCache *hc, const char *key, size_t keylen, uint32_t uidvalidity)
Multiplexor for StoreOps::fetch.
Definition: hcache.c:562
int hcache_store_email(struct HeaderCache *hc, const char *key, size_t keylen, struct Email *e, uint32_t uidvalidity)
Multiplexor for StoreOps::store.
Definition: hcache.c:670
Header cache multiplexor.
struct MaildirEmailData * maildir_edata_new(void)
Create a new MaildirEmailData object.
Definition: edata.c:53
static size_t maildir_hcache_keylen(const char *fn)
Calculate the length of the Maildir path.
Definition: hcache.c:58
int maildir_hcache_store(struct HeaderCache *hc, struct Email *e)
Save an Email to the Header Cache.
Definition: hcache.c:155
struct Email * maildir_hcache_read(struct HeaderCache *hc, struct Email *e, const char *fn)
Read an Email from the Header Cache.
Definition: hcache.c:113
struct HeaderCache * maildir_hcache_open(struct Mailbox *m)
Open the Header Cache.
Definition: hcache.c:96
int maildir_hcache_delete(struct HeaderCache *hc, struct Email *e)
Delete an Email from the Header Cache.
Definition: hcache.c:81
void maildir_hcache_close(struct HeaderCache **ptr)
Close the Header Cache.
Definition: hcache.c:69
static const char * maildir_hcache_key(struct Email *e)
Get the header cache key for an Email.
Definition: hcache.c:46
void maildir_parse_flags(struct Email *e, const char *path)
Parse Maildir file flags.
Definition: mailbox.c:82
Maildir Mailbox.
Convenience wrapper for the library headers.
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:253
size_t mutt_str_len(const char *a)
Calculate the length of a string, safely.
Definition: string.c:496
Pop-specific Email data.
The envelope/body of an email.
Definition: email.h:39
void * edata
Driver-specific data.
Definition: email.h:74
bool old
Email is seen, but unread.
Definition: email.h:49
void(* edata_free)(void **ptr)
Definition: email.h:90
char * path
Path of Email (for local Mailboxes)
Definition: email.h:70
Wrapper for Email retrieved from the header cache.
Definition: lib.h:99
uint32_t uidvalidity
IMAP-specific UIDVALIDITY.
Definition: lib.h:100
struct Email * email
Retrieved email.
Definition: lib.h:102
Header Cache.
Definition: lib.h:86
A mailbox.
Definition: mailbox.h:79
Container for Accounts, Notifications.
Definition: neomutt.h:42
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:46