]> granicus.if.org Git - mutt/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)
committerKevin McCarthy <kevin@8t8.us>
Sat, 3 Aug 2019 21:08:09 +0000 (14:08 -0700)
The scanner will disable the header cache, allowing scanning all
messages in the mailbox.

autocrypt/autocrypt.c
autocrypt/autocrypt_db.c
autocrypt/autocrypt_private.h

index 4b7d4815e51f30cb5368dd80376ade9ca48ec726..7e139870a6716b688adca70fc8f4743568957aa7 100644 (file)
@@ -25,6 +25,7 @@
 #include "mutt_crypt.h"
 #include "mime.h"
 #include "mutt_idna.h"
+#include "mailbox.h"
 #include "autocrypt.h"
 #include "autocrypt_private.h"
 
@@ -787,3 +788,74 @@ int mutt_autocrypt_generate_gossip_list (HEADER *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;
+  BUFFER *folderbuf = NULL;
+  CONTEXT *ctx = NULL;
+
+#ifdef USE_HCACHE
+  char *old_hdrcache = HeaderCache;
+  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 (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_open_mailbox (mutt_b2s (folderbuf), MUTT_READONLY, NULL);
+      mutt_sleep (1);
+      mx_close_mailbox (ctx, NULL);
+
+      FREE (&ctx);
+      mutt_buffer_clear (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
+  HeaderCache = old_hdrcache;
+#endif
+  mutt_buffer_pool_release (&folderbuf);
+}
index c8a42b814490db0a45c4483fa67a410966a32324..b03f33cc63470642592358c06821ba44e8a7a3ef 100644 (file)
@@ -77,6 +77,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 96c487f54f255892a1a17754d58b2d6edf5458fd..43b6b29da651de55ed33550252c703939a324556 100644 (file)
@@ -20,8 +20,8 @@
 #define _AUTOCRYPT_PRIVATE_H 1
 
 #include <sqlite3.h>
-
 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);