]> granicus.if.org Git - neomutt/commitdiff
Add mx operation save_to_header_cache
authorKevin McCarthy <kevin@8t8.us>
Sat, 15 Dec 2018 22:49:55 +0000 (14:49 -0800)
committerRichard Russon <rich@flatcap.org>
Mon, 7 Jan 2019 15:09:41 +0000 (15:09 +0000)
This will be used when reading protected headers, to store the
encrypted subject in the header cache so it can be searched with.

Co-authored-by: Richard Russon <rich@flatcap.org>
14 files changed:
compress.c
imap/imap.c
imap/imap_private.h
imap/message.c
maildir/maildir.c
maildir/maildir_private.h
maildir/mh.c
maildir/shared.c
mbox/mbox.c
mx.c
mx.h
nntp/nntp.c
notmuch/mutt_notmuch.c
pop/pop.c

index 861884631cead6b4f1a76c594c8e36c28e136114..8d5e2e66c4d00b077e361a350287b80995f79401 100644 (file)
@@ -843,6 +843,23 @@ static int comp_msg_padding_size(struct Mailbox *m)
   return ops->msg_padding_size(m);
 }
 
+/**
+ * comp_msg_save_hcache - Save message to the header cache - Implements MxOps::msg_save_hcache()
+ */
+static int comp_msg_save_hcache(struct Mailbox *m, struct Email *e)
+{
+  if (!m || !m->compress_info)
+    return 0;
+
+  struct CompressInfo *ci = m->compress_info;
+
+  const struct MxOps *ops = ci->child_ops;
+  if (!ops || !ops->msg_save_hcache)
+    return 0;
+
+  return ops->msg_save_hcache(m, e);
+}
+
 /**
  * comp_tags_edit - Implements MxOps::tags_edit()
  */
