Package: mairix
Severity: wishlist

Dear maintainer,

The attached patch adds a .mairixrc option "follow_mbox_symlinks" which
causes mairix to follow symlinks to mboxes when indexing.  This
behaviour was disabled by default, with no option to re-enable, in
mairix version 0.22.  This patch does not change the default behaviour
of mairix for users who do not explicitly include "follow_mbox_symlinks"
in their .mairixrc.

I have submitted this patch to upstream's bug tracker, but since
upstream releases infrequently, I propose that this patch be included in
Debian's packaging of mairix.  That's because it's particularly useful
for users of git-annex, of which there are many in Debian's userbase.
It is possible to work around mairix's symlink-skipping behaviour [1],
but a simple configuration file option to restore the old behaviour is
much more practical.

[1] 
https://joeyh.name/blog/entry/moving_my_email_archives_and_packages_to_git-annex/

-- 
Sean Whitton
From: Sean Whitton <spwhit...@spwhitton.name>
Date: Wed, 23 Mar 2016 17:18:47 -0700
Subject: Option to follow symlinks to mboxes in rc file
Forwarded: https://github.com/rc0/mairix/pull/20

Add .mairixrc option "follow_mbox_symlinks" which allows the user to
restore the behaviour disabled by commit 74ebca5.

This is particularly useful for users of git-annex.  It is possible to
work around mairix's symlink-skipping behaviour [1], but a simple
configuration file option to restore the old behaviour is much more
practical.

This patch does not change the default behaviour of mairix for users who
do not explicitly include "follow_mbox_symlinks" in their .mairixrc.

[1] https://joeyh.name/blog/entry/moving_my_email_archives_and_packages_to_git-annex/
---
 mairix.c | 9 ++++++++-
 mairix.h | 3 ++-
 mbox.c   | 7 ++++---
 3 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/mairix.c b/mairix.c
index 09f255b..2ef6a62 100644
--- a/mairix.c
+++ b/mairix.c
@@ -51,6 +51,7 @@ static char *omit = NULL;
 static char *database_path = NULL;
 static enum folder_type output_folder_type = FT_MAILDIR;
 static int skip_integrity_checks = 0;
+static int follow_mbox_symlinks = 0;
 
 enum filetype {
   M_NONE, M_FILE, M_DIR, M_OTHER
@@ -249,6 +250,7 @@ static void parse_rc_file(char *name)/*{{{*/
     }
     else if (!strncasecmp(p, "mh=", 3)) add_folders(&mh_folders, copy_value(p));
     else if (!strncasecmp(p, "mbox=", 5)) add_folders(&mboxen, copy_value(p));
+    else if (!strncasecmp(p, "follow_mbox_symlinks", 20)) follow_mbox_symlinks = 1;
     else if (!strncasecmp(p, "omit=", 5)) add_folders(&omit, copy_value(p));
 
     else if (!strncasecmp(p, "mformat=", 8)) {
@@ -490,6 +492,7 @@ int main (int argc, char **argv)/*{{{*/
   int do_integrity_checks = 1;
   int do_forced_unlock = 0;
   int do_fast_index = 0;
+  int do_mbox_symlinks = 0;
 
   unsigned int forced_hash_key = CREATE_RANDOM_DATABASE_HASH;
 
@@ -617,6 +620,10 @@ int main (int argc, char **argv)/*{{{*/
     do_integrity_checks = 0;
   }
 
+  if (follow_mbox_symlinks) {
+    do_mbox_symlinks = 1;
+  }
+
   if (!folder_base) {
     fprintf(stderr, "No folder_base/MAIRIX_FOLDER_BASE set\n");
     exit(2);
@@ -746,7 +753,7 @@ int main (int argc, char **argv)/*{{{*/
       unlock_and_exit(2);
     }
 
-    build_mbox_lists(db, folder_base, mboxen, omit_globs);
+    build_mbox_lists(db, folder_base, mboxen, omit_globs, do_mbox_symlinks);
 
     any_updates = update_database(db, msgs->paths, msgs->n, do_fast_index);
     if (do_purge) {
diff --git a/mairix.h b/mairix.h
index 2480492..b05c1c6 100644
--- a/mairix.h
+++ b/mairix.h
@@ -357,7 +357,8 @@ int cull_dead_messages(struct database *db, int do_integrity_checks);
 
 /* In mbox.c */
 void build_mbox_lists(struct database *db, const char *folder_base,
-    const char *mboxen_paths, struct globber_array *omit_globs);
+    const char *mboxen_paths, struct globber_array *omit_globs,
+    int do_mbox_symlinks);
 int add_mbox_messages(struct database *db);
 void compute_checksum(const char *data, size_t len, checksum_t *csum);
 void cull_dead_mboxen(struct database *db);
diff --git a/mbox.c b/mbox.c
index ebbfa78..f8bed26 100644
--- a/mbox.c
+++ b/mbox.c
@@ -743,7 +743,8 @@ void glob_and_expand_paths(const char *folder_base,
 /*}}}*/
 
 void build_mbox_lists(struct database *db, const char *folder_base, /*{{{*/
-    const char *mboxen_paths, struct globber_array *omit_globs)
+    const char *mboxen_paths, struct globber_array *omit_globs,
+    int do_mbox_symlinks)
 {
   char **raw_paths, **paths;
   int n_raw_paths, i;
@@ -776,8 +777,8 @@ void build_mbox_lists(struct database *db, const char *folder_base, /*{{{*/
     if (lstat(path, &sb) < 0) {
       /* can't stat */
     } else {
-      if (S_ISLNK(sb.st_mode)) {
-        /* Skip mbox if symlink */
+      if (S_ISLNK(sb.st_mode) && !do_mbox_symlinks) {
+        /* Skip mbox if symlink and no follow_mbox_symlinks in mairixrc */
         if (verbose) {
           printf("%s is a link - skipping\n", path);
         }

Attachment: signature.asc
Description: PGP signature

Reply via email to