]> diplodocus.org Git - minc/commitdiff
Get unseen-sequence and mh-sequences from mhparam instead of hard-coding.
authorEric Gillespie <epg@pretzelnet.org>
Wed, 10 Dec 2014 09:21:06 +0000 (01:21 -0800)
committerEric Gillespie <epg@pretzelnet.org>
Wed, 10 Dec 2014 09:21:06 +0000 (01:21 -0800)
minc

diff --git a/minc b/minc
index c0688d6..e240da6 100755 (executable)
--- a/minc
+++ b/minc
@@ -190,14 +190,8 @@ if (!$mh) {
 
 $ENV{"MHCONTEXT"} = $mh . '/.minc.context';
 
-# TODO: Support dot-locking too.  This works on FreeBSD and Linux.
-my $locking = `mhparam datalocking`;
-$? < 0 && die;
-$? == 0 || die('mhparam datalocking: ' . exit_msg($?));
-chomp($locking);
-if ($locking ne 'fcntl') {
-    die("mh locking $locking not supported; only fcntl");
-}
+my $SEQ_FILE;
+my $UNSEEN;
 
 \f
 ###############################################################################
@@ -320,11 +314,12 @@ sub get_highest_msgnum {
 }
 
 sub mark {
+    $SEQ_FILE or return;
     my $folder = shift;
     my $msgnum = shift;
     my $seq = shift;
 
-    my $fn = "$mh/$folder/.mh_sequences";
+    my $fn = "$mh/$folder/$SEQ_FILE";
     my ($fh, $e) = lkopen_fcntl($fn, O_RDWR | O_CREAT, 0600);
 
     my @sequences = <$fh>;
@@ -493,8 +488,8 @@ sub store_message {
             # fails.  While it is slow, it is not safe to store multiple
             # messages and then have a failure before marking some (or
             # all).
-            if ($mhfolder ne 'SPAM') {
-                mark($mhfolder, $dst_msgnum, 'unseen');
+            if ($UNSEEN and $mhfolder ne 'SPAM') {
+                mark($mhfolder, $dst_msgnum, $UNSEEN);
             }
         }
     }
@@ -872,6 +867,29 @@ if (!caller()) {
         require "$HOME/.minc";
     }
 
+    my $locking = '';
+    open(my $fh, '-|', 'mhparam',
+         'datalocking', 'mh-sequences', 'unseen-sequence') or die("open(mhparam|): $!");
+    while (<$fh>) {
+        chomp;
+        if (s/^fcntl:\s*//) {
+            $locking = $_;
+        } elsif (s/^mh-sequences:\s*//) {
+            $SEQ_FILE = $_;
+        } elsif (s/unseen-sequence:\s*//) {
+            $UNSEEN = $_;
+        }
+    }
+    if (!close($fh)) {
+        $! == 0 or die("open(mhparam|): $!");
+        die('mhparam '. exit_msg($?));
+    }
+
+    # TODO: Support dot-locking too.  This works on FreeBSD and Linux.
+    if ($locking ne 'fcntl') {
+        die("mh locking '$locking' not supported; only fcntl");
+    }
+
     my $inbox;
     if ($MAILDIR) {
         $inbox = $MAILDIR;