summaryrefslogtreecommitdiff
path: root/bin/expand-annex-mboxes
blob: 7f3525bcb2776321c181e43c07a1c3d7c9ea67a9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/perl

use 5.028;
use strict;
use warnings;
use lib "$ENV{HOME}/src/dotfiles/perl5";

use Fcntl qw(LOCK_EX LOCK_NB);
use File::Path qw(make_path);
use File::Spec::Functions qw(catfile splitpath);
use Local::Homedir::Mail qw(expand_mbox);

# CONFIG

our $mboxes   = "$ENV{HOME}/annex/mail";
our $expanded = "$ENV{HOME}/.fmail/annex";

# CODE

# flock ourselves to ensure that only one copy of this script is ever running
open our $us, "<", $0 or die $!;
exit 0 unless flock $us, LOCK_EX|LOCK_NB;

make_path($expanded);
open my $touch_fh, '>', "$expanded/.duplicity-ignore";
close $touch_fh;

foreach my $mbox (glob "$mboxes/*.gz") {
    # $mbox might be a dangling symlink on this machine
    next unless -e $mbox;

    my (undef, undef, $name) = splitpath($mbox);
    $name =~ s/\.gz$//;
    expand_mbox($mbox, catfile($expanded, $name));
}