Created
November 4, 2014 08:23
-
-
Save checko/de7564ba1badf2338384 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
# usage: | |
# vmutt [maildir] [command] | |
# eg. | |
# vmutt ~/mail/flagged "mutt -f ~/mail/flagged" | |
use warnings; | |
use strict; | |
use File::Basename qw/basename dirname/; | |
use File::Spec; | |
my $dir = $ARGV[0]; | |
my $cmd = $ARGV[1]; | |
die("first argument must be maildir full of symlinks") unless -d "$dir/cur"; | |
my @orglinks = <$dir/cur/*>; | |
my @orgdests = map { readlink } @orglinks; | |
my %original; | |
@original{@orgdests} = @orglinks; | |
my $ret = system($ARGV[1]); | |
#exit($ret) if $ret; | |
my @newlinks = <$dir/cur/*>; | |
my @newdests = map { readlink } @newlinks; | |
for my $i (0..$#newlinks) { | |
my $link = $newlinks[$i]; | |
my $dest = $newdests[$i]; | |
if (exists $original{$dest}) { | |
if ($original{$dest} ne $link) { | |
my $newname = File::Spec->catfile( | |
dirname($dest), | |
basename($link) | |
); | |
print "rename: $dest -> $newname\n"; | |
rename($dest, $newname); | |
} | |
delete $original{$dest}; | |
} else { | |
die "WTF? where did $dest come from?!"; | |
} | |
} | |
for (keys %original) { | |
print "delete: $_\n"; | |
unlink($_); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
backup of http://mafipulation.org/static/vmutt