From: Kevin McCarthy Date: Sat, 15 Dec 2018 22:49:55 +0000 (-0800) Subject: Add mx operation save_to_header_cache. X-Git-Tag: mutt-1-12-rel~181 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=09dd4a5d7b69dc688c4a7f3c07b74b66bea7315f;p=mutt Add mx operation save_to_header_cache. This will be used when reading protected headers, to store the encrypted subject in the header cache so it can be searched with. --- diff --git a/compress.c b/compress.c index a09295d8..9b809507 100644 --- a/compress.c +++ b/compress.c @@ -981,5 +981,6 @@ struct mx_ops mx_comp_ops = .commit_msg = commit_message, .open_new_msg = open_new_message, .msg_padding_size = compress_msg_padding_size, + .save_to_header_cache = NULL, /* compressed doesn't support maildir/mh */ }; diff --git a/imap/imap.c b/imap/imap.c index 696689ba..c7ff117a 100644 --- a/imap/imap.c +++ b/imap/imap.c @@ -1605,6 +1605,25 @@ static int imap_check_mailbox_reopen (CONTEXT *ctx, int *index_hint) return rc; } +static int imap_save_to_header_cache (CONTEXT *ctx, HEADER *h) +{ + int rc = 0; +#ifdef USE_HCACHE + int close_hc = 1; + IMAP_DATA* idata; + + idata = (IMAP_DATA *)ctx->data; + if (idata->hcache) + close_hc = 0; + else + idata->hcache = imap_hcache_open (idata, NULL); + rc = imap_hcache_put (idata, h); + if (close_hc) + imap_hcache_close (idata); +#endif + return rc; +} + /* split path into (idata,mailbox name) */ static int imap_get_mailbox (const char* path, IMAP_DATA** hidata, char* buf, size_t blen) { @@ -2336,4 +2355,5 @@ struct mx_ops mx_imap_ops = { .open_new_msg = imap_open_new_message, .check = imap_check_mailbox_reopen, .sync = NULL, /* imap syncing is handled by imap_sync_mailbox */ + .save_to_header_cache = imap_save_to_header_cache, }; diff --git a/mailbox.h b/mailbox.h index 6ae29e23..602850ed 100644 --- a/mailbox.h +++ b/mailbox.h @@ -82,6 +82,7 @@ int mx_is_pop (const char *); int mx_access (const char*, int); int mx_check_empty (const char *); int mx_msg_padding_size (CONTEXT *); +int mx_save_to_header_cache (CONTEXT *, HEADER *); int mx_is_maildir (const char *); int mx_is_mh (const char *); diff --git a/mbox.c b/mbox.c index 0f07cc49..254db452 100644 --- a/mbox.c +++ b/mbox.c @@ -1406,6 +1406,7 @@ struct mx_ops mx_mbox_ops = { .check = mbox_check_mailbox, .sync = mbox_sync_mailbox, .msg_padding_size = mbox_msg_padding_size, + .save_to_header_cache = NULL, }; struct mx_ops mx_mmdf_ops = { @@ -1419,4 +1420,5 @@ struct mx_ops mx_mmdf_ops = { .check = mbox_check_mailbox, .sync = mbox_sync_mailbox, .msg_padding_size = mmdf_msg_padding_size, + .save_to_header_cache = NULL, }; diff --git a/mh.c b/mh.c index 02472601..1dc10893 100644 --- a/mh.c +++ b/mh.c @@ -2508,6 +2508,33 @@ static int mh_check_mailbox (CONTEXT * ctx, int *index_hint) } +static int maildir_save_to_header_cache (CONTEXT *ctx, HEADER *h) +{ + int rc = 0; +#if USE_HCACHE + header_cache_t *hc; + + hc = mutt_hcache_open (HeaderCache, ctx->path, NULL); + rc = mutt_hcache_store (hc, h->path + 3, h, 0, &maildir_hcache_keylen, + MUTT_GENERATE_UIDVALIDITY); + mutt_hcache_close (hc); +#endif + return rc; +} + + +static int mh_save_to_header_cache (CONTEXT *ctx, HEADER *h) +{ + int rc = 0; +#if USE_HCACHE + header_cache_t *hc; + + hc = mutt_hcache_open (HeaderCache, ctx->path, NULL); + rc = mutt_hcache_store (hc, h->path, h, 0, strlen, MUTT_GENERATE_UIDVALIDITY); + mutt_hcache_close (hc); +#endif + return rc; +} /* @@ -2754,6 +2781,7 @@ struct mx_ops mx_maildir_ops = { .open_new_msg = maildir_open_new_message, .check = maildir_check_mailbox, .sync = mh_sync_mailbox, + .save_to_header_cache = maildir_save_to_header_cache, }; struct mx_ops mx_mh_ops = { @@ -2766,4 +2794,5 @@ struct mx_ops mx_mh_ops = { .open_new_msg = mh_open_new_message, .check = mh_check_mailbox, .sync = mh_sync_mailbox, + .save_to_header_cache = mh_save_to_header_cache, }; diff --git a/mutt.h b/mutt.h index 90d63f7a..11eb5163 100644 --- a/mutt.h +++ b/mutt.h @@ -981,6 +981,7 @@ struct mx_ops int (*commit_msg) (struct _context *, struct _message *); int (*open_new_msg) (struct _message *, struct _context *, HEADER *); int (*msg_padding_size) (struct _context *); + int (*save_to_header_cache) (struct _context *, struct header *); }; typedef struct _context diff --git a/mx.c b/mx.c index 9d311ef8..ff3a1a33 100644 --- a/mx.c +++ b/mx.c @@ -1545,4 +1545,13 @@ int mx_msg_padding_size (CONTEXT *ctx) return ctx->mx_ops->msg_padding_size (ctx); } +/* Writes a single header out to the header cache. */ +int mx_save_to_header_cache (CONTEXT *ctx, HEADER *h) +{ + if (!ctx->mx_ops || !ctx->mx_ops->save_to_header_cache) + return 0; + + return ctx->mx_ops->save_to_header_cache (ctx, h); +} + /* vim: set sw=2: */ diff --git a/pop.c b/pop.c index 288166de..99605195 100644 --- a/pop.c +++ b/pop.c @@ -798,6 +798,22 @@ static int pop_check_mailbox (CONTEXT *ctx, int *index_hint) return 0; } +static int pop_save_to_header_cache (CONTEXT *ctx, HEADER *h) +{ + int rc = 0; +#ifdef USE_HCACHE + POP_DATA *pop_data; + header_cache_t *hc; + + pop_data = (POP_DATA *)ctx->data; + hc = pop_hcache_open (pop_data, ctx->path); + rc = mutt_hcache_store (hc, h->data, h, 0, strlen, MUTT_GENERATE_UIDVALIDITY); + mutt_hcache_close (hc); +#endif + + return rc; +} + /* Fetch messages and save them in $spoolfile */ void pop_fetch_mail (void) { @@ -970,4 +986,5 @@ struct mx_ops mx_pop_ops = { .commit_msg = NULL, .open_new_msg = NULL, .sync = pop_sync_mailbox, + .save_to_header_cache = pop_save_to_header_cache, };