From 008cba7a81885680fadaf779a803c1436c66cf04 Mon Sep 17 00:00:00 2001 From: Eric Gillespie Date: Wed, 10 Dec 2014 01:21:06 -0800 Subject: [PATCH] Get unseen-sequence and mh-sequences from mhparam instead of hard-coding. --- minc | 40 +++++++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/minc b/minc index c0688d6..e240da6 100755 --- 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; ############################################################################### @@ -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; -- 2.56.0