]> granicus.if.org Git - neomutt/commitdiff
Add option to scan mailboxes during first run
authorKevin McCarthy <kevin@8t8.us>
Thu, 1 Aug 2019 01:56:29 +0000 (18:56 -0700)
committerRichard Russon <rich@flatcap.org>
Mon, 19 Aug 2019 23:14:27 +0000 (00:14 +0100)
The scanner will disable the header cache, allowing scanning all
messages in the mailbox.

Co-authored-by: Richard Russon <rich@flatcap.org>
autocrypt/autocrypt.c
autocrypt/autocrypt_db.c
autocrypt/autocrypt_private.h

index 3d7dd09fb65463ab0c862738499e6c86b4c923d7..d8b8a0fb86ddcb7cdc8e31b274a71f1eefd933bf 100644 (file)
@@ -35,6 +35,8 @@
 #include "curs_lib.h"
 #include "globals.h"
 #include "mutt_curses.h"
+#include "muttlib.h"
+#include "mx.h"
 #include "ncrypt/ncrypt.h"
 #include "send.h"
 
@@ -795,3 +797,70 @@ int mutt_autocrypt_generate_gossip_list(struct Email *hdr)
   mutt_autocrypt_db_peer_free(&peer);
   return rv;
 }
+
+/* This is invoked during the first autocrypt initialization,
+ * to scan one or more mailboxes for autocrypt headers.
+ *
+ * Due to the implementation, header-cached headers are not scanned,
+ * so this routine just opens up the mailboxes with $header_cache
+ * temporarily disabled.
+ */
+void mutt_autocrypt_scan_mailboxes(void)
+{
+  int scan;
+  struct Buffer *folderbuf = NULL;
+  struct Context *ctx = NULL;
+
+#ifdef USE_HCACHE
+  char *old_hdrcache = C_HeaderCache;
+  C_HeaderCache = NULL;
+#endif
+
+  folderbuf = mutt_buffer_pool_get();
+
+  /* L10N:
+     The first time autocrypt is enabled, Mutt will ask to scan
+     through one or more mailboxes for Autocrypt: headers.
+     Those headers are then captured in the database as peer records
+     and used for encryption.
+     If this is answered yes, they will be prompted for a mailbox.
+  */
+  scan = mutt_yesorno(_("Scan a mailbox for autocrypt headers?"), MUTT_YES);
+  while (scan == MUTT_YES)
+  {
+    /* L10N:
+       The prompt for a mailbox to scan for Autocrypt: headers
+    */
+    if ((!mutt_buffer_enter_fname(_("Scan mailbox"), folderbuf, 1)) &&
+        mutt_buffer_len(folderbuf))
+    {
+      mutt_buffer_expand_path_regex(folderbuf, false);
+      struct Mailbox *m = mx_path_resolve(mutt_b2s(folderbuf));
+      /* NOTE: I am purposely *not* executing folder hooks here,
+       * as they can do all sorts of things like push into the getch() buffer.
+       * Authentication should be in account-hooks. */
+      ctx = mx_mbox_open(m, MUTT_READONLY);
+      mx_mbox_close(&ctx);
+      mutt_buffer_reset(folderbuf);
+    }
+
+    /* outside of the MUTTMENU system, we have to deal with issues
+     * like the file browser not being cleared from the screen... */
+    move(0, 0);
+    clrtobot();
+
+    /* L10N:
+       This is the second prompt to see if the user would like
+       to scan more than one mailbox for Autocrypt headers.
+       I'm purposely being extra verbose; asking first then prompting
+       for a mailbox.  This is because this is a one-time operation
+       and I don't want them to accidentally ctrl-g and abort it.
+    */
+    scan = mutt_yesorno(_("Scan another mailbox for autocrypt headers?"), MUTT_YES);
+  }
+
+#ifdef USE_HCACHE
+  C_HeaderCache = old_hdrcache;
+#endif
+  mutt_buffer_pool_release(&folderbuf);
+}
index 3c2c510e0828af711b02ce0ba4c6f6af0695d715..2043870df28faac4391a5bab848fe0576dd15f82 100644 (file)
@@ -79,6 +79,7 @@ int mutt_autocrypt_db_init(int can_create)
       goto cleanup;
     /* Don't abort the whole init process because account creation failed */
     mutt_autocrypt_account_init(1);
+    mutt_autocrypt_scan_mailboxes();
   }
   else
   {
index d1a5bf27cdf39818b2d73699a06d9b2483c7e36f..2c7fc79e284b68969a22ea2bf98f812b1a39f8b8 100644 (file)
@@ -30,6 +30,7 @@ struct AddressList;
 struct Buffer;
 
 int mutt_autocrypt_account_init (int prompt);
+void mutt_autocrypt_scan_mailboxes (void);
 
 int mutt_autocrypt_db_init (int can_create);
 void mutt_autocrypt_db_close (void);