@@ -965,6 +982,7 @@ struct MxOps MxCompOps = {
   .msg_commit       = comp_msg_commit,
   .msg_close        = comp_msg_close,
   .msg_padding_size = comp_msg_padding_size,
+  .msg_save_hcache  = comp_msg_save_hcache,
   .tags_edit        = comp_tags_edit,
   .tags_commit      = comp_tags_commit,
   .path_probe       = comp_path_probe,
index db2f4d77565ebfa68b96ea318717314c2c514c6f..e18324c8b60134961e4c48c55f6207022c6a1466 100644 (file)
@@ -2527,6 +2527,7 @@ struct MxOps MxImapOps = {
   .msg_commit       = imap_msg_commit,
   .msg_close        = imap_msg_close,
   .msg_padding_size = NULL,
+  .msg_save_hcache  = imap_msg_save_hcache,
   .tags_edit        = imap_tags_edit,
   .tags_commit      = imap_tags_commit,
   .path_probe       = imap_path_probe,
index d64fa4524a4986c7062cf15ee4f17cb633cc2cbe..b511fadcb07524a1b1cc99788f015e50b24b6b42 100644 (file)
@@ -299,6 +299,7 @@ int imap_append_message(struct Mailbox *m, struct Message *msg);
 int imap_msg_open(struct Mailbox *m, struct Message *msg, int msgno);
 int imap_msg_close(struct Mailbox *m, struct Message *msg);
 int imap_msg_commit(struct Mailbox *m, struct Message *msg);
+int imap_msg_save_hcache(struct Mailbox *m, struct Email *e);
 
 /* util.c */
 struct ImapAccountData *imap_adata_get(struct Mailbox *m);
index 03dac63af4c6af9273917969c01500735f1f0853..f615e261bbd3669b7ab619ebaf213de0d78c0664 100644 (file)
@@ -2057,3 +2057,24 @@ int imap_msg_close(struct Mailbox *m, struct Message *msg)
 {
   return mutt_file_fclose(&msg->fp);
 }
+
+/**
+ * imap_msg_save_hcache - Save message to the header cache - Implements MxOps::msg_save_hcache()
+ */
+int imap_msg_save_hcache(struct Mailbox *m, struct Email *e)
+{
+  int rc = 0;
+#ifdef USE_HCACHE
+  bool close_hc = true;
+  struct ImapAccountData *adata = imap_adata_get(m);
+  struct ImapMboxData *mdata = imap_mdata_get(m);
+  if (mdata->hcache)
+    close_hc = false;
+  else
+    mdata->hcache = imap_hcache_open(adata, NULL);
+  rc = imap_hcache_put(mdata, e);
+  if (close_hc)
+    imap_hcache_close(mdata);
+#endif
+  return rc;
+}
index 49823acb18e2898dbb066e5c268fc570da9ad19d..6532eb73d7471ef257c60306b9de54f3733abdf2 100644 (file)
@@ -655,6 +655,22 @@ static int maildir_msg_commit(struct Mailbox *m, struct Message *msg)
   return md_commit_message(m, msg, NULL);
 }
 
+/**
+ * maildir_msg_save_hcache - Save message to the header cache - Implements MxOps::msg_save_hcache()
+ */
+static int maildir_msg_save_hcache(struct Mailbox *m, struct Email *e)
+{
+  int rc = 0;
+#ifdef USE_HCACHE
+  header_cache_t *hc = mutt_hcache_open(HeaderCache, m->path, NULL);
+  char *key = e->path + 3;
+  int keylen = maildir_hcache_keylen(key);
+  rc = mutt_hcache_store(hc, key, keylen, e, 0);
+  mutt_hcache_close(hc);
+#endif
+  return rc;
+}
+
 /**
  * maildir_path_probe - Is this a Maildir mailbox? - Implements MxOps::path_probe()
  */
@@ -696,6 +712,7 @@ struct MxOps MxMaildirOps = {
   .msg_commit       = maildir_msg_commit,
   .msg_close        = mh_msg_close,
   .msg_padding_size = NULL,
+  .msg_save_hcache  = maildir_msg_save_hcache,
   .tags_edit        = NULL,
   .tags_commit      = NULL,
   .path_probe       = maildir_path_probe,
index 5efcb9ec9d4ea4b5fb532c16b35346a37b80ad82..dd75183b983b84e3e6540575b17b120e21966561 100644 (file)
@@ -82,10 +82,12 @@ int             mh_mbox_check      (struct Mailbox *m, int *index_hint);
 int             mh_mbox_close      (struct Mailbox *m);
 int             mh_mbox_sync       (struct Mailbox *m, int *index_hint);
 int             mh_msg_close       (struct Mailbox *m, struct Message *msg);
+int             mh_msg_save_hcache (struct Mailbox *m, struct Email *e);
 
 /* Maildir/MH shared functions */
 void                    maildir_canon_filename (struct Buffer *dest, const char *src);
 void                    maildir_delayed_parsing(struct Mailbox *m, struct Maildir **md, struct Progress *progress);
+size_t                  maildir_hcache_keylen  (const char *fn);
 struct MaildirMboxData *maildir_mdata_get      (struct Mailbox *m);
 int                     maildir_mh_open_message(struct Mailbox *m, struct Message *msg, int msgno, bool is_maildir);
 int                     maildir_move_to_context(struct Mailbox *m, struct Maildir **md);
index 0ba59f97056a8c5119b0bd13f59e4616610cde76..2f4a6bf75ac93cb3a2669c1430eec7bf8881a96c 100644 (file)
@@ -815,6 +815,7 @@ struct MxOps MxMhOps = {
   .msg_commit       = mh_msg_commit,
   .msg_close        = mh_msg_close,
   .msg_padding_size = NULL,
+  .msg_save_hcache  = mh_msg_save_hcache,
   .tags_edit        = NULL,
   .tags_commit      = NULL,
   .path_probe       = mh_path_probe,
index 7d53ada04d123f5d11bec975b17faf865c7919ae..0a0b637795afb1d609e8ddf73ca49d72c4aa12a5 100644 (file)
@@ -488,7 +488,7 @@ int maildir_move_to_context(struct Mailbox *m, struct Maildir **md)
  *
  * @note This length excludes the flags, which will vary
  */
-static size_t maildir_hcache_keylen(const char *fn)
+size_t maildir_hcache_keylen(const char *fn)
 {
   const char *p = strrchr(fn, ':');
   return p ? (size_t)(p - fn) : mutt_str_strlen(fn);
@@ -1853,3 +1853,17 @@ int mh_msg_close(struct Mailbox *m, struct Message *msg)
 {
   return mutt_file_fclose(&msg->fp);
 }
+
+/**
+ * mh_msg_save_hcache - Save message to the header cache - Implements MxOps::msg_save_hcache()
+ */
+int mh_msg_save_hcache(struct Mailbox *m, struct Email *e)
+{
+  int rc = 0;
+#ifdef USE_HCACHE
+  header_cache_t *hc = mutt_hcache_open(HeaderCache, m->path, NULL);
+  rc = mutt_hcache_store(hc, e->path, strlen(e->path), e, 0);
+  mutt_hcache_close(hc);
+#endif
+  return rc;
+}
index 028f13235f597a1cc72094450430402de289382f..013b7ed6a6405f0258348c5b44524b51850886f4 100644 (file)
@@ -1835,6 +1835,7 @@ struct MxOps MxMboxOps = {
   .msg_commit       = mbox_msg_commit,
   .msg_close        = mbox_msg_close,
   .msg_padding_size = mbox_msg_padding_size,
+  .msg_save_hcache  = NULL,
   .tags_edit        = NULL,
   .tags_commit      = NULL,
   .path_probe       = mbox_path_probe,
@@ -1862,6 +1863,7 @@ struct MxOps MxMmdfOps = {
   .msg_commit       = mmdf_msg_commit,
   .msg_close        = mbox_msg_close,
   .msg_padding_size = mmdf_msg_padding_size,
+  .msg_save_hcache  = NULL,
   .tags_edit        = NULL,
   .tags_commit      = NULL,
   .path_probe       = mbox_path_probe,
diff --git a/mx.c b/mx.c
index 2afe4ef50d54f5843a596cd94facdb515a5e06bc..6331f98e3b2f66479f53eb790723f6ecb14aa634 100644 (file)
--- a/mx.c
+++ b/mx.c
@@ -1570,3 +1570,20 @@ int mx_mbox_check_stats(struct Mailbox *m, int flags)
 
   return m->mx_ops->mbox_check_stats(m, flags);
 }
+
+/**
+ * mx_save_to_header_cache - Save message to the header cache - Wrapper for MxOps::msg_save_hcache()
+ * @param m Mailbox
+ * @param e Email
+ * @retval  0 Success
+ * @retval -1 Failure
+ *
+ * Write a single header out to the header cache.
+ */
+int mx_save_hcache(struct Mailbox *m, struct Email *e)
+{
+  if (!m->mx_ops || !m->mx_ops->msg_save_hcache)
+    return 0;
+
+  return m->mx_ops->msg_save_hcache(m, e);
+}
diff --git a/mx.h b/mx.h
index 0ec265b4d6c32bd1d42d34774778ae1d501b8644..89ee3feacf48a323aaa74bdc2fb40ff709b31523 100644 (file)
--- a/mx.h
+++ b/mx.h
@@ -205,6 +205,14 @@ struct MxOps
    * @retval num Bytes of padding
    */
   int (*msg_padding_size)(struct Mailbox *m);
+  /**
+   * msg_save_hcache - Save message to the header cache
+   * @param m Mailbox
+   * @param e Email
+   * @retval  0 Success
+   * @retval -1 Failure
+   */
+  int (*msg_save_hcache) (struct Mailbox *m, struct Email *e);
   /**
    * tags_edit - Prompt and validate new messages tags
    * @param m      Mailbox
@@ -270,6 +278,7 @@ int             mx_msg_commit      (struct Mailbox *m, struct Message *msg);
 struct Message *mx_msg_open_new    (struct Mailbox *m, struct Email *e, int flags);
 struct Message *mx_msg_open        (struct Mailbox *m, int msgno);
 int             mx_msg_padding_size(struct Mailbox *m);
+int             mx_save_hcache     (struct Mailbox *m, struct Email *e);
 int             mx_path_canon      (char *buf, size_t buflen, const char *folder, int *magic);
 int             mx_path_canon2     (struct Mailbox *m, const char *folder);
 int             mx_path_parent     (char *buf, size_t buflen);
index 54239017bc4c54fc12d0fd9f8d38fb6eb6ecf6c1..0f8597da128f3012df1f39f699d1a7f1851133ef 100644 (file)
@@ -2894,6 +2894,7 @@ struct MxOps MxNntpOps = {
   .msg_commit       = NULL,
   .msg_close        = nntp_msg_close,
   .msg_padding_size = NULL,
+  .msg_save_hcache  = NULL,
   .tags_edit        = NULL,
   .tags_commit      = NULL,
   .path_probe       = nntp_path_probe,
index 7a5778032b68ed34a4085f8fb15e92124cbaa234..6e204e5334226fe7e43a382cc1f13916746f0112 100644 (file)
@@ -2552,6 +2552,7 @@ struct MxOps MxNotmuchOps = {
   .msg_commit       = nm_msg_commit,
   .msg_close        = nm_msg_close,
   .msg_padding_size = NULL,
+  .msg_save_hcache  = NULL,
   .tags_edit        = nm_tags_edit,
   .tags_commit      = nm_tags_commit,
   .path_probe       = nm_path_probe,
index 4cfd6231a0e6765d1fd9db058b5da9f69ea5ca2f..d0289225e42d5842970eabbf050c7a5f6b0ed5c6 100644 (file)
--- a/pop/pop.c
+++ b/pop/pop.c
@@ -1211,6 +1211,23 @@ static int pop_msg_close(struct Mailbox *m, struct Message *msg)
   return mutt_file_fclose(&msg->fp);
 }
 
+/**
+ * pop_msg_save_hcache - Save message to the header cache - Implements MxOps::msg_save_hcache()
+ */
+static int pop_msg_save_hcache(struct Mailbox *m, struct Email *e)
+{
+  int rc = 0;
+#ifdef USE_HCACHE
+  struct PopAccountData *adata = pop_get_adata(m);
+  struct PopEmailData *edata = e->edata;
+  header_cache_t *hc = pop_hcache_open(adata, m->path);
+  rc = mutt_hcache_store(hc, edata->uid, strlen(edata->uid), e, 0);
+  mutt_hcache_close(hc);
+#endif
+
+  return rc;
+}
+
 /**
  * pop_path_probe - Is this a POP mailbox? - Implements MxOps::path_probe()
  */
@@ -1276,6 +1293,7 @@ struct MxOps MxPopOps = {
   .msg_commit       = NULL,
   .msg_close        = pop_msg_close,
   .msg_padding_size = NULL,
+  .msg_save_hcache  = pop_msg_save_hcache,
   .tags_edit        = NULL,
   .tags_commit      = NULL,
   .path_probe       = pop_path_probe,