NeoMutt  2024-04-25-1-g3de005
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
hcache.c File Reference

Maildir Header Cache. More...

#include "config.h"
#include <stdbool.h>
#include <string.h>
#include <sys/stat.h>
#include "mutt/lib.h"
#include "config/lib.h"
#include "email/lib.h"
#include "core/lib.h"
#include "hcache/lib.h"
#include "edata.h"
#include "mailbox.h"
+ Include dependency graph for hcache.c:

Go to the source code of this file.

Functions

static const char * maildir_hcache_key (struct Email *e)
 Get the header cache key for an Email.
 
static size_t maildir_hcache_keylen (const char *fn)
 Calculate the length of the Maildir path.
 
void maildir_hcache_close (struct HeaderCache **ptr)
 Close the Header Cache.
 
int maildir_hcache_delete (struct HeaderCache *hc, struct Email *e)
 Delete an Email from the Header Cache.
 
struct HeaderCachemaildir_hcache_open (struct Mailbox *m)
 Open the Header Cache.
 
struct Emailmaildir_hcache_read (struct HeaderCache *hc, struct Email *e, const char *fn)
 Read an Email from the Header Cache.
 
int maildir_hcache_store (struct HeaderCache *hc, struct Email *e)
 Save an Email to the Header Cache.
 

Detailed Description

Maildir Header Cache.

Authors
  • Richard Russon

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file hcache.c.

Function Documentation

◆ maildir_hcache_key()

static const char * maildir_hcache_key ( struct Email e)
static

Get the header cache key for an Email.

Parameters
eEmail
Return values
strHeader cache key string

Definition at line 46 of file hcache.c.

47{
48 return e->path + 4;
49}
char * path
Path of Email (for local Mailboxes)
Definition: email.h:70
+ Here is the caller graph for this function:

◆ maildir_hcache_keylen()

static size_t maildir_hcache_keylen ( const char *  fn)
static

Calculate the length of the Maildir path.

Parameters
fnFile name
Return values
numLength in bytes
Note
This length excludes the flags, which will vary

Definition at line 58 of file hcache.c.

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}
const char * cc_maildir_field_delimiter(void)
Get the cached value of $maildir_field_delimiter.
Definition: config_cache.c:131
size_t mutt_str_len(const char *a)
Calculate the length of a string, safely.
Definition: string.c:490
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ maildir_hcache_close()

void maildir_hcache_close ( struct HeaderCache **  ptr)

Close the Header Cache.

Parameters
ptrHeader Cache

Definition at line 69 of file hcache.c.

70{
71 hcache_close(ptr);
72}
void hcache_close(struct HeaderCache **ptr)
Multiplexor for StoreOps::close.
Definition: hcache.c:541
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ maildir_hcache_delete()

int maildir_hcache_delete ( struct HeaderCache hc,
struct Email e 
)

Delete an Email from the Header Cache.

Parameters
hcHeader Cache
eEmail to delete
Return values
0Success
-1Error

Definition at line 81 of file hcache.c.

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}
int hcache_delete_email(struct HeaderCache *hc, const char *key, size_t keylen)
Multiplexor for StoreOps::delete_record.
Definition: hcache.c:738
static size_t maildir_hcache_keylen(const char *fn)
Calculate the length of the Maildir path.
Definition: hcache.c:58
static const char * maildir_hcache_key(struct Email *e)
Get the header cache key for an Email.
Definition: hcache.c:46
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ maildir_hcache_open()

struct HeaderCache * maildir_hcache_open ( struct Mailbox m)

Open the Header Cache.

Parameters
mMailbox

Definition at line 96 of file hcache.c.

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);
104}
const char * cs_subset_path(const struct ConfigSubset *sub, const char *name)
Get a path config item by name.
Definition: helpers.c:169
static const char * mailbox_path(const struct Mailbox *m)
Get the Mailbox's path string.
Definition: mailbox.h:223
struct HeaderCache * hcache_open(const char *path, const char *folder, hcache_namer_t namer)
Multiplexor for StoreOps::open.
Definition: hcache.c:472
Container for Accounts, Notifications.
Definition: neomutt.h:41
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:45
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ maildir_hcache_read()

struct Email * maildir_hcache_read ( struct HeaderCache hc,
struct Email e,
const char *  fn 
)

Read an Email from the Header Cache.

Parameters
[in]hcHeader Cache
[in]eEmail to find
[in]fnFilename
Return values
ptrEmail from Header Cache

Definition at line 113 of file hcache.c.

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}
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:48
void email_free(struct Email **ptr)
Free an Email.
Definition: email.c:46
void maildir_edata_free(void **ptr)
Free the private Email data - Implements Email::edata_free() -.
Definition: edata.c:38
struct HCacheEntry hcache_fetch_email(struct HeaderCache *hc, const char *key, size_t keylen, uint32_t uidvalidity)
Multiplexor for StoreOps::fetch.
Definition: hcache.c:561
struct MaildirEmailData * maildir_edata_new(void)
Create a new MaildirEmailData object.
Definition: edata.c:53
void maildir_parse_flags(struct Email *e, const char *path)
Parse Maildir file flags.
Definition: mailbox.c:82
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:253
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
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
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ maildir_hcache_store()

int maildir_hcache_store ( struct HeaderCache hc,
struct Email e 
)

Save an Email to the Header Cache.

Parameters
hcHeader Cache
eEmail to save
Return values
0Success
-1Error

Definition at line 155 of file hcache.c.

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}
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:669
+ Here is the call graph for this function:
+ Here is the caller graph for this function